LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Bytes at Port is zero after VISA Write

Solved!
Go to solution
I am trying to connect mahr millitron with VISA Serial, but in my code, I am getting zero at "bytes at port". On the other hand, when I run "Simple Serial" example in Labview, firstly Labview runs E4 error later it works perfectly. Also, my code ran sometimes perfectly. Why is my code not working?
Download All
0 Kudos
Message 1 of 6
(2,492 Views)
Solution
Accepted by topic author Judeau

1) Right click on your string constant and make sure “Display \-codes” is selected. Do you still see the I\r string in there or did it suddenly change to look like I\\r?

 

2) Use of Bytes at serial port is ALWAYS wrong when communicating with an instrument. Instead enable the Termination Boolean input on the Serial Port Init VI and choose the correct termination character for your instrument. In your case is is almost certainly 13 for the carriage return character. Then remove the delay and the Bytes at Serial Port node and call directly VISA Read with a number of bytes to read that is guaranteed to be larger than your expected answer string. VISA Read will return when one of these conditions occurs, whichever occures first:

1) Any error occured in the underlaying communication layer

2) The enabled termination character was received

3) The number of requested bytes was received

4) The session timeout has elapsed

 

No ned for a Bytes at Serial Port at all nor a delay in front to prevent your program from querying that property before the device had a chance to even respond and flaky communication because that delay may be generally much longer than really needed (slowing down your instrument communication unnecessarily) but on occasion still to short for the device to fully respond when it is at that moment busy with something else!

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 6
(2,475 Views)
“Display \-codes” has worked. Thanks a lot.
0 Kudos
Message 3 of 6
(2,466 Views)

@rolfk wrote:

2) Use of Bytes at serial port is ALWAYS wrong when communicating with an instrument.


"Always" is a little strong.  It does have its place.  But 99.9999999999999999999999999% of the time, it should not be used to tell the VISA Read how much to read.

Shameless plug: VIWeek 2020/Proper way to communicate over serial


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

@crossrulz wrote:

@rolfk wrote:

2) Use of Bytes at serial port is ALWAYS wrong when communicating with an instrument.


"Always" is a little strong.  It does have its place.  But 99.9999999999999999999999999% of the time, it should not be used to tell the VISA Read how much to read.

Shameless plug: VIWeek 2020/Proper way to communicate over serial


That’s why I added “when communicating with an instrument”. In that context I’m convinced that ALWAYS is not even a tiny bit to strong! The resulting code from using Bytes a Serial Port is always more complex, more error prone and requiring more corner case handling and still never be fully reliable, especially in combination with arbitrary delays to make the whole thing work (most of the time)!

 

When there is a termination character, always use it, otherwise when it’s a fixed size protocol, either explicit through lengths embedded in the stream or implicit from the message identifier in a header, use that. If none of this is true, shoot the developer of that device to the moon in a one way rocket! 😀

Rolf Kalbermatter
My Blog
Message 5 of 6
(2,389 Views)

@rolfk wrote:

When there is a termination character, always use it, otherwise when it’s a fixed size protocol, either explicit through lengths embedded in the stream or implicit from the message identifier in a header, use that. If none of this is true, shoot the developer of that device to the moon in a one way rocket! 😀


Best summary ever.  Though, now you got me wanting to watch The Honeymooners.

Spoiler
I would post a video, but YouTube is blocked for me.

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
(2,377 Views)