Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert Hexadecimal String to ASCII in VBAI

Solved!
Go to solution

Good day to NI experts,

 

I would like to ask for help regarding VBAI's Calculator step. Is there any way I could convert Hexadecimal String in to ASCII character? For example 25(Hex) to %(ASCII) or if not in Calculator any other methods? I'll have to send the data through TCP/IP afterward.

 

Thank you very much,
Andrei K. 

0 Kudos
Message 1 of 7
(3,520 Views)

Here's a sample of what you could do. There are also other formaters for the "Format to String" like %08x will pad the resulting string with zeros if the hex value doesn't take up 8 characters.

 

Hope this helps,

Brad

0 Kudos
Message 2 of 7
(3,518 Views)

Sir,

 

Thank you very much for the response but I can't seem to have an ASCII output as required. In my program, I computed for Number of strings and gave me 37Decimal. I converted it to Hex String and gave me 25String. I then converted 25String to Hex and gave me 25Hex. Now, 25Hex should be converted into ASCII. It's ASCII value should have been "%" (percent symbol) and not "19".

 

What has transpired in the program is that the "Format Into String" command has converted the 25 value into 19. When you convert 25Dec to Hex, the result would be 19Hx therefore, it didn't convert Hex into ASCII. Still hopefull that there would be a way to get an ASCII result.

 

Thank you very much,

Andrei k.

Philippines

0 Kudos
Message 3 of 7
(3,507 Views)

Hex to ASCII image

0 Kudos
Message 4 of 7
(3,506 Views)
0 Kudos
Message 5 of 7
(3,505 Views)
Solution
Accepted by topic author andrake

Now I understand what you want. You can actually accomplish this from the TCP step. First you will need to get the length of the string in a numeric like you did in the Calculator step, but then you can send this numeric as a hex ascii string in the TCP step. To do this, have the result of the calculator return the length of the string as a numeric. In the TCP step, add a Write command and Insert a result. Select the numeric output from the Calculator step and choose U8 for the data format. You can use the Normal Display/Hex Display to see the data that will be sent and when viewing normal display, you can see it is a value of '%' when the length is 37. See the attached screenshot to see how I did this.

 

Hope this helps,

Brad

0 Kudos
Message 6 of 7
(3,499 Views)

Hi Mr. Brad,


Wow! That really is the solution. I appreciate and thank you very much for the great help!!!


Sincerely,

Andrei K.

0 Kudos
Message 7 of 7
(3,494 Views)