LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Read Byte count switching between 2 values

Solved!
Go to solution
Solution
Accepted by topic author NickBl

You need to either a) end with a termination character enabled, or b) specify a number of bytes to read which is equal or less than the number you send. 

 

In the latter case, you'll read exactly the number of bytes you enter. The VISA Read will trigger a warning, with a message something like "The number of bytes read was exactly equal to the number requested. Ensure that the buffer doesn't still contain more data." Here, you're being told that there might still be more in the buffer to be read, which is exactly what would happen if you read fewer bytes than you send.

 

In you run this in a while loop, you'll discover that gradually (or perhaps not so gradually) the buffer will fill up with the bytes you're not reading each iteration. This will give you an error about the buffer being full (I think this is output from VISA Write).

 

The remaining error to consider is that due to timeout - when you set the number of bytes to read to be too high, and don't enable termination characters. In that case, the Read will empty the buffer, but if you don't write more, it will just sit there waiting for the additional bytes. Eventually, it will timeout (10 seconds is the default I believe).

 

So in conclusion, it's possible to avoid the use of termination characters, but it isn't so straightforwardly simple. Given the choice I would almost always choose to use termination characters. If you're wanting to use the CR and LF characters in the messages you're sending, you can use a different character for termination. If you really want to avoid them entirely (term chars, not CR/LF) then you can use the Bytes at Port to tell your VISA Read how many bytes to read, but now you need to add appropriate Wait nodes, and check more hasn't arrived, and so on.


GCentral
0 Kudos
Message 11 of 13
(898 Views)

Ok thank you! That's the problem I was running into and I didn't know why it would only work if I specified the exact amount of bytes. But okay, I understand how it works now. I'm going to go with pre-defining the amount of bytes specified since that works better in my case.

0 Kudos
Message 12 of 13
(887 Views)

@NickBl wrote:

Is there a way to exclude that \n when creating my file to read in? Because right now I'm wiring the numbers I put in to a write delimited spreadsheet.vi



Yes, simply use the search replace string function to replace all carriage returns (\n) in the string with empty string constants.

 

This removes any need to spin strings forward/backwards or to know the length of the string. It will also remove any inadvertently added end of line constants mid string pre-transmit.

 

James

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 13 of 13
(882 Views)