LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to send byte data to serial port

Solved!
Go to solution

Hello,

 

I am trying to communicate with a non-commercial device that uses RS-232 for communication. I'm using the "simple serial" example vi approach. I know all the correct settings I need ( baud rate, stop bits, parity etc...) so I know that won't be an issue. The question I have is more around implementing what I want to send in the correct format in LabVIEW.

 

My understanding is that VISA expects the message to be supplied as a string type. I was going to simply use the byte-array-to string approach but the problem is that some of the data I will be sending will be numbers that aren't representable in one byte. For example the data I'm trying to send may look like this:

 

MESSAGE HEADER: (decimal)

 

msg[0] = 1

msg[1] = 63

msg[2] = 0

msg[3] = 6300

 

DATA PORTION (decimal):

 

msg[4] = 'C'

msg[5] = '!'

msg[6] = 76509

......

 

How can I work with values as integers so that I can peform arithmetic operations on them, but still have them be stores as U8 byte types for my string input to visa? Should I just forget that function and instead type cast everything as a string value?

 

Thanks!

0 Kudos
Message 1 of 4
(8,614 Views)
Solution
Accepted by topic author TestEngineer11

Personally, I am a big fan of Flatten Into String and its opposite Unflatten From String.  Those functions can handle any data type and just flattens the raw data into a string data type.


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 2 of 4
(8,611 Views)

Thanks for feedback. So if I have an array of integers and I pass them through the "flatten to string" function, will VISA correctly transmit that to the serial port? Because when I look at the output it looks like garbage. See attached example.

0 Kudos
Message 3 of 4
(8,608 Views)

Setting the proper display style(s) helps.  For the numerics, right click and choose Visible Items->Radix.  There will be a little icon show up in the control/indicator showing which radix (display format) is being used.  You can click on that icon and choose a different format.  I used "Hex".  Similarly, you can right-click on the string and choose Visible Items->Display Style and then choose the hex format.

 

Also note that I wired up a FALSE constant to the "Prepend Array or String Size" so that the size is not added to the beginning of the string data.


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 4 of 4
(8,591 Views)