10-02-2012 09:14 AM
Hello everyone,
I'm trying to collect data from both a NI PCI-6221 board and serial port (through TCP connection) in Labview. To make the VI run faster, I adopt the Producer-Consumer structure:
in the producer loop, I read data from both DAQ assistant (on Demand) and from serial port (the data sample comes every 8 ms), and enqueue both data samples and a tick count value;
in the consumer loop, I insert the items into three arrays (two data samples and a tick count), with each array connected to a shift register; outside the consumer loop, each output of register is written to a different channel of a opened TDMS file.
If I set the producer loop to be a timed-loop (1kHz clock frequency, dt=8), every data sample from serial port comes with quite a long delay (about a few seconds) after that with the same value from the NI-board.
Then I set the producer loop to be a while-loop, without a "wait" function. In this case, the VI seems to run faster, and the serial port provide a certain-value data sample about 50~60ms after the board provide that value. But the problem is that, the interval between two iterations of loop changes all the time. The tick counts recorded in the TDMS file show that the interval between two iterations could vary from "0ms" to 20 ms.
So I was wondering if I can make the loop run as fast as possible, meanwhile keep the interval between loop iterations relatively constant? Or there is a better way to measure the delay I mentioned?
Thanks in advance,
ZY
10-07-2012 08:49 PM
Hi terrylizi,
If you need logging datat from DAQmx to TDMS, maybe you can try this one:
10-08-2012 12:26 PM
You might be better off with two producer loops, on for the DAQ operation and another for the serial port. Then the timing on each is not limited by any delays in the other. The serial port is probably asynchronous so that you cannot be certain of stable timing there.
Lynn
10-09-2012 02:36 AM
Hi Yongqing,
Thanks for the tips. But in my VI, the data logging works fine and does not seem to be the bottleneck of the data flow. My goal is to log DAQ data and serial-port data with the same tick count, so I'm not sure if DAQmx could help me with that. Any suggestion?
ZY
10-09-2012 02:38 AM
Sorry, I'm not the expert of DAQmx, let's see whether there's any DAQmx expert can help here. Good luck!
10-09-2012 02:54 AM
Hi johnsold,
Thanks for the advice. But in order to analyze the delay I mentioned, I need to acquire data samples from DAQ and serial port at the same time, or at each time point when the serial-port data is read, a DAQ data sample need to be read as well. Do you think I can do this with two producer loops?
ZY
10-10-2012 03:57 PM
ZY,
No. The two loops would almost certainly run at different rates eventually, even if they started out together. I may have misunderstood your requirement before.
After re-reading your initial post, I suspect that there is something wrong with the way you have programmed your producer loop or the serial device is not responding as you expect it to.
Please post your VI with some data showing the problem. We do not have your equipment of course so we cannot watch as the data is generated. What kind of device is connected via the serial port?
Lynn
10-10-2012 09:59 PM
I had to do something similiar, except with a much smaller expected delay than 8ms. The problem was that com port reads are at the mercy of the OS. There were variable delays of up to +/-50ms.
I ended up using multiple channels on the same DAQ card (well, multiple cards) and processing the analog recording of the UART line into bits, then Bytes, etc.