I have a Modbus TCP device and one of the data fields I need is a byte in the lower 8 bits of HR323. This value is a signed value which seems to be the issue I’m having. I need to ‘extract’ this byte to a tag so I created an OPC tag for HR323, then I created an expression tag of type byte and the expression I’m using is:
{[.]IOLinkData/I3} & 0xFF
Which should mask the lower byte of IOLinkData/I3 and store that in my byte tag, but instead of just using the bitwise value, it seems Ignition is returning an integer value from the expression and then attempting to convert that into a byte.
For example the value currently being sent by the IOLink block is -3 or 0b11111101. this is throwing an “Error_TypeConversion” presumably because Ignition is converting 0b11111101 to 0b0000000011111101 which is 253 (the value read if i change the expression tag to short) and then failing to convert 253 to byte since it would overflow. I can make it work with the expression:
if(
getBit({[.]IOLinkData/I3},7),
(({[.]IOLinkData/I3} & 0xFF) - 256),
({[.]IOLinkData/I3} & 0xFF)
)
but is there a cleaner way to make Ignition look at just the 8 bit value (ignoring the more significant bits) and use that as the byte?