Erwin Draconis
Erwin Draconis

Reputation: 784

Read/Write S7-1200 bit memory via C#

I am trying to set value on a boolean memory in the S7-1200 CPU, I have used the SNAP7 library but I couldn't get success with it :

Result result = new Result();
byte[] Buffer = new byte[26];
Client.DBRead(1, 0, 2, Buffer); 
result.bArret = S7.GetBitAt(Buffer, 0, 1);
result.bMarche = S7.GetBitAt(Buffer, 0, 2);
Client.DBWrite(1, 0, 10, buff);

My goal is to be able to write value on memory : enter image description here

Here is the DataBlock 1 :

enter image description here

I need to accomplish this task without using OPC or some other third software.

Upvotes: 5

Views: 5080

Answers (1)

Erwin Draconis
Erwin Draconis

Reputation: 784

Problem solved by replacing Merkers by datablock variables , here is an example :

        S7Client client = new S7Client();
        int res = client.ConnectTo("192.168.0.10", 0, 0);

        int DBNumber;
        int Size;
        int Result;
        byte[] buffer = new byte[2];
        DBNumber = System.Convert.ToInt32(1);
        Size = System.Convert.ToInt32(2);
        Result = client.DBWrite(DBNumber, 0, Size, buffer);
        buffer[0] = 1;
        buffer[1] = 1;
        Result = client.DBWrite(DBNumber, 0, Size, buffer);

hope that someone will found it usefull in the future.

Upvotes: 6

Related Questions