LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronize Serial Communication and DAQ

Even though there are some questions regarding serial communication and DAQ synchronization, none of them seemed to match my present situation. 

 

Please find my attached vi. It has two separate vi's intentionally put in a single while loop. One is cDAQ and the other is serial communication state machine. 

 

Both the vi's work by themselves, when they are in their separate while loops. The waveform chart is as expected when they are plotted in two different graphs (as the vi attached)

 

However, I would like to plot them in a single plot (waveform). This is when the problem arises, as the DAQ module is very fast compared to serial communication. I am struggling to synchronize them. Presently I am using continuous data sampling for DAQ and playing around with the number of samples. I also tried changing to N sample acquisition, that was not helpful either, as it became too slow compared to real time. Serial communication comes in with 20 bytes every 10 ms. Effectively I would like to plot a graph, with data points at every 0.01. 

 

Primarily concerned about synchronizing the data, plotting them on same graph and saving them in a single csv file. Also, clearing the waveform graph when athe run button is pressed.

 

 

PS: Ignore the array manipulation in both the state machine and other DAQ module. It is not effective as of now.

 

0 Kudos
Message 1 of 13
(7,109 Views)

There is just no way you are going to be able to reliably synchronize data from a serial port with data from a DAQ device.  Technically, you really don't know when the data from the serial device really occurred.

 

If you want to combine two sources of data, your best bet is to put them into separate parallel while loops that work at their own pace.  You can even timestamp the serial data if you want.  Pass the data from both loops through queues to a loop that will handle the meshing of the data and building them into a single graph.  You may want to make that either a waveform graph, or an XY graph rather than a waveform chart.  You can create your own buffer to store the history of older data to make the graphs behave like a chart.

 

PS:  Be sure to use block diagram cleanup.  You've got several wires that are hidden, or enter/exit functions and structures at strange places making your VI harder to read.

 

I would probably use just 1 queue and pass along with the data in a cluster an enum to identify the source of the data.  If you use 2 queues, you'd need really low timeouts on both of them so that the faster queue doesn't fill up while it is waiting for data from the slower queue.

0 Kudos
Message 2 of 13
(7,077 Views)

Few questions: 

 

1. How is a parallel while loops, different from just two while loops?

2. Queue - should I be looking at producer consumer architecture too?

0 Kudos
Message 3 of 13
(7,062 Views)

@looser_engineer wrote:

Few questions: 

 

1. How is a parallel while loops, different from just two while loops?

2. Queue - should I be looking at producer consumer architecture too?


1.  They are not different.  Other than it is possible that you'd have two while loops that would run sequentially if you had a wire run from one to the other.

2.  Yes.

0 Kudos
Message 4 of 13
(7,057 Views)

I successfully created, producer consumer architecture for serial and DAQ system in two vi's

 

Need help with the following. 

 

1. Guidance on meshing the data

2. Should I use one or two queues?

3. HOw would one add time stamp?

 

Lastly, if you are trying to debug, you could simulate the serial communication with a sine graph of time period of 1 second and data points at every 0.01 seconds. (Amplitude whatever). The eight values I am reading from the serial communication are like 8 sine waves, with different amplitude (time period 1 sec).

 

REgarding the DAQ module, I still face problem in figuring out the continuous sampling or N Data sampling. As N data sampling seems to fall behind real time and I am unable to acquire real time data. I am unaware how one could simulate it. 

0 Kudos
Message 5 of 13
(7,053 Views)

Sorry, I forgot to do the clean up again. will do it on my next upload. 

0 Kudos
Message 6 of 13
(7,052 Views)

Honestly, I'd just "Cheat"

 

The serial data is slow

The DAQmx Data is fast

 

Use a notifier for the serial and a queue for the DAQmx.  Like so:

Capture.PNG


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 13
(7,046 Views)

Could you please attach the vi.

 

 

0 Kudos
Message 8 of 13
(7,044 Views)

You know what a snipped in LabVIEW is?

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 9 of 13
(7,014 Views)

Snipped or snippet?

0 Kudos
Message 10 of 13
(7,008 Views)