LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Arduino VISA read binary data

Solved!
Go to solution

Hi everyone,

I am quite new with LAbView and I am struggling with the reading of binary data from Arduino.

I have an Arduino DUE which sends two values int16 to the serial port, each loop. So I have to read from serial and parse 2 and 2 bytes.

I have 2 question:

  • Does VISA read read binary data? As I can see, it reads only ASCII strings, how can I make it read bytes?
  • How can I parse my two signal and then rapresent them  separately?

I attach my block diagram, which doesn't work (I did it for strings).

 

Thank you for your time!

0 Kudos
Message 1 of 7
(3,309 Views)

Technically all data is binary.

 

First you need to disable the termination character.  If you are getting 2 INT16 values as a total 4 bytes, you'll wind up getting a short message if one of those bytes is equal to the termination character.  You can get rid of the property node that sets the ASRL End Out termination character.

 

What does the data look like in the string control?  If it is truly binary, as in not human readable, you don't want to string, but to typecast it.

 

Attach an actual VI instead of a picture.  Save the data that shows up in the "numeric data" string as the default in that control before saving the VI and attaching it to your message.

0 Kudos
Message 2 of 7
(3,296 Views)

@tyar97 wrote:
  • Does VISA read read binary data? As I can see, it reads only ASCII strings, how can I make it read bytes?

Common misconception.  VISA Read just reads bytes.  The indicators just default to show strings in ASCII.  You can change them to show Hex data or "/ Codes" to make it more obvious.

 


@tyar97 wrote:
  • How can I parse my two signal and then rapresent them  separately?

Use Unflatten From String with an array of I16 as the data type and you will get an array with your two data points.

 

Some other issues I see:

  1. Since you are sending binary/hex/raw data, you need to turn off the Termination Character and remove any reference to it.  Termination Characters are used for ASCII messages.
  2. No need to set the buffer size or to clear it.
  3. You might want to really think about your message protocol.  The issue I see is a lack of framing to make sure you are reading the data in full messages and not getting out of sync.  For binary/hex/raw data, that typically involves a start byte (0x2 is common), a message ID, the data, and a checksum.  You probably don't need the message ID here since you are only sending 1 type of message.  But with this setup, you can read until the start byte is read, then read the rest of the data and verify the checksum.  If the checksum passes, then you know you have a full valid message.  If not, then throw away what you just read and start over looking for the sync byte.

 

 


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
Message 3 of 7
(3,295 Views)

Thank you for your reply.

 

 


@crossrulz  ha scritto:

 

You might want to really think about your message protocol.  The issue I see is a lack of framing to make sure you are reading the data in full messages and not getting out of sync.  For binary/hex/raw data, that typically involves a start byte (0x2 is common), a message ID, the data, and a checksum.  You probably don't need the message ID here since you are only sending 1 type of message.  But with this setup, you can read until the start byte is read, then read the rest of the data and verify the checksum.  If the checksum passes, then you know you have a full valid message.  If not, then throw away what you just read and start over looking for the sync byte.

I am sorry but I do not know how to do what you have suggested using LaVIEW, particularly how to implement the checksum, may you help me?

 

I did the rest but know I have this error from Unflatten from String:

"Unflatten or byte stream read operation failed due to corrupt, unexpected, or truncated data."

What may be the cause?

 

Thank you in advance.

 

0 Kudos
Message 4 of 7
(3,247 Views)
Solution
Accepted by topic author tyar97

@tyar97 wrote:

I did the rest but know I have this error from Unflatten from String:

"Unflatten or byte stream read operation failed due to corrupt, unexpected, or truncated data."

What may be the cause?


Most likely you are not sending the data the way you claimed.  It might help if you posted your Arduino code as well so we can see exactly what your message protocol is.

 

Another possibility is you missed a Boolean input on the Unflatten From String.  There is an input for "data includes string or array size".  It defaults to TRUE.  You will want that to be set to FALSE.


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 5 of 7
(3,244 Views)

Ouch, you are right I lost that false, now it seems it works as it has to!!

 

Thank you for your help!!

0 Kudos
Message 6 of 7
(3,234 Views)

@tyar97 wrote:

Ouch, you are right I lost that false


Don't take it too hard.  I couldn't count the number of times I have messed that up.


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