String ASCII move as HEX to string table

We have the NCD ethernet receiver too. We have customer using PAC R1 with ncd, we were having some issues on the data prasing, so I was working on rewriting the prasing code. As both epic and pac r1 has same chart for ncd data prasing. Our customers have options to pick between ethernet and serial. Ethernet is most preferred for epic verson. But older pac r1 customers we are sticking with serial only.


2 Likes

Hello all.

I have a similar problem as an OP but can’t use Unpack string function (developing the code in PAC control 8.5, don’t ask why).

what would be the best way to convert the string I receiving to string of HEX characters without this function. Basically I’m trying to implement Unpackstring subroutine myself.

So far my code:

for nIndex = 0 to (GetStringLength(s2unpack)-1) step 1
GetSubstring(s2unpack, nIndex, 2, sCharacter);
nCharacter = HexStringToNumber(sCharacter);
NumberToStringField(nCharacter, 2, sCharacter);
sString = sString + sCharacter;
next

does not yield any meaningful results.

I would appreciate any suggestions.
Thanks!

It looks like you are getting and decoding two hex characters at a time?
If that’s the case, you should probably be using step 2, not step 1 — so that you’re avoiding overlapping every other character in the original string data.

Can you test that and see if it makes any difference?

1 Like

Nope, it does not matter.

From 2 below strings I always get 0 on nCharacter variable.
GetSubstring(s2unpack, nIndex, 2, sCharacter);
nCharacter = HexStringToNumber(sCharacter);

I need to get the Hex value of the character and convert it to decimal number of the character.
Kind of inverted crt(nCharacter) function…

Can you give an example of the s2unpack value you’re working with? Also, can you confirm the lengths of s2unpack and sCharacter? Just trying to cover all bases.

Agree with torchard - should be step 2 with the logic given.

s2unpack - is this a string of hex characters or is it binary?

Sorry, should’ve done it earlier.

The string is (data coming from the turbo pump):

02160020B9000000000FA000000000000000000000000022

as I read it in the HEX window. What I want it to read it and have an actual string like that.
The problem is that 02 and 16 are not printable characters, and I do not know how to convert that I read into the string.

and I want to read this:

Thank you

All strings are 48 bytes in length.

I’m using the following line in 10.5 PAC Control (variable names are different from example above) to read data from the pump:

UnpackString(sSmallTurboRecvStr, 0, GetStringLength(sSmallTurboRecvStr), sSmallTurboRecvStrUnpkd, 9, 0);

I need the same function in PAC 8.5 (it came to PAC control in later versions), and trying to implement myself subroutine that would do the same function but will work in 8.5.

Something like this (untested):

for nIndex = 0 to (GetStringLength(s2unpack)-1) step 1
  nCharacter = s2unpack[nIndex];
  NumberToHexString(nCharacter, sCharacter);
  if(GetStringLength(sString) > 0) then
    sString = sString + " " + sCharacter;
  else
    sString = sString + sCharacter;
  endif  
next
2 Likes

Hi Philip.

Thank you for your suggestions. You resolved my issue - the line I was looking for was

nCharacter = s2unpack[nIndex];

Thanks.

So, to summarize:

If you need to convert HEX string in the ASCII character numbers string you can use the code below.

The string we are working with is this one:

02160020B9000000000FA000000000000000000000000022

it looks like this when inspected:


or in HEX format:

One can convert it with embedded function (newer PAC control):

UnpackString(sTest1, 0, GetStringLength(sSmallTurboRecvStr), sTest1Unpkd, 9, 0);

where sTest1 - original string from above
sTest1Unpkg - converter string to ASCII HEX

Or the routine below (can be converter to subroutines with the same name in older PAC control)

sString = “”;
for nIndex = 0 to (GetStringLength(sTest1)-1) step 1
nCharacter = sTest1[nIndex];
NumberToHexString(nCharacter, sCharacter);
if(GetStringLength(sCharacter) < 2) then
sCharacter = “0” + sCharacter;
endif
sString = sString + sCharacter;
next

Thank you guys for the help!!! Appreciate it a lot.

2 Likes

Thanks a heap for the comprehensive summary reply.
Really adds a lot of value to the thread.
Glad you got up and running.