From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert byte to hex string

I am receiving a single byte using the VISA functions via RS232 from an embedded controller. Each byte is received as formatted as ASCII text, as that is how the VISA functions intepret things, but I want to view the hex values of the bytes received, so I am using the attached VIs to first cast the byte received into a U8, and then converting it back into a hex string. I feel that there is probably a way to do this in one step, but I can't figure it out. Does anyone know of a way to do this all in one go?That is convert the received byte directly into a hex string.

 

~Benjamin

 

Image.JPG

0 Kudos
Message 1 of 10
(10,702 Views)
Put an indicator on the string wire coming out of the VISA Read.  Right click and set it for Hex Display.
0 Kudos
Message 2 of 10
(10,690 Views)

Would it be possible to cast from Bytes to HEX ? Not just for viewing purposes.. 

0 Kudos
Message 3 of 10
(7,983 Views)

What exactly do you mean?

 

Bytes are bytes.  Hex is one way of displaying the numerical value of the bytes.

 

Do you want it to become a string of alphanumerical characters? For example, you get a byte that is 255, and you don't want it to be a numeric that is shown as "FF", but you want it to be a string with the characters "F" and "F"?

 

If so, look at the string palette >> Number to String and get Number to Hexadecimal string.

Message 4 of 10
(7,975 Views)

string to hex.png

 

Something like this should do the job...

 

Deceased.

Message 5 of 10
(7,972 Views)

Well, I'll elaborate more on my problem.. 

Actually I'm working on a TCP IP LabVIEW server and a C++ CSocket client application. 

The LabVIEW server should send IEEE 754 64-bit floating point measures (in binary) to the client, which decodes those recieved bytes as floating point numbers. 

I'm new to both labview and Socket programming, but from what I understood, when it comes to TCP IP communications: LabVIEW only sends data in a string form.

Since sending binary arrays is not allowed, I thought transforming those 64 bit arrays into hexa strings and sending them over the TCP IP connection should do the job. What do you think? 

Thank you. 

0 Kudos
Message 6 of 10
(7,964 Views)

Well, I'll elaborate more on my problem.. 

Actually I'm working on a TCP IP LabVIEW server and a C++ CSocket client application. 

The LabVIEW server should send IEEE 754 64-bit floating point measures (in binary) to the client, which decodes those received bytes as floating point numbers. 

I'm new to both LabView and Socket programming, but from what I understood, when it comes to TCP IP communications: LabVIEW only sends data in a string form.

Since sending binary arrays is not allowed, I thought transforming those 64 bit arrays into hexadecimal strings and sending them over the TCP IP connection should do the job. What do you think? 

Thank you. 

0 Kudos
Message 7 of 10
(7,959 Views)

With that description, it sounds like you want the Typecast function.  It converts data from one datatype to another without changing the underlying bytes.  You determine what datatype you want it to become by wiring that datatype into the top.  So if you had a string and want it converted to an array of U32's, you'd wire a U32 array constant to the top.  If you have an array of U64's and want to convert it to a string, you wire a string to the top.  Actually, you don't even have to wire the string because that is the default datatype for Typecast if nothing is wired to the top.

Message 8 of 10
(7,958 Views)

You should be able to type cast the DBL to string and send it, at the end of the day the string is just 1s and 0s.. You can reconstruct it at the other end,

 

Deceased

Message 9 of 10
(7,957 Views)

IsmaNaj wrote:  The LabVIEW server should send IEEE 754 64-bit floating point measures (in binary) to the client, which decodes those received bytes as floating point numbers.

In that case, I prefer to use the Flatten To String and Unflatten From String functions to convert your data to/from the string.  I prefer these over the Type Cast since you can specify the Endianness of the data.  The Type Cast only uses Big Endian.

 

Also, it is a common practice to send the number of bytes in a message before the message.  So then the client reads 4 bytes to get an I32 and then uses that value to know how many more bytes need to be read.


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 10 of 10
(7,938 Views)