Reputation: 99
I'm using S7.Net Plus for Modbus TCP communication with Siemens S7 1200 PLc. I'm able to sent all types(integer, word, double) of data to PLC. Boolean only when I'm using Read single variable class eg:
plc.write("DB12.DBX0.0",false);
This is not an optimised code when I want to send a number of variables, So I'm using the following code and sending in array format
byte[] db12Bytes = new byte[1];
S7.Net.Types.Boolean.SetBit(db12Bytes[0],0);
plc.WriteBytes(DataType.DataBlock, 12, 0, d12Bytes);
But this not working as expected, the boolean value is not getting updated.
Is there a solution to this? Can anyone help me with this?
Upvotes: 1
Views: 1107
Reputation: 778
Instead of using: S7.Net.Types.Boolean.SetBit(db12Bytes[0],0);
Just use db12Bytes[0] = 1;
This is because in your db12Bytes is a buffer of bits. Since a bit can only be 0 or 1 you can just set the bit in buffer to 1 ( true )
For example you want to set bit number 3 on true: db12Bytes[3] = 1;
The same methode you can use for setting the bits on false: db12Bytes[3] = 0;
Upvotes: 0