LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to display raw, not ascii, bytes from serial port?

Hello, I have an instrument that outputs raw data, not ascii, bytes to a serial port.  How do you display raw data, not ascii, bytes from a serial port?  Since raw data bytes are not displayable, there is got to be something in labview to interpret/display the received bytes the way it is as data in HEX or Binary.  The STRING-TO-HEX and STRING-TO-BINARY functions are not applicable in this case because the bytes were not string type in the first place.  For example, if the receive byte is 0x4D, I need to display 4D in HEX or 77 in Decimal and not the ascii character "M" corresponding to 0x4D ascii code.  I am using a VISA-RD function currently to receive the data from a COM port.  VISA-RD outputs string type.  Thank for any feedback or suggestion in advance.
0 Kudos
Message 1 of 4
(3,956 Views)
Right click on your string indicator and select Hex Display.
0 Kudos
Message 2 of 4
(3,952 Views)


BC@Baxter wrote:
...The STRING-TO-HEX and STRING-TO-BINARY functions are not applicable in this case because the bytes were not string type in the first place...

Of course they are string type, just not formatted in a human readable form. So, YES, these functions are not appropriate.


BC@Baxter wrote:
For example, if the receive byte is 0x4D, I need to display 4D in HEX or 77 in Decimal and not the ascii character "M" corresponding to 0x4D ascii code. 

Dennis is right, but there is no "decimal" display for strings, so the second requirement needs a tiny little bit more code.

If you have a single byte string, you can typecast it into a U8 number and set the display format as decimal, hex, octal, or binary as desired. In decimal, it would display the number 77. Since it is now a numeric, you can even do math with it. 🙂

In general, the string has multiple bytes, and you would typecast it into an array of U8 numbers (Since this is an often used function, there is also a "string to byte array" which does the same thing).

Typecasting is the secret. You can e.g. easily typecast 2 bytes into a U16, 4 bytes into a I32, 8 bytes into a DBL,  etc. For more detailed requirements, there is also the "unflatten from string". Check the online help for details. Good luck!


 


 

0 Kudos
Message 3 of 4
(3,929 Views)
Thanks for the info.  It works now.  Really appreciate it.
0 Kudos
Message 4 of 4
(3,918 Views)