04-03-2013 11:16 AM
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.(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.
(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.
Solved! Go to Solution.
04-03-2013 11:23 AM - edited 04-03-2013 11:31 AM
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.
04-03-2013 11:27 AM
Adding to Mark's comments, here is an other way but along the same lines.
04-03-2013 11:38 AM
I typecast the number to a hexadecimal string and that did the trick. Thanks.