Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

What might cause adding a line space (or a line with "%") before the output value in read buffer from VISA

I have been changing the pattern of a machine program, which originally built with flat sequence structures, to a state machine form. However, I have faced a problem like shown below. As you see in the picture, the old version and the new version have the same set, but the results are different. I assume that the space(it is empty space in the picture but sometimes it comes with "%" character) before the value gives me "0" but I have no idea where that space from or how to get rid of the space. Please help me!

 

Old VersionOld Version

New VersionNew VersionSub VI 2Sub VI 2

Old versionOld versionOld Version resultOld Version resultNew versionNew versionNew version valueNew version value

0 Kudos
Message 1 of 3
(2,884 Views)

I have been changing the pattern of a machine program, which originally built with flat sequence structures, to a state machine form. However, I have faced a problem like shown below. As you see in the picture, the old version and the new version have the same set, but the results are different. I assume that the space(it is empty space in the picture but sometimes it comes with "%" character) before the value gives me "0" but I have no idea where that space from or how to get rid of the space. Please help me!

 

Old VersionOld Version

New VersionNew VersionSub VI 2Sub VI 2

Old versionOld versionOld Version resultOld Version resultNew versionNew versionNew version valueNew version value

0 Kudos
Message 2 of 3
(2,897 Views)

What instrument are you communicating with?  What other transactions happened before this one?

 

My guess is that the core of your issue is that Bytes At Port.  It appears that your instrument ends its data with an end of line as a termination character.  If this is true, then you can get rid of that wait and the Bytes At Port and just tell the VISA Read to read more bytes than you ever expect in a message.  I tend to use 50 or 100.  You will need to make sure the Enable Termination Character is enabled and the correct termination character is set when you use the Configure Serial Port.

 

Here is the why: If the termination character is enabled, the VISA Read will read until the first of the following conditions: 1) it reads the number of characters it was told to, 2) it reads the termination character, or 3) it times out.  So by setting the bytes to read to a really high number, we are relying on the termination character to stop the read.  This will ensure we got the entire message.

 

So back to your problem and what I suspect is happening.  Since you are using the Bytes At Port, you are just reading everything that is at the port when you check to see how much data is there.  You do not know if you are getting the full message.  You do not know if more is in the process of coming in.  Furthermore, you are relying on your wait being long enough.  Wait too long and you are wasting time.  Wait too short, and you miss data and/or data gets confused.  So my thought is that the empty line is actually the end of a previous message.


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 3 of 3
(2,855 Views)