In a follow up to my other post about reading a Modbus address whose format is swapped bytes. That is a tag whose value I know to be -32768 or 00000000 00000001 in binary but Ignition is reading it as 128 or 00000001 00000000 in binary since there is currently no option to swap the bytes of a 16 bit integer in the Modbus settings.
I also need to write back to a Modbus register whose format is swapped bytes. At this point the only way I can figure out how to accomplish the byte swapping is to have 3 tags.
- A Raw value Tag- This is the tag with the byte in the wrong order as read from the device
- The corrected Expression tag - This is the tag that uses the expression Phil recommended in the other tread that swaps the high and low bytes using bit shifting
- A memory tag for writing new values to - This tag would have an script in the value changed option that shifts the high low bytes and then writes back to tag 1
Is there a better method for doing this? I plant to create a datatype that handles the tag creation in one go, it just seems like Iām going about this inefficiently.