Converting PanelBuilder32 Dints to strings

I’m trying to pull out a 10 character serial number that RSLogix500 saves as 5 DINT tags in a SLC. Any ideas?

A str(xx) give me an error code of unknown function.

So given that DINTs are 32 bits long, it looks like it is using 16 bits to represent each character. Do you know how it is encoding the characters? ASCII maybe?

AlThePal asks a good question. Also, what model SLC is it and how are you connecting it to Ignition?

I am connecting to a SLC 5/04 and the dints are definitely stored as the ASCII values of the string, but because Logix500 can easily convert back and forth, it stored them as dints instead of chars. Is there an easy way to separate the bytes and get the chars? I should preface by saying I am new to Ignition and Python.s

There are a number of ways to do this. I reckon the most useful is to read the DINTs into SQLTags of type INT4 and then create an Expression SQLTag of type String with the following expression:stringFormat("%c%c%c%c%c%c%c%c%c%c", toInt({dint1}/65536), toInt({dint1}&65535), toInt({dint2}/65536), toInt({dint2}&65535), toInt({dint3}/65536), toInt({dint3}&65535), toInt({dint4}/65536), toInt({dint4}&65535), toInt({dint5}/65536), toInt({dint5}&65535))(This example assumes your values are stored in SQLTags dint1 to dint5.)

This code works by splitting each of your 32 values back into 16 bit values. A line like toInt({dint1}/65536) gets the topmost 16 bits and a matching line liketoInt({dint1}&65535) gets the bottommost 16 bits. The stringFormat call then forces these 16 bit integer values into the ASCII equivalent.

All this should give you a single SQLTag containing your original 10 character string.

Yes! This was great advice. The only thing I needed to change was that I only needed 1 byte, not 2, so I used 255 and 256. At first I was getting some Chinese characters that I was pretty sure I had not input.

stringFormat("%c%c%d%c%c%c%c%c%c", toInt({[.]Serial Number Tags/dint1}/256), toInt({[.]Serial Number Tags/dint1}&255), toInt({[.]Serial Number Tags/dint2}/256), toInt({[.]Serial Number Tags/dint2}&255), toInt({[.]Serial Number Tags/dint3}/256), toInt({[.]Serial Number Tags/dint3}&255), toInt({[.]Serial Number Tags/dint4}/256), toInt({[.]Serial Number Tags/dint4}&255), toInt({[.]Serial Number Tags/dint5}/256), toInt({[.]Serial Number Tags/dint5}&255))

Thanks so much!