Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial data comes in with delay and in inconsistent batches

Solved!
Go to solution

Hi everyone,

 

I'm having issues with getting quick, smooth data from a serial device. Data currently comes in large chunks (0-4000 bytes), interspersed by many empty reads, which results in visibly delayed acquisition of data. (Chunks come in at ~4 Hz.) I know that streaming smooth, timely data (at a very high frequency) is possible, because we have a MATLAB Simulink program that is able to achieve this with the same device (using FIFO Read Binary).

 

I'm currently streaming data from a device that sends packet data without termination characters. Each packet starts with [45, 62] and is then followed by seven bytes of data. The attached VI uses a consumer-producer loop. The producer handles serial communication while the consumer is a state machine that identifies headers and then processes them into usable form. I suspect the issue is with the producer loop, but I included the entire subVI for examination. It's currently written to be part of a larger program (stops are linked to a ref and all data goes into a queue).

 

Things I've tried include:

  1. Reading 1000 bytes, with 0 timeout. This results in the same behavior.
  2. Reading 4 or fewer bytes with 10000 timeout. This results in functionally the same behavior as above, except rather than returning empty data, it just waits for a moment before returning a "burst" of reads over many iterations of the producer loop.
  3. Using a timed loop with T=1ms, timeout=1, read 4 bytes. Very smooth data coming in, but very significant lag between device and LabVIEW read data.
  4. Using a timed loop with T=1ms, timeout=1, read 36 bytes. Same as original issue, with "chunky" data stream.

Any advice or help would appreciated. I suspect there's something I'm misunderstanding about serial ports, and could use guidance from y'all.

 

Thanks a bunch!

0 Kudos
Message 1 of 5
(2,596 Views)

I had same issue when i started with custom VISA communication.

 

I think your problem is that you use Bytes at port function, rather than using that just read a large chunk, for example 1000 bytes.

 

image.png

 

0 Kudos
Message 2 of 5
(2,565 Views)

Hi AeroSoul,

 

Thanks for your suggestion. Having tried that with timeouts of 0 and 10000, the behavior seems to be roughly the same, with data coming in about once every two seconds. With timeout of 0, most reads are empty; with timeout of 10000, the loop iterates ~4 times, waits about 0.5 seconds, and then reads 4 times again. It's almost as if the device itself sends data in clumps of ~4000 bytes. I only know this not to be true because I've seen it working on Simulink. (Note: the Simulink interface is on a different PC.)

 

I'd be open to investigating the device output with another machine/device, but am not sure how.

0 Kudos
Message 3 of 5
(2,558 Views)
Solution
Accepted by topic author charleslu

Came across the solution with some online digging. Turns out it has nothing to do with LabVIEW at all. What I needed to do was to go into the COM port device driver advanced settings in Windows Device Manager and switch latency from 16 ms (default) to 1 ms. All issues have gone away.

Message 4 of 5
(2,531 Views)

Good catch

greetings from the Netherlands
0 Kudos
Message 5 of 5
(2,519 Views)