LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

integer to hex string

Solved!
Go to solution

Hello gents,

I am having this problem trying to send a string of 18 bytes in HEX according to my device request schema using the TCP Write.vi

As you can see in the attachments, if I use the concatenate string function and hard code the 18 bytes as constant as HEX display the message is valid and the device respond correctly.

The next step is to have byte F and byte 11 as user input so I have replaced the two constants "14" and "15" with two numerical inputs and using the Number To Hexadecimal String i connected the output of the function to Byte F and Byte 11.

The output of the Number To Hexadecimal String is correct as I input the value of 20 and the function converts to 14 (hex) if I have a indicator set to normal display.

If I change the indicator to Hex display then I get the ASCII representation of the value 20.

The problem is if I connect the output of the Number To Hexadecimal String to the Concatenate String instead of the constant the value 20 is represented as "3134" as ASCII.

 

How can I convert the value 20 that is an I32 to hex 14?

I have attached some screen shots of the code working with constants and not working with I32 to Hex conversation.

 

 

Download All
0 Kudos
Message 1 of 6
(7,201 Views)

Use 'number to hexadecimal string' in the string conversion palette. You can also use format into string.

 

numbertohex.png

 

If you are displaying (doesn't change the value) the number as a hexadecimal string then it is showing the hexadecimal character codes for the ASCII. You will get 2 'characters' per byte/ASCII character.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 2 of 6
(7,174 Views)
Solution
Accepted by topic author Marken

Since your values can only go into a single byte, change your data type of your two inputs to be U8 or I8.  After than, just use Type Cast to change those bytes into a string.


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 3 of 6
(7,164 Views)

Hi Sam,

Thank you very much for your time.

I have done exactly what you have suggested and the function converts the integer 20 into hex14 as you see on the attached picture.

But if I connect the output of the 'number to hexadecimal string' to the "concatenate strings" function it will insert the ASCII values, please picture on the output labelled "Request"

 

What I am doing wrong Sam?

 

Regards

Marian

 

0 Kudos
Message 4 of 6
(7,120 Views)

Hi Crossrulz,

 

Thank you for your time, the typecast works OK.

 

Kudos to you.

 

Regards

Marian

0 Kudos
Message 5 of 6
(7,108 Views)

Hi Marken,

 

another approach:

check.png

Note the radix/display mode of all the constants in the image…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 6
(7,101 Views)