Is it possible to directly monitor a boolean bit within an integer?
I am working on a project that involves a lot of switches. The switches monitor the status of their ports within an unsigned integer. The first nine bits of the integer represent the nine ports.
e.g. 0000 0000 0010 1010 means ports 2, 4 and 6 have a connection established.
I would like to monitor these ports within the AC800m PLC by addressing the boolean bit only.
The communication protocol I am using is Modbus TCPIP
I am using the software Compact Control Builder.
Is it possible to directly address the boolean bits?
In Modbus, there is both Coil (=Single Bit) and Register (=Word, 16Bit) Commands - However this depends on what your communication partner supports.
If you need to communicate with Registers, you can use the "word" datatype (and convert with word_to_dint / dint_to_word for communication), and the Commands
SetBit( word, int)
ClearBit( word, int)
bool TestBit( word, int)
for Operations on single Bits within the word - the second parameter is always the Bit Position. Just always subtract the Switches Port Number by 1 as the index starts with 0...
I propose you other solution.
Declare the variable read by modbus as "dint", declare the status variable as "Boolean16" and use the function "DintToBool16" to convert:
DintToBool16( Int := vRead,
BoolStruct => vBoolean16 );
(* vBoolean16.B0 to vBoolean16.B15 are the boolean address *)