Converting Byte Value to Bit (on / off) targetId

Just wondering if there is a way to convert a byte when it is a specific value to an on/off bit type targetId?

Specifically, when the byte value is 13 (decimal) I would like this to on (1) \and every other value off (0).

You could use enum for that:


@realdashdev thanks using enum already but didn’t think of using # to abbreviate all other results, presumably I can’t feed this into targetId143, which is on / off?

I don’t see any reason why you could not.

This didn’t work with the on/off targetId

Yes, if you specify units=“bit”, only the least significant bit is read from the value.

@realdashdev the following example does not work, I assume this is because the units apply to the value and not the enumerated value, although when the value =13, bit 0 is actually set with bits 2 and 3

value targetId=“143” offset=“6” length=“1” units=“bit” enum=“13:1,#:0

The following works but it can’t be assigned to the targetId which is on/off

value name=“MP: TC_Lockup” offset=“6” length=“1” enum=“13:1,#:0

If you specify units=“bit”, value can be either 0 or 1. enum is handled after the units conversion, so that is why it does not work with units=“bit”.

Edit: Added conversion for bitwise and, as I do not know what other data may be on those bytes.

Lets see:

- Value 13 in binary is 1101, so we can do a bitwise AND to confirm that those bits (and only those) are on.

value name="MP: TC_Lockup" offset="6" length="1" units="bit" conversion="V & 13"

Also noticed that in your examples you are using special double quota characters, so copy-pasting from your posts probably will not work. For that reason, always use a text editor that immediately shows any syntactic errors in your XML.

1 Like