08-16-2011 07:11 AM
Ok please correct me if I am wrong.
So in the while loop, all I need to do is wire the shared variable (Variable1) into a buffered network shared variable inside the false case structure? (this would allow the transfer of the data points to the computer)
And then create a new VI under the computer, include all the indicators and include the write2measure (exe1.vi) in the new VI?
I have just moved around my VIs in that manner and the project is attached. Can you pelase kindly have a check again? Once again thanks for your patience and help.
08-16-2011 07:56 AM
Hello,
Yes, you are correct. I know that this architecture looks bit stupid in your program, but usually the Real-Time is meant to be running on it's own and it analyze all the data on the real-time target - so if you would do the analysis in the timed loop, timed loop would be not deterministic and you would not ensure desired response time.
There are still few cosmetics changes I would recommend you in your program:
- in the computer VI, you need to have Buffered variable inside the loop, so you get data all the time and not just once - you also need to set timeout, so the variable waits for a data to be sent
- there is still one indicator and one control in the cRIO VI - Samples per Sec and Stop. Appropriate would be to transfer them to computer VI, create 2 more network shared variables (one for stop and one for sample rate) and implement same communication as for data - with difference that you don't make them buffered. (for stop variable would be the best, if you first write false into variable before while loop, and then you write into a variable in the while loop only when the stop button in true - otherwise you could loose the true value through network connection)
If anything is still not clear, feel free to ask.
Best Regards,
Gregor Cerne
National Instruments
08-16-2011 08:51 AM
I ran the VI and it is able to write lvm files into my computer, the format is close to what I want, however the elapsed time disappeared.
If you can have a look at the test001.lvm file I have attached previously, you can see that the leftmost column contains the elapsed time of the data taken. I count the number of samples within each second to figure out wat the sampling rate is, without the elapsed time I am not sure how to determine whether the program is writing data at the desired sampling rate.
With the sampling rate network variable, if I want to make the sampling rate user specified, I will need to create a control for the sampling rate at the computer.vi, assign the value to the network variable and then put the variable onto the cRIO VI, do the appropriate conversion and wire it to the period of the timed loop. Am I right?
And with all the tank indicators for each signal, do i have to use the array to cluster method you suggested before? Can I simply drag and drop the 20 AI shared variables onto the block diagram of computer.vi and create an indicator for each?
I have also just realised that the clock time on the cRIO is different to the "real" time even after I changed the timezone in the network setting on MAX. So the time stamp on the cRIO VI and computer VI are showing two different times. How can i fix the time on the controller?
08-16-2011 09:25 AM
Hello,
If you want to check the real sampling rate, I think is the best way is to store the timestamp of Variable1 to shift register, and subtract it from the new value. The difference between timestamps is time between samples. I am attaching the picture at the end.
Sampling rate network variable: Almost right; but you need first show Right Data Node of timed loop (right-click you will find the option) and connect the sampling rate network variable to the period of that Right Data Node. If you would connect to a start node it would set the rate only at the start and it would not change. That variable (sampling rate) need to have RT FIFO enabled with single-element.
If you put all the AI shared variables drag and drop to the computer, it would be the same as the first version of program; you need to do array to cluster method.
There is no support for changing the date and time in MAX with LabVIEW 2009; still there is option to change it programmatically. More details in following link: http://digital.ni.com/public.nsf/allkb/FAB0EC4D6E5EE0F386257738005733A3?OpenDocument&metc=max_MAXDat...
One more thing: the Variable1 need to have RT FIFO enabled with multiple-element - otherwise you can loose data.
Best Regards,
Gregor Cerne
National Instruments
08-16-2011 09:47 AM
So is there a way to include the elapsed time into the lvm file again?
08-16-2011 10:01 AM
Hello,
For elapsed time you could implement the code in attachment below into your while loop in the cRIO VI. For best performance you can add Elapsed Time to the end of the array with values, and then send this array to computer VI. There you would need to extract Elapsed Time, change it to string, and wire it to the Comment input of exe1.vi
Best Regards,
Gregor Cerne
National Instruments
08-16-2011 10:00 PM
Thanks!
Regarding the suggestion you have made with the stop variable before: "for stop variable would be the best, if you first write false into variable before while loop, and then you write into a variable in the while loop only when the stop button in true - otherwise you could loose the true value through network connection" Sorry I dont quite understand what this does, can you please explain? My guess is that writing false into the variable would ensure the while loop executes properly wheneva the VI is started.
What I am doing with the stop variable right now is that when the user pressed the stop button in the computer.vi, it will stop the writing data to file process, also it will write a true value to the stop variable, which in turns stop all the loop operations in the cRIO VI. Would this cause any loss of data? Because now that the data acquisition and data logging is done by two seperate VI, what actually happens if I only run one of the VI?
For example, I ran the computer.vi without running the cRIO VI, it is saving data into my computer which is different to what I expected, I thought that if the cRIO VI is not running, then the netowrk variables (variable1 and buffered) would be empty?
08-17-2011 05:20 AM
Hello,
First, you need to set the stop variable to false, then the while loop executes. If the Stop button is not pressed, the False value stays in the variable, so you don't need to send False again, leaving more scape for other network communications. But when the button is pressed, you write true to variable and true stays inside the variable until the program is over. The code is attached below. I think that your code could execute also without problems, but this way you are sure that the cRIO reads the True value and you don't use network connection when you don't need to.
When you stop the VI, you stop only VI - network shared variables are still "running" and they are not empty, thet is why you see unexpected data. There is feature in LabVIEW, which can ckeck status and values of those variables: In LabVIEW, please click menu Tools > Distributed System Manager. Then under Network items search for the IP of your device, and under it you will find libraries with different data - from values of C-modules, deployed variables to system memory usage.
Best Regards,
Gregor Černe
National Instruments
08-18-2011 01:40 AM
Thanks!
I have experienced some really strange problems now when i run my VIs.
1) Whenever I run the cRIO.vi it would stop by itself after 1 second but when I run it the second time it will be fine. I was thinking of using the code you provided but because my supervisor wants me to keep all the user controls in only one V, I have decided to stick with my code, could this been the reason causing the problem?
2) I am trying to make the sampling rate user specified (to be more specific I only want to provide three options to the users, so maybe three buttons representing three different sampling rate), but whenever I tried to change the code specifying the sampling rate (in cRIO.vi), for example I tried to assign a network variable called sampling, replace the constant value with my network variable, assign a control to the variable in computer.vi. When I run cRIO.vi, the connection to the RT target will be lost and I would need to turn off the actual controller and turn it back on to resume connection (even restarting MAX couldnt re-establish the connection). I have attached a picture below to show where the exact code is located.
3) I have also attached the latest version of my work, in the cRIO.vi, is the flat sequence structure neccessary? Can you please have a check and let me know about the mistakes I have made please?
Thanks a lot!
08-18-2011 01:56 AM
Just to clarify about problem 1) my stop button is on computer.vi which is where I want all the user actions to take place in. So ideally I want to specify the sampling rate here as well but simply by transferring the sampling rate across using network variable causes problem 2) and I am suspecting it might be a hardware problem? Hopefully it isnt otherwise there wont be much I can do .... 😞