02-04-2014 11:28 PM
Hi to everybody, I hope anybody can help me with the next case:
I am working on a system in which I have to read signals of 5 different sensors which have different ways to communicate (4 - 20 mA, voltage, RS-232, ModBUS, etc.) with the DAQ Device (cDAQ in my case), at same time when I am reading the variables I must check for the state of several digital inputs to verify connections and if any is interrupt I must stop the Data Acquisition.
My question is if is recommendable to put all the tasks in a single loop with the logic shown in the attached image.
Or if I should divide the tasks in a multiple loop architecture.
If the answer is the second, my next question is: How many DAQ tasks per loop is OK?, my doubt is based on the number of variables that I am going to read
and the different ways to get the measures, specially which are by protocols (ModBUS, RS-232), all this by the response time.
Thanks in advance, all suggestions are welcome!
02-05-2014 02:14 AM
Hi AYanez,
while you could put all "tasks" into just one loop I would recommend to separate them in several parallel loops. I would create 3 loops: DAQmx, RS232, and MODBUS…
That way you can easily handle all those different samplerates and response times!
my doubt is based on the number of variables that I am going to read
Which "variables" are you referring to?
02-05-2014 07:36 AM
RS-232 and Modbus should definately be in separate loops. For the DAQmx, it really depends on how often you need to read each task. I prefer having a separate loop for each type of taks (analog input, digital I/O, counter input, etc).
02-05-2014 09:33 AM - edited 02-05-2014 09:53 AM
Hi GerdW, the measured variables by the sensors, those I am referring, thanks for the help!
By the way, when I divide the tasks, which is the best way to control the acquisition, I am studying the possibility of using an Event Structure with Programattic Events, of this way for example with the ModBUS loop I could send the commands like Read Coils or Write Coils to change the configuration and I would use the Timeout Event to retrieve values of the sensor.
I thought this alternative but I don´t know if this is the best way or if use Queues would be better.
Best regards to both and thanks for their valuable time and help!!
02-05-2014 10:51 AM
I would recommend using a loop just for control and UI events. It should only have an event structure. Don't use the timeout case, since that just turns the system into a polling. Use Queues to send data from the controller loop to your other loops and User Events to send data back to the controller looop.
02-05-2014 11:13 PM
I understand your point crossrulz, but I was referring to use an Event Structure with the next approach:
My approach consists in delegate a DAQ Task to an Event Structure, which is normally sleep and with an User Event I could configure some actions like:
Start DAQ Task, Stop DAQ Task or Read values with the help of Timeout Event which will activate the polling in the loop when I send the Enum Item Read.
I see 2 advantages with this idea:
The loop has delay itself with the Timeout Event.
The loop does not waste CPU while we dont need of this.
I know that Queues are useful but my doubt is if this way of using Event Structure is OK even when it is not so common, if is not I appreciate if someone tell me his opinion about which would be the best way to separate the DAQ Tasks in several loops.
Thanks for the answers, I really appreciate the help more even when is for learning some new.
02-06-2014 06:32 AM
User Events to queue up DAQ tasks? That certainly sounds like a Queue to me. And the queue has a timeout if you want to use it. Using a queue is a little more straight forward and easier to read, IMHO.
02-06-2014 06:19 PM
So the correct approach for many DAQ Tasks in paralell would be to use a Queue State Machine per loop to manage the task, what would happen if I if I wanted to save the data to a TDMS file?.
I really would appreciate a VI example with 2 DAQ Tasks in parallel that sends data to 1 graph using your approach.
I apologize for being so annoying but I really want to learn to deal with these cases correctly, as it is widely used in real cases.
Thanks!
03-04-2014 03:35 AM
Hi,
I have similar problem.
I have cDAQ NI9174 and modules NI 9205 for Voltage input measurement and NI 9219 for RTD input. I would like to measure the voltage and temperature simultaneously to have temp and voltage data per one time sample. Shall I use the DAQ mxRead VI twice in one while loop (for voltage and temp) or shall I implement two separate loops and synchronize the timing ???
03-04-2014 10:34 AM
In my case in the end I put the acquisition in just one loop because the objective of this is to observe the behavior of a phenomenon so it makes no sense having different Read Rates, because the client wants have the readings in 1 sample on demand synchronized as possible.
If in your application is intended to have the posibility of changing the Frequencies of Reading, the best is having 2 loops with Queues like crossrulz said.