NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Covert ASCII to HEX

Solved!
Go to solution

Hello, 

I have a String "\$Bis,1,20240130,4096,PS,1#\$Prd,Z189055,012345678,00.00,0,BCH,20240130#\$Nam,AV4I PSM-HPLNA Q4#\$EndBis,A8,E0#"

I want to convert it to Hex,

Output should be, "244269732C312C323032343031332C343039362C50532C3123245072642C5A3138393035352C3031323334353637382C30302E30302C302C4243482C323032343031333023244E616D2C415634492050534D2D48504C4E412051342324456E644269732C41382C453023"

I have try to achive this uisng For loop, But I did not get answer. 

Please help if you have any idea about that


0 Kudos
Message 1 of 7
(284 Views)

TestStand is not exactly what I'd call a programming language, so it has some limitations... what are the reasons against implementing this conversion in a code module?

0 Kudos
Message 2 of 7
(275 Views)

That I really did not understsand. I have try to to with several expession but did not work.

Do you have any idea how can I do this, some new method or any idea?

0 Kudos
Message 3 of 7
(260 Views)

What you are trying to achieve could be done more conveniently using LabVIEW/.net/ Python.

This code can be called from TestStand.

0 Kudos
Message 4 of 7
(231 Views)

@Rshah31 wrote:

I have try to achive this uisng For loop, But I did not get answer. 


A for loop is a programming structure that does not directly operate on data. Show us what you tried.

(You could have said you tried a screwdriver and we still would not know what you did!).

 

ASCII and HEX are both very vague terms and it is not really obvious what you are looking for.

 

ASCII is an ancient convention that assigns 7-bit patterns to readable or control characters.

HEX is just a formatting convention for binary data, reducing four adjacent bits to an ASCII character 1..F.

 

So what exactly do you have and what do you want. Maybe take a step back and explain your use case. For example your output is at least missing the "\" (i.e. all "\$ are reduced to "$"). Does "\" have a special meaning?

 

Message 5 of 7
(210 Views)
Solution
Accepted by Rshah31

Like everyone else said, I would use NI carefully when converting data like this. But it is possible, even though TestStand is not meant for these things. Basic steps inside a for loop:

 

1) Get the full length of your input string - Len(Locals.InputString) and create a for loop

2) Get one char with Mid function e.g. Locals.OneChar = Mid(Locals.InputString, Locals.LoopVariable, 1)

3) Inside the loop, convert each char to a number with Asc() function

4) Add the received number as a hex string to your output string buffer e.g. Locals.OutputString += Str(Locals.OneChar, "%02X")

 

Input: \$Bis,1,20240130,4096,PS,1#\$Prd,Z189055,012345678,00.00,0,BCH,20240130#\$Nam,AV4I PSM-HPLNA Q4#\$EndBis,A8,E0#

 

Output: 5C244269732C312C32303234303133302C343039362C50532C31235C245072642C5A3138393035352C3031323334353637382C30302E30302C302C4243482C3230323430313330235C244E616D2C415634492050534D2D48504C4E41205134235C24456E644269732C41382C453023

 

It seems your provided output string disregards the "\" symbol, so you should do something about that as well

0 Kudos
Message 6 of 7
(129 Views)

Thank you for the reply, 

It works---

0 Kudos
Message 7 of 7
(105 Views)