07-29-2020 02:54 AM
Solved! Go to Solution.
07-29-2020 03:27 AM
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!
07-29-2020 03:42 AM
07-29-2020 07:28 AM
@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
07-29-2020 08:05 AM - edited 07-29-2020 08:10 AM
@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! 😀
07-29-2020 09:01 AM
@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.