Setting output state using Snap7 c#

29 Views Asked by At

I have started using Snap7 library to communicate with Simatic 1200 and reading and writing data blocks works fine. My question is appears due to my lack of understanding basics that I cant find, because documentation is written in that way that it is assumed that reader knows basic levels.

I want to control outputs 'DOa' and 'DOb' by executing certain commands. I guess that it is certain data block and address that needs to be recalled.

Can You guide me what to look for ? I know that there are some type of data blocks but which of them is related to outputs.

1

There are 1 best solutions below

0
Seba Ja On

If someone would need it here is the code that works fine Cheers

 MyClient = new S7Client();
 MyClient.ConnectTo("10.0.0.2", 0, 0);

 // Set the output values
 int outputByte = 0;  // outputs are in the first byte of the output area
 // Set DOb 
 int outputNumberDOb = 8;//1st bit
 byte[] bufferDOb = new byte[1];
 bufferDOb[0] = 0x01;  // Set to 0x01 for ON, 0x00 for OFF
 int result = MyClient.WriteArea(S7Consts.S7AreaPA, 0, outputByte * 8 + 
 outputNumberDOb, 1, S7Consts.S7WLBit, bufferDOb);

 // Set DOb
 outputNumberDOb = 9;//2nd bit
 bufferDOb = new byte[1];
 bufferDOb[0] = 0x01;  // Set to 0x01 for ON, 0x00 for OFF
 result = MyClient.WriteArea(S7Consts.S7AreaPA, 0, outputByte * 8 + 
 outputNumberDOb, 1, S7Consts.S7WLBit, bufferDOb);