Convert data value to ASCII and archive the combined String

Ignition version is 7.9.9

I’m trying parse ascii from a decimal value into some form I can display (I have accomplished this by using “lookup” and adding all the characters together in a label),and archive for our operations team.
I can’t find a built in function to do this. It looks like there is a function in version 8, but I don’t know when we will be upgrading.

The data resides in Hex in a Siemens 400 PLC data block. The data is a recipe number (8 bytes) and a recipe name (16 bytes).
I have a Power Table with the decimal to ASCII equivalents. My thought is to use the tag value (for each byte), comparing the value from the tag to the table (using lookup) and return the ASCII character. Add the characters to form a string in a tag that can be archived. I’m struggling with getting the 8/16 ASCII characters into a tag that can be archived as a string.

Example: Recipe # = 50
Datablock hex value =3500 (bytes 1 and 2)

Recipe name = Test
Datablock hex value =5465 7374 (bytes 1 thru 4)

Should that be #3532?

Q1. Are you trying to do this in Python or Expression Language?
Q2. Are you reading the data as numbers or strings? Can you be specific?

Sorry, #3530h = ASCII 50
Q1, Label has expression binding using “lookup” to add all the characters together. The task of getting that String of characters into a tag I can archive is what I am looking for help with. I don’t know the path to script that function whatever that solution is.
Q2, the data in the PLC is at the base hex. Ignition can read the data byte as decimal in a tag configured as an Integer or byte. Right now the hex vale is 53h, Ignition tag displays this as 83d, label dispalys the "lookup from my table as “S”.

Is there any chance you could modify the PLC to include the standard string type header before these registers? (One byte maximun string length, one byte current string length.) Then you could use the standard string type.

You could put this in a project script:

def toAscii(hexValue):
    import struct
    return struct.pack('i',hexValue)

Then call it from an expression with runScript().

No, it’s an OEM machine and we can’t change the logic.

My scripting ability is limited. I’m not sure understand what defines the “struct” as it relates to the Power Table or the tags I have reading each of the hex values in the PLC.

You don’t need the power table at all. This will do the conversion for you.

Put the code in a project script, then you can call it from an expression with the tag value as the parameter and it will return the ascii string

I can’t seem to get this to work. I put the script in the “Script Library [Project]”. Named it Read_ASCII.

Create a test Expression tag and run “runScript” against the tag that has the data from the PLC.
runScript(“Read_ASCII”, “Test Tags/TestExpTag_1”)

Does “toAscii” work in version 7.9?

The function will work with 7.9.

There are two potential problems here.

  1. It’s been a while and I don’t actually remember but I don’t think that project scripts are available in tags, you would need it to be in a gateway shared script.

  2. In the expression you showed you were sending the path to the tag and not the value of the tag.

If you’re going to need this enough then perhaps putting it in a gateway script is a good idea.

I would probably use an expression binding on the label.

I’m going to try to put a screenshot in here to show what I have so far. Maybe make more sense.
I have labels populated with the ASCII characters. What I want to do (if possible) is to place that ASCII string into a tag, as a string, so I can archive it in a tag. All the tags I’m using from the PLC are shown. One tag for reference for configuration.