LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Concatenating Hex and ASCII Stings to get one HEX string

Solved!
Go to solution

Hi,

 

I am trying to concatenate a MODBUS Application Protocol Header with a function code and data that I am sending over TCP/IP to a motor controller.  I am running into problems when I try to read the length of my function code and data.  I am using "string length" to read the command data that I am inputting, converting that to a hex number, then concatenating that with some constant strings in hex display and my function code and data which is also in hex display. When I concatenate the lines, the end message is incorrect because (I think) the string length I've read and converted to hex is in ASCII text? 

 

Does this sound like its the problem, and if it is, can anyone help me with fixing it? If that's not the problem can anyone help me figure out what is?

 

Thanks

0 Kudos
Message 1 of 3
(4,453 Views)
Solution
Accepted by topic author drb12345

drb,

 

Converting it to hex will show it as ascii, thats what it is, a human readable number represented in Hex format. If all you want to do is add the raw value then convert this to a char and add it. For example if you have more then 16 data bytes then you will be adding two extra bytes to the end instead of one. 

 

Conc Hex Char.png

 

 

If all you are trying to do is add a byte vale representing the amount of data you are sending then just convert to a single char and add, as shown above. Obviously this means that the string length cannot be greater then 256.

 

Even if you have less then 16 bytes of data so the hex value added onto the end is only 1 char then unless the receiver is meant to be reading a hex value it will still be incorrect. For example 1 in Hex will read as 49 raw.

 

Hope this helps,

 

Rgs,

 

Lucither 

------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
Message 2 of 3
(4,446 Views)

Thanks Lucither,

 

Converting the number to a character was exactly what I needed to do.  I ended up formatting it as an unsigned 16 bit number because the formatting for that value in the header calls for 2 bytes.  Comes out perfectly now.

 

Thanks Again,

 

Dawson

0 Kudos
Message 3 of 3
(4,418 Views)