Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Erroneous zero byte at visa serial read

Solved!
Go to solution

Hi All,

 

Currently trying to debug a problem i'm having with a Labview2011 VI and USB-485/2 device.

 

The setup has been simplified to have port 1 wire to port 2 in a 2wire-auto configuration. As described here:
http://digital.ni.com/public.nsf/allkb/D5CC369B3E3E6F0586256D1600563245

and here:
https://decibel.ni.com/content/docs/DOC-4169

 

Port 1 transmits an 8 byte message using visa-write then commences a 8 byte visa-read. (contained in a 10hz timed loop)

Port 2 is configured in a simple loop using the wait for byte visa event, then visa-read 8 bytes, wired directly into visa-write.

For Port 1 data transmitted, data received and the visa-read error code are logged to disk.

 

The setup sucessfully transmits are receives data without loss ... so the loop back is working..

 

However! every now and again, an additional zero byte is read from the visa-read of port1.

 

Almost all port 1 visa-read operations return the "1073676294" code (The number of bytes transferred is equal to the requested input count. More data might be available) which is fine. Very occasionally though, the error code "0" is return (operation completed sucessfully). This "0" code seems to be associated with the additional byte in the receiver.

 

This is causing a problem because it throws the command/response pairs of the intended application out of sync.

 

I have tried numerous buad rates, visa-read timeouts and transmit frequencies, the problem remains. Adding a visa-flush buffer prevents the error from propogating, but does not stop it occuring and upsetting the command/response logic.

 

Any ideas would be appreciated.

 

0 Kudos
Message 1 of 6
(5,026 Views)

Care to share your code?

 

If you are using the Bytes At Port property node, just stop it.  You expect 8 bytes, so just read 8 bytes.

 

What I'm thinking is happening is you are not waiting long enough for the data to come in and when you do the Bytes At Port, it returns 0.  So you read 0 bytes.


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 6
(5,015 Views)

Cheers Crossrulz!

 

I'm not using the bytes at port property, as you say, just reading the required 8 bytes.  However i may have resolved this by disabling the terminator character, though I'm not sure why this would cause the result it did.

 

Will attach code for completeness asap.

 

Thanks again !

 

 

 

0 Kudos
Message 3 of 6
(4,973 Views)
Solution
Accepted by lt.alias

If you are sending true binary data (which it sounds like you are), then you should have the termination character disabled.  Remember that the VISA Read will complete when the FIRST of the following happen: the desired number of characters is read, the termination character is found, there is a timeout.  So if there is a 0xA in your data, that will stop the read before you would want it to.


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
Message 4 of 6
(4,961 Views)

code snipit for completeness..

0 Kudos
Message 5 of 6
(4,934 Views)

Just so you know, there is no need to continuously set the instrument timeout.  You can just set that with the input on the Configure Serial Port.

 

And this probably is not the appropriate place to use a timed loop.  A normal while loop will be just fine.  Just put in a 100ms wait inside of the loop.  The timed loop does a lot under the hood that I'm sure you don't want.


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 6 of 6
(4,919 Views)