K
I need some help understanding Modbus function code 22 0x16. Is it correct? Can it set and clear bits at the same time?
If the intent of the function is to turn off the bits that are 0 in the "AND" parameter and turn on the bits that are a 1 in the "OR" parameter the example pseudo code and data example appear to be wrong.
Modbus_Application_Protocol_V1_1b.pdf Sample:
Result = (Current Contents AND And_Mask) OR (Or_Mask AND (NOT And_Mask))<pre>
Current Contents = 12 0001 0010
And_Mask = F2 1111 0010
Or_Mask = 25 0010 0101
(NOT And_Mask) = 0D 0000 1101
Result = 17 0001 0111</pre>
Notice that:
* The sample data is constructed as such that it never clears any bits in "Current Contents" Bits 1 and 4 (Zero Base) are on in "Current Contents" and "Result" so this is a poor example.
* The result fails to set the 5th (Zero Base) bit in the result that is set in the "Or_Mask".
I believe the pseudo code should be:
Result = (Current Contents AND And_Mask) OR (Or_Mask) in the case where true bit mask are provided.
Will you please provide sample data where bits are set and cleared in "Current Contents".
If the intent of the function is to turn off the bits that are 0 in the "AND" parameter and turn on the bits that are a 1 in the "OR" parameter the example pseudo code and data example appear to be wrong.
Modbus_Application_Protocol_V1_1b.pdf Sample:
Result = (Current Contents AND And_Mask) OR (Or_Mask AND (NOT And_Mask))<pre>
Current Contents = 12 0001 0010
And_Mask = F2 1111 0010
Or_Mask = 25 0010 0101
(NOT And_Mask) = 0D 0000 1101
Result = 17 0001 0111</pre>
Notice that:
* The sample data is constructed as such that it never clears any bits in "Current Contents" Bits 1 and 4 (Zero Base) are on in "Current Contents" and "Result" so this is a poor example.
* The result fails to set the 5th (Zero Base) bit in the result that is set in the "Or_Mask".
I believe the pseudo code should be:
Result = (Current Contents AND And_Mask) OR (Or_Mask) in the case where true bit mask are provided.
Will you please provide sample data where bits are set and cleared in "Current Contents".