NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert HEX into String bassed on variables

Hello,

sorry for my bad english i hope you can understand this Smiley Happy

I am looking for a function in Test Stand wich allows me to split a String (HEX Number).
This Function is based on two Variables "Bytepos" and "Length", for example Bytepos = 2 and Length =4,
and convert me then the number that was found.
Is this possible?

I have found function like DelocalizeExpression() or Len(), but i have the desired result.

I hope you can help me
0 Kudos
Message 1 of 4
(4,306 Views)

Hey dome,

Assume Locals.HexString = "0xFFFF".
Assume that Locals.BytePos = 2
Assume that Locals.Length = 4
Assume Locals.Number is where we want to store the result.

This:

Locals.Number = LocalizeExpression("0x" + Mid(Locals.HexString, 2 + Locals.BytePos, Locals.Length))

Returns:

Locals.Number = 255

If you want to force Locals.Number to show up as a Hex value then you need to change the properties of it:

RightClick>>Numeric Format...  Change Type:  to Hexadecimal.

Hope that helps,

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 2 of 4
(4,301 Views)
hey ~jiggawax~

i have tried but it doesn't work but not so as I will.
I will explain my problem^^

I have an Local Result ="624041013D00020149032F000002B202E2034F" and I have two Variables BytePos and Length.
TestStand should be able to splitter the Varialbe Result bassed on BytePos und returns so many Byte how are in the Variable Length.
And then to convert it.

So i hope you can help me

greetings
0 Kudos
Message 3 of 4
(4,271 Views)
Hi,

I think jigg is right.
His expression should work.

But the string in his exemple begins with "0x", so he set an offset of 2 to BytePos :
Locals.HexString = "0xFFFF"
Locals.Number = LocalizeExpression("0x" + Mid(Locals.HexString, 2 + Locals.BytePos, Locals.Length))
=> 2 + Locals.BytePos is the zero-based starting index of the substring to extract.

If your string does not begin with "0x", you must remove the offset. The new expression is :

Locals.Number = LocalizeExpression("0x" + Mid(Locals.HexString, Locals.BytePos, Locals.Length))

Note that BytePos is a zero-based index.


Bruno
0 Kudos
Message 4 of 4
(4,265 Views)