LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

building a hexadecimal string

Solved!
Go to solution

I want to send a hexadecimal string to a device.

 

0000 0000 0006 0103 07D2 0001

 

If I send the string as written above, I get the expected response.

 

The 07D2 is a register number and I would like the user to be able to choose the register. I created this code to see if I could insert the required hexadecimal string into the full string.hex string snippet.png(note that the string constants are set to hexadecimal display)

 

This works great, producing the correct hex string, 0000 0000 0006 0103 07D2 0001.  I send the string and the device responds as expected.

 

Since I want the user to be able to choose the register I created a mechanism for that and replaced the substring constant (07D2) with that code.

 

hex string snippet 2.png(note that the value entered in the D-Reg No. control is 2003.)

 

Although the conversion from the I16 control to a hex string produces 07D2, the resulting hex string from the replace string subset function produces this, 0000 0000 0006 0103 3037 4432 0001.

 

Can anyone offer any advice or perhaps suggest another method? 

 

Thanks.

 

John.

0 Kudos
Message 1 of 4
(2,342 Views)
Solution
Accepted by topic author JFMoynihan

First, when formating strings you are better off using the Fromat String Vi rather than replacing elements in a string. However in this case your format to string is retrungin you the ASCII representation of the number and hence you get the wrong value in the output string. What you need to do is replace the bytes in the string with the actual binary data, not the ASCII representation. One way to accomplish that is to simply flatten the number to a string and then replace the bytes. You could also typecast the number as well and then replace the data. Here is an example.

 

binary string format.png



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 4
(2,336 Views)

Adding to Mark's comments, here is an other way but along the same lines.

replace.png


CLA CTAChampionI'm attending the GLA Summit!
Subscribe to the Test Automation user group: UK Test Automation Group
0 Kudos
Message 3 of 4
(2,331 Views)

I typecast the number to a hexadecimal string and that did the trick.  Thanks.

0 Kudos
Message 4 of 4
(2,328 Views)