12-24-2018 08:42 AM
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!
Solved! Go to Solution.
12-24-2018 08:51 AM
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.
12-24-2018 08:56 AM
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.
12-24-2018 09:34 AM - edited 12-24-2018 09:35 AM
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.