LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Detecting first serial byte received

Hi,
 
We are using our own serial device through a usb-Rs485 (2-wire bidirectional) converter using N-VISA serial communications vi's. Since we have commands that may return data from the device with varying lengths of data (10 bytes to 3000 bytes) we would like to know when the first characer of the reply comes in. This will tell us the reply is coming and to wait for the rest of it. If the reply does not come in, we can then issue a retry immediately. All replies start within 100 ms of the command, for example. If we can't detect the first character we have to wait a time greater then the longest anticipated reply to attempt the retry or else a collision may occur if the reply is acutally coming in.
 
The problem is that the serial port tends to buffer up a number of bytes coming back before they are indicated by the "# bytes on serial port" vi. There may be 14 characters, for example, in the buffer before it detects that there are any bytes available at all, even though we are only looking for one byte.
 
Is there a way to know the first byte has returned by some other means, dll or api or detection of rx line change or control line change? Is there another way around this issue.
 
Thanks for your help.
 
Ron Larson
0 Kudos
Message 1 of 3
(2,656 Views)

Hello. I suggest you try using the example VI (menu help --> Find Examples --> Serial --> Basic serial write and read.vi). In this program you can specify the number of bits you're looking for, the baud rate, flow control, stop bit, etc. It may help you solve your problem.

Cheers,

Ali

Message 2 of 3
(2,639 Views)
The other possible option is to use a VISA Event. There is an event for serial character. If you look in the shipping examples, there is an example called Detect Break Event. It cna be modified by just changing the enum for the event type.
0 Kudos
Message 3 of 3
(2,635 Views)