LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

optimal reading from VISA

I want to read serial data from my hardware. Messages are constructed like:

Start byte (1 byte) (0xFF)
Message type (1byte)
Data lenght (1byte)
Data (N bytes)
Checksum (1 byte)

 

Hardware sending this messages continious.

 

So my question is Which way for reading is more effective:

1. Read one byte and find start of message (read while value is not 0xFF), then read second byte and analyze and then third byte etc. So you need to read serial port at least 4 times per message.
2. Read 100 bytes - or all available bytes at once and then iterating through it using while loop and shift register.

 

I think that each visa read use computer resource, but also managing shift registers use resource especially if there is a lot of data. So which way is better?

Kind regards

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

What I have done in the past is read all data available at the port.  I use concatinate strings to append this read data to my buffer stored in a shift register.  I then use Search/Split String to find the sync byte.  I can then look at the command byte and byte count using Substring.  Do whatever other processing you need to do from there.  I then used Substring to remove the processed command from my buffer.  This buffer is stored in a shift register.

 

That setup worked pretty well for what I needed.  I believe I found that the VISA Read was the slow part, so I wanted to read as much data as possible at one time.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 5
(2,552 Views)

Multiple VISA reads is not a problem.  It isn't using "computer resources".  And shift registers aren't really using any computer resources that you'd need to worry about.

 

What I do is assume that the buffer is clear when I open VISA.  Then every write command returns a full response, and I'm not getting any other data in the serial port that would interfere with the response, or getting unsolicited messages between write commands.

 

Read 3 bytes.  Check that the first byte is FF.  (If it's not, then you'll have to do figure out how to sort out the error.

Get the value of the 3rd byte.  Let's call it N since it is the number of data bytes.

 

Now Read N+1 bytes.

 

Now you should have the full message and can work with it.

 

Loop repeats for the next Write command, Read 3 bytes.  Read N+1 bytes sequence.

 

0 Kudos
Message 3 of 5
(2,538 Views)

I forgot to write that a program will run on cRIO device. Is it change anything?

0 Kudos
Message 4 of 5
(2,502 Views)

I don't understand your question.

 

What did what you asked before have to do with a cRIO?

 

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