09-19-2016 01:49 PM
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 ?
09-19-2016 02:16 PM
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.
09-19-2016 05:25 PM
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.
09-19-2016 11:55 PM
Oh yes you are right. I will try to change. Still have some wrong characters coming
09-20-2016 02:04 AM
No still get weird characters, and I know the parity baud rate etc. is correct
09-20-2016 03:11 AM
Can you post your current code?
Norbert
09-20-2016 03:52 AM
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!
09-20-2016 09:31 AM
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
09-20-2016 09:46 AM
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
09-20-2016 02:27 PM
Your right. TWill try to change. Might not be before friday. Will return. Thank you all for your help 🙂