1

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?

ZF007
  • 3,708
  • 8
  • 29
  • 48
impulse101
  • 99
  • 1
  • 10

1 Answers1

0

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;

Victor Pieper
  • 540
  • 2
  • 17
  • Hi, welcome to StackOverflow! Your post does not answer the question. Once you have enough reputation, you will be able to add comments to questions. For now you should either edit your answer providing a complete solution or delete your post. – Ramon Dias Feb 13 '23 at 17:18
  • @RamonDias please rerate my answer. I extended it with an explantion and another example. (: – Victor Pieper Feb 14 '23 at 08:07