LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read known length RS-232

This seems simple enough, but I am having difficulty figuring out the most efficient way of doing it.

 

I have multiple different boards that I am testing on an Automated Test Fixture

 

The microcontroller on each of the boards spits out a stream of RS-232. Each board has a different byte length. These byte lengths are known for each of the different boards. Each board has a different dead time between when it spits out this data.

 

So, for example, one of the boards spits out a 32 byte stream of RS-232 data every 6 seconds. I then decode this into the multiple different values that these bytes represent and do work on those values.

 

I have attached my current way of reading this byte stream, note that the Configure serial port is not in this subVI but I have set it up.  There has got to be a better way to do this. My current method misses some data and sometimes confuses the order of the bytes, seemingly catching the middle of the data stream and then the start of the next to make up the total length.

 

So, any suggestions?

0 Kudos
Message 1 of 7
(3,505 Views)
Does the micro spend a termination character such as a line feed or carriage return? If so, enable it with the VISA Configure Serial Port and simply set the number of bytes to read to some arbitrarily high number. You may have to do a single dummy read to get a partial read at the beginning. After that, you would be synched to the transmission.
0 Kudos
Message 2 of 7
(3,497 Views)

Does the data stream sent out be these boards have a termination character? 

 

If so enable the "term char" on the serial setip vi and set your VISA read to a high value.

 

VISA will read until is sees the termination character or times out.

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 7
(3,490 Views)

Unfortunately, no. The micro does not send a termination character.

 

I am just given a certain number of bytes to expect.

0 Kudos
Message 4 of 7
(3,485 Views)
Perhaps you can start by requesting one more byte than is expected. Than when it times out, discard that data as it may be incomplete. Subsequent reads of the specified byte count should be okay as long as your loop time is less than the 6 seconds you mentioned. You would want to set a fairly short VISA Read timeout value as well.
0 Kudos
Message 5 of 7
(3,476 Views)
And do a flush buffer before that first read.
0 Kudos
Message 6 of 7
(3,461 Views)

@Dennis_Knutson wrote:
Perhaps you can start by requesting one more byte than is expected. Than when it times out, discard that data as it may be incomplete. Subsequent reads of the specified byte count should be okay as long as your loop time is less than the 6 seconds you mentioned. You would want to set a fairly short VISA Read timeout value as well.

If the timeout is short, won't you get a few timeouts in your subsequent reads?

 

 


@bshover wrote:

This seems simple enough, but I am having difficulty figuring out the most efficient way of doing it.

 

I have multiple different boards that I am testing on an Automated Test Fixture

 

The microcontroller on each of the boards spits out a stream of RS-232. Each board has a different byte length. These byte lengths are known for each of the different boards. Each board has a different dead time between when it spits out this data.

 

So, for example, one of the boards spits out a 32 byte stream of RS-232 data every 6 seconds. I then decode this into the multiple different values that these bytes represent and do work on those values.

 

I have attached my current way of reading this byte stream, note that the Configure serial port is not in this subVI but I have set it up.  There has got to be a better way to do this. My current method misses some data and sometimes confuses the order of the bytes, seemingly catching the middle of the data stream and then the start of the next to make up the total length.



Can you post some example strings? It's usually best to do some sort of string match. If that's still not possible then you have to be really clever and poll for bytes on the port  untill you go x ms with no bytes on the port. Then request the right number of bytes using long timeouts. Example:

 

SERIAL_READ_BD.png

0 Kudos
Message 7 of 7
(3,427 Views)