1

When I am trying to write an integer to an integer Database field I am successful:

byte[] db13buffer = new byte[buffer];
var shorty = short.Parse(valuesForPlc[i]);
S7.SetIntAt(db13buffer, 0, shorty);     
int writeResult2 = client.DBWrite(dbnumber, start, size, db13buffer);

How can I write a Boolean (true) value to The database?

I have the following database structure in the plc:

enter image description here

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Mister Verleg
  • 4,053
  • 5
  • 43
  • 68

1 Answers1

1

To set a bit in a data block use the following helper function of Sharp7.S7:

void SetBitAt(ref byte[] Buffer, int Pos, int Bit, bool Value)

To set the bit Boolean use the following code:

S7.SetBitAt(ref db13buffer, 4, 0, true);

To set the bit Boolean at position 4.0 the size of db123buffer must be at least 6 bytes.

dergroncki
  • 798
  • 1
  • 12
  • 24