Settimino library Write only one bit in buffer

Hello team. I make a project with arduino module esp8266 and Siemens PLC S7 1200. I connect them with settimino library. I can read parameters but i have an issue with write parameters from arduino to PLC. I use the command Client. WriteArea but with this i change a byte. In case I want to change only a bit value what should i do? Is There another Write command for bits?

The project has to do with communication between Alexa and S7 1200 PLC through ESP8266. I don't want to use alexa skills for safety reasons. I want the communication take place in the LAN. Everything is ready except this i describe before. Every help will be appreciated.

Read the byte, set/clear the bit of interest, write the byte back. Arduino has the bitSet() and bitClear() functions which can do that for you.

The bit i want to change is not in arduino but in PLC. The communication happens with settimino library and the information saved in an arduino buffer. This buffer has a total of 10 bytes all come from PLC. So with bitSet and bitClear i cant change a bit in this buffer. Check this page http://settimino.sourceforge.net/ .

I understand that, but to change a bit in the PLC, you have to use the WriteArea() call. If you know the entire byte of data, then you can call this directly. If you don't know the state of the other bits within that byte, you would first have to do a ReadArea() call to retrieve that byte, then change it within the Arduino using bitSet/bitClear, and then write it back to the PLC

Yes, you can.

byte MyBuffer[10];
Client.ReadArea(S7AreaDB, 24, 0, 10, &MyBuffer);  // read your 10 bytes
byte myByte = MyBuffer[5];  // byte of interest
bitClear(myByte, 4);  // clear bit of interest
MyBuffer[5] = myByte;  // but it back into buffer
Client.WriteArea(S7AreaDB, 24, 0, 10, &MyBuffer);  // write data back
// or just write back the single byte you changed

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.