The lack of Client of different protocol in OpenPLC IDE have been there for many years. I do know that Arduino API need a Network object. This object could be Ethernet or WiFi. Many boards have it own API how this should be done instead of 1 solution that feat them all.
Let take
@davenardella Settimino a S7-Communication library to be able to talk to Siemens device's or other that support it.
All communication API need a Network object.
ex.
#include <WiFi.h> to include API to use WiFi Network
OpenPLC IDE already have Modbus TCP support and it also give us the network object. It means if we like to use Settimino as Arduino extension. We understand quickly we do not need SSID, PASSWORD, WiFi.begin()... The reason is Modbus TCP already give us this information. If so many communication protocol for Arduino compatible board have the same approach why not use it in a clever way instead of ONLY for modbus protocol. It means we only need to setup a Modbus TCP with correct configuration and use other protocol. The code below is running on Arduino board with a dummy plc program that do nothing.
So it kind of give me the sense that Network object should be separate object, and from that object we include communication protocol. What I'm trying to say you do not need WiFi.h header if you include Modbus TCP. We could go so far to remove the Platform.h from the code below and it still work. My point is or what I like to share is. The communication tab in the upload dialog of OpenPLC could look different.
So there is 3 part of a communication: Network object, Interface, Protocol. It means the only thing that is different is the Protocol and its implementation.
It also means files that are part of compile state could be separate from each other and the maintaining part could be easier to debug. To embedded #ifdefine
statement to doing hacks to support a implementation do not need to be in the protocol but instead in the Interface. Its kind of way how Settimino is working
with the Platform.h header. You only need to update the header to support a board. The file I'm target here or concern is ModbusSlave.cpp I believe the structure
of that file could separate the interface from the protocol.
- Enable network (checkbox) with configuration
- Choose protocol interface type (Ethernet or WiFi)
- Enable Modbus
- Enable S7
It means that Modbus and S7 share the same Network object, the object that make sure your board could communicate with your Network.
This way it properly would be easier to support other protocol. Instead of have nested calls to same libraries or maybe better performance
in the compiling state.
The code will set the bit 0 of byte 0 to True or False every second.
To be able to run the code below you need a dummy plc program that include contact and coil and variable.
Add a Arduino extension, copy/paste the code below, add Modbus TCP configuration and upload to your board.
PS. You do need to download the Settimino library and install it on your Arduino environment.
//////////////////////////////// sketch section ////////////////////////////////
//#include <Platform.h>
#include <Settimino.h>
IPAddress PLC = "S7_SERVER_IP";
S7Client s7Client;
uint16_t db1 = 1;
bool state = false;
unsigned long previousMillis = 0;
const long interval = 1000;
void sketch_setup() {
s7Client.ConnectTo(PLC, 0, 0);
}
void sketch_loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (state == false) {
state = true;
} else {
state = false;
}
}
if (s7Client.Connected) {
s7Client.WriteBit(S7AreaDB, db1, 0, 0, state);
}
}