10-30-2015 12:55 PM
Hello all
I am communicating with a third party serial instrument continuously while running an analog input operation. I have both the serial task and AI task in the same loop and seemingly regardless of the loop speed I get a timeout error - the serial read cannot complete in time. I suspect synchronization problems as I observe the error gets thrown after a longer time running the program when I decrease the loop speed. (I am controlling the loop speed based on the sampling rate and number of samples read for the AI task.)
I have read a lot of documentation on here about synchronizing various tasks but have never come across an example where a serial device is run along with an AI operation. Any advice on this? Should I have both tasks in the same loop?
Thank you for your time and I can provide more information as necessary. I have attached the main VI 'serial_minicone.vi' along with the serial sub VI 'tipdatasub.vi' and 'sleevedatasub.vi' which are very similar. The other two sub VI 'ai2.vi' and 'ai4.vi' just contain some arithmetic for the instrument calibrations.
Thank you!
Jeff
ps These VIs are in development so please forgive the lack of user-friendliness...
11-01-2015 08:23 PM
Have you tried running the serial task in a separate loop or VI, without running any AI task? It may be the AI task is a red herring, and there are actual timeout issues when talking to the serial device.
Have you verified the loop rate is what you're expecting based on the AI task timing?
11-02-2015 12:36 AM - edited 11-02-2015 12:39 AM
I had a look at your VIs. There are several problems:
Here I would imagine you could use a Producer/Consumer design. I do not know what is your data acquisition requirement, but here you must make a decision. You have a slow RS232 and a fast DAQmx task. Assuming that you want to save the data at a rate of 4Hz (DAQmx 20 kHz rate, 5000 samples), you could use 3 loops: 2 producer and 1 consumer. If you do not need a tight sync between the RS232 and DAQmx data, I would just use a Queue for the DAQmx, this would send data from the DAQmx Producer to the Consumer loop. In the RS232 Producer, you could use a Notifier to broadcast always the most recent result to the Consumer loop (and use the "Get Notifier Status" in consumer loop).
And of course, process the data ONLY in the Consumer loop, you should have nothing in the fast DAQmx Producer loop, only the DAQmx Read and the Enqueue element (in this case the element is a 2D array).
11-02-2015 04:10 AM
I tried to put together a quick example, note that, i did not have the time to properly clean up the VI, neither to program more proper intercommunication/error handling... But I hope it can give you some idea how to decouple different loops not to slow down DAQ...
Another thing, you should use LabVIEW project, to properly maintain your VIs, subVIs, and typdef controls...
11-02-2015 10:39 AM
Great thank you both for your replies!
It turns out the AI task was a red herring as I received the same timeout errors when ONLY talking to the serial instrument (no AI task in the loop). My new diagnosis is that the carriage return character, which is appended both to commands to the device, and responses from it, was getting overwritten due to the VISA Write and Read functions executing one immediately after the other. This is not the most elegant solution, but I added 10 ms delays between each VISA Write and Read, and I have not had any errors since. I should note (there was a good debate about the best way to handle termination characters in my last post) I also tried writing the carriage return by explicitly including it in my commands to the device and had the same errors. So in this case it seems the VISA instrument properties END IN and END OUT are doing fine appending the termination characters. Any thoughts on the way I solved this problem (with the delays)??
As for the loop rate, by separating the serial instrument in its own loop, I realized the instrument is capable of receiving commands and writing responses very quickly, but the board on the instrument only updates the value of the tip load and sleeve load at about 3-4 Hz. So there is no reason to run the loop much faster than this. I can verify my AI sampling characteristics do in fact control the loop rate.
Blokk, thank you for posting this code. I have used queues before to separate DAQmx Read operation and data processing / writing to file, but I have not used a notifier to broadcast from a producer loop to a consumer loop. Very cool. Could you please explain the error handling? For example, if one of the VISA VIs in the Serial Loop throws an error, does the program stop? I would feel much more comfortable about running the program continuously if I knew it could get through a garbled command here or there.
Thanks!
Jeff
11-02-2015
04:46 PM
- last edited on
11-15-2024
03:29 PM
by
Content Cleaner
Could you please explain the error handling? For example, if one of the VISA VIs in the Serial Loop throws an error, does the program stop? I would feel much more comfortable about running the program continuously if I knew it could get through a garbled command here or there.
Correct observation 🙂 No, if the Serial loop generates an error, it will stop execute, but the 2 other loops will NOT know about this error. So this is one thing should be fixed.
Since I always use a kind of Queued Message Handler design, where I have a Event Structure, I usually use a User Event to broadcast error from other loops toward the GUI (Event Structure) loop. And then the GUI loop "tells" the other still running loops to stop (or handling/reporting/logging error).
In your case, if you use my example VI, a possible "quick fix" for error handling could be the following:
As you see, this is not an elegant/sophisticated way to do error handling. You could have a look how error handling works for example in the Queued Message Handler, but it is a bit more elevated level of LV programming (I suggest to go through Core-1-2-3 online teaching material):
http://www.ni.com/webcast/3640/en/
Good luck!
EDIT: You could also use the Notifier from the top "Serial loop", to broadcast an error msg, similarly as the DAQmx loop commands to process data or stop the Consumer loop...Anyway, if you dig deeper into LV, you will see why the "User Events" are so useful 🙂
11-04-2015 11:35 AM
Hmm I think I'm about halfway to understanding this error handling...haha. The way you explain how each loop is interconnected makes sense. I just need to understand the details. Will go through the suggested teaching materials and thank you for giving me a place to start!!
Jeff