LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Lags on data rappresentation in real time serial communication

Hello!
I have a problem with my vi that uses a VISA serial communication to display data in real time coming from a board.
As you can see in the file attached, the block diagram is very simple: I set the VISA communication, write a string to start the read stream and write another string to stop it. The sample rate from the external board is aout 500sps and one sample is composed by 24 bytes.
In the first time I used a "wait" block of 2ms (disabled in the vi attached) and all seems to works but I noticed an increasing lag in the charts during the execution. So I deleted the "wait" block and consequently the lag, but now the data acquisition seems to continue jerkly without data losses. I attached a video that shows it:in the first part the data representation is flowing and in the second it is jerky.
So I try to use a "VISA Wait on Event" block to wait until there are some bytes before perform a read (like here), but the "VISA Enable Event" puts out the error
"−1073807322 : Specified event type is not supported by the resource".

 

Is my serial vi correct?
Why this jerky behavior?
The VISA read is blocking until it reads all the bytes defined by the user?
Why the "VISA Enable Event" error?

 

Please help me.

Download All
0 Kudos
Message 1 of 17
(3,696 Views)

1. The simplest way to receive streaming serial data is to make use of a termination character.  Since you explicitly disabled that, I'm guessing your "board" is some kind of custom thingy that doesn't give you one.  This is the beginning of your difficulty.

 

2. Are you connected at 119.2 kbs?  If so, it seems like you're pushing the bandwidth limits of the serial bus with 500 samp/sec * 24 bytes/samp.  Pushing the limits tends to make bad things happen too.

   Do you have control over the comm protocol from this "board"?  Can you add a termination character?  You may also need to compress the data stream or lower the sample rate.

 

3. Are you using a USB to serial converter?  Not all of them are well behaved

 

4. You're going to need to work on your serial code to handle timeout errors, framing errors, etc.  Your attempt to use VISA events looked like a step in the right direction.  I'm guessing the error you got may be due to use of a USB-to-serial converter.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 2 of 17
(3,676 Views)

This runs on a Windows PC, right?  So there is no "real time" involved!  This is a specific term that basically means that the "Hardware is in charge of the clock" and the Operating System (Windows) doesn't get to set priorities, pause to let Virus Scans run, etc.

 

Is your VISA device running with a Termination Character enabled?  It is often a good idea to "Let Hardware Be Hardware", that is, let the Hardware that has the capacity to know what is going on be in charge.  In the case of VISA with a Termination Character, this means that you read, say, 1000 characters (much longer than you need), and when the Read finishes (because VISA "saw" the Termination Character), you ask VISA "How many Bytes did you read?", and then process what it tells you.  This means you stay "out of the way" of VISA until it tells you that it is done, at which point you "process everything quickly" and hand control back to VISA.

 

Bob Schor

0 Kudos
Message 3 of 17
(3,670 Views)

Kevin has good points. Especially the termination character. If you ever get one byte out of synchronization, your VI will fail.

 

The default value for the baud rate is 1E6. That seems unusual. Can the devices at both ends support that? What kinds of devices are you using for serial communications?

 

The sequence structure is not needed. Dataflow will take care of the things whihc need to be ordered.

 

Lynn

0 Kudos
Message 4 of 17
(3,670 Views)

The board is a system made by me that uses a FTDI USB/UART converter. The actual boudrate is 1 Mbps. Actually I don't use a final character but It is the intention.

0 Kudos
Message 5 of 17
(3,665 Views)

What serial device is used at the computer?

 

Lynn

0 Kudos
Message 6 of 17
(3,661 Views)

I use a FTDI that converts a serial communication (up to 3 Mbps) to a USB. It creates a COM port on the computer. 

0 Kudos
Message 7 of 17
(3,658 Views)

Since the data are numbers, it is possible that the termination character occurs before the real termination of the data. In this case I have to controll the nuber of the read bytes until it is 24? Right?

0 Kudos
Message 8 of 17
(3,643 Views)

At 1 Mbps, you've got headroom to add a termination character to your framing protocol.  DO IT!   Might as start with the (default) linefeed character.   

 

After that, do like Bob_Schor described for the VISA Reads.  The VISA events that don't work on your USB-to-serial device won't be needed anyway.

 

You'll still have a little work to do since your binary data stream will sometimes include a data byte of that same character, which VISA will (properly) interpret as a line termination.  

 

 

-Kevin P

 

<Edit>  P.S.  Saw your latest reply after I posted.  I see you've anticipated the issue of data looking like a termination char.  You might want  to try a multi-character line termination convention on your custom board.  Have VISA terminate on the last character in the sequence.  But then you can look at the string for the special sequence to give you a much higher probability of distinguishing termination from data.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 9 of 17
(3,641 Views)

I have tryed with the termination character and check the correct data packet integrity and the data were all correct. But the main problem persists: the charts and all data indicators don't show continously the data stream but jerkily.
Another suggestions?

 

PS: thanks for the previous answers.

0 Kudos
Message 10 of 17
(3,609 Views)