ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA comport wrong data

Having this code getting data from a balance. The code fails every 3 - 4 time.

When things goes well the concated string is : \s1863.57\s\sg\r\n\s1863.57\s\sg\r\n (code display)

When thins goes wrong it could be : p\03\03;\r\n or \03\03;\r\n

What am I doing wrong ?

 

snip.png

0 Kudos
Message 1 of 19
(4,513 Views)

Michael.Koppelgaard wrote:  What am I doing wrong ?

You are using the Bytes At Port.  Because you are dealing with a message that includes a termination character, let VISA use that.  So instead of the Bytes At Port, just tell the VISA Read to read more bytes than you ever expect in a message.



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 19
(4,503 Views)

As Crossrulz pointed out, using Bytes at Port is just wrong.

 

The reason it fails is that you read the message when you have 6 or more bytes.  But the full message string is 13 characters long when you factor in the decimal point, spaces, "g" and CR and LF.

0 Kudos
Message 3 of 19
(4,473 Views)

Oh yes you are right. I will try to change. Still have some wrong characters coming

0 Kudos
Message 4 of 19
(4,459 Views)

No still get weird characters, and I know the parity baud rate etc. is correct

0 Kudos
Message 5 of 19
(4,447 Views)

Can you post your current code?

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 6 of 19
(4,441 Views)

It's possible that the scale actually send these characters (or that the communication get disturbed)

so some sort of error checking should be implemented.

Possible checks: min length and last characters a '\sg\r\n'  and a number conversion without warning/error.

 

If it's of any importance to reliable read the values: Ask the scale manufator if there is a protocol including a checksum!

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 7 of 19
(4,437 Views)

My code now is like this. How do you propose building extra checks ?

I modified the output from balance so the output is the balance data e.g.: 1003.26 or 126.52

snip.png

0 Kudos
Message 8 of 19
(4,421 Views)

You discard all characters when running into the timeout if the last packet is less than 9 bytes. This seems to be wrong as strings will be incomplete.

 

Norbert

 

 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 9 of 19
(4,415 Views)

Your right. TWill try to change. Might not be before friday. Will return. Thank you all for your help 🙂

0 Kudos
Message 10 of 19
(4,398 Views)