LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sending hex string to a serial port

i have seen a few examples but i havn't found my answer yet.

i am trying to send a string of hex bytes out a serial port the format being A123D4FF
my problem is that i don't understand how to send A1h out the port and not 'A' '1"

can someone point me in the right direction or show me a vi that does something similar??
0 Kudos
Message 1 of 5
(13,386 Views)
The string that you give to VISA can be viewed as an array of U8 data (there is a handy conversion vi that goes back and forth).

However if you have a string of ASCII that you want to transmit as hex, then you need to convert the string from ASCII to "raw data" and then send that out. I recently had to do this for a serial number vi that I wrote which took a serial number from the user as ASCII then write it to a EEPROM as hex.

I did this by first breaking the ASCII string into chunks of two characters each (so 'A12BC3' would be broken into chunks of 'A1', '2B', and 'C3') then converting each chunk into a number via a scan from string vi. The output gets placed into a new array which, in your case, would then be written out of the serial port.

T
here may be a better way, but this worked quite well and was fast to write.

Hope this helps!
0 Kudos
Message 2 of 5
(13,386 Views)
Try this vi.


cheers
ian.f
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
Message 3 of 5
(13,386 Views)
Right-click on the string constant and select Hex display...now write in A123D4FF...wire that to the serial write and you are now sending the correct binary string, not the readable version of it.

If you build the strings dynamically from e.g. numbers all you need to do is to type cast them to a string. If e.g. you have a U32 value of 45 type casting it to a string will give you a binary string...if you look at it in hex display it will look like this:

0000 002D

The type cast can be found on the advanced -> data manipulation palette. On the string-> string conversion palette you can also find a function to convert an array of bytes to a string so if you already have the data as an array of byte values just use that to get the string to send.
Message 4 of 5
(13,386 Views)
Turn the Hex display on by right click your string control then select
Hex display. You can type in hex value directly.

Hope this help
0 Kudos
Message 5 of 5
(13,386 Views)