Convert 16 bit integer to Two Character ascii

I have a power meter that holds (4) Modbus registers for the device serial number that is ascii. Each register sends raw integer values for (2) ascii characters for its serial number. Is there a way to convert the integer in expression binding after pulling in the register tag to display the (2) ascii characters? For example, lets just start with ONE register that reads the following and we can call it (Tag33)

Raw Value Input Register 33 (Unsigned 16) = Tag33 = 17463
Configure Expression Binding Code = toHex(Tag33) = 4437

ascii table for 44 = D (Which matches the device in first character)
ascii table for 37 = 7 (Which matches the device in second character)
How can I get Ignition to display D7 ?

The modbus driver will do this for you with the HRS address syntax. {Well, IRS prefix for input registers.}

Yeah, probably easier to read the String, but if you had to make an expression:

char(({[~]Tag33} >> 8) & 0xFF) + char({[~]Tag33} & 0xFF)

I have it pulled in to my Modbus register, have it now set to Holding Reg (Unsign16) but still yields 17463 any conversion I have tried with Expression Binding only yields the 4437.

Modbus driver*.....

This worked!!! Thanks Kevin !!!

@Kevin.Herron & @pturmel, If I were to read the String, how would I do that? In my "Device Connections" -> "Modbus Type" I have Tag33 as Holding Register (UInt16). Am I missing anything?

@pturmel I see your message the address syntax shows an example "[DL240]HRS1024:20` Read 20 character string value starting at Holding Register 1024". Would I have "HRSTag33:2" ? If so, where would this go? I am new to Ignition, but have been able to pick things up quickly.

"Tag33" isn't a Modbus address. What is the underlying OPC Item Path for this tag?

If that is "Tag33" it means you've set up an address mapping on the device config (recommend you don't do this) and need to go figure out the real address.

Under Tag Browser, I have my Device, lets call it Unit10. From there I see my available tags populated from "Device Configuration". Under Unit10, I have Register 33.

Under Register 33 there is a drop down menu, is this where I edit it?

No, it sounds like you need to find this page in the Gateway: Modbus Address Mapping - Ignition User Manual 8.1 - Ignition Documentation

This is exactly what I have with all my registers I have pulled in through the Modbus Driver...

Better yet, this is my screen shot of my Modbus Driver (sorry to confuse with the other image)

Ok, delete all of that and let's do this the recommended way.

Just create 4 OPC tags in the Ignition Tag Browser. For the OPC Item Path, use an address like:

  • [DeviceName]10.HR33
  • [DeviceName]10.HR34
  • [DeviceName]10.HR35
  • [DeviceName]10.HR36

Alternatively, the String approach:

  • [DeviceName]10.HRS33:8
1 Like

OK, I think I am understanding this now. I was hopeful that I didn't need to create a tag and just pull in the register with it being converted and be done. Let me try this and I will get back to the thread shortly. Thanks!!!

That's the "String approach". Highly recommended.

Am I confusing the "String approach" with my Modbus Type when pulling it in under "Device Configuration" as Holding Register (UInt16) ? Here is a screen shot if you haven't seen the other post...

Kevin's advice, and mine too, is to not use the mappings in the Device Configuration section at all. Use explicit OPC item paths in your Ignition tags.

If you simply cannot live without browsing your device registers, consider my alternate driver.

OK. I will create the OPC tag path.

@Kevin.Herron & @pturmel, I am getting a "Bad_NodeID Unknown" error configuration message. Here is my 33 reg Tag Editor properties screen shot...