Settimino is an ARDUINO library, it consists of three files
It depends on the supplied Ethernet Library (<Arduino Dir>\libraries\Ethernet).
To use it, just like other libraries, you need to import it in your programming environment.
To do this follow this excellent tutorial
Instead, to modify/extend Settimino follow
The main class exported is S7Client which is the object that is able to connect and transfer the data from Arduino to a Siemens PLC (and vice-versa).
There is not a global instance of S7Client, you have to instance it (or them) in your sketch.
Each client uses a socket (via
the EthernetClient object) so you can instantiate up
to four clients or less if you are instantiating other Ethernet object (or
derived) in the same project.
This is the limit of the W5100 Ethernet chip.
S7Client is a class, but as you can see in other libraries, the Object Oriented Paradigm must be revisited for Arduino, due the needing to have a small footprint for the programs, so let’s see the Settimino choices.
· The Arduino environment is not multitask so, although you have 4 clients, only one at time is the active one.
· The client is fully synchronous, each job (transaction) is completely executed in its function call.
Said that, a global data buffer is used. It’s shared across all clients since only one at time can use it.
This data buffer is able to contain only one PDU see Siemens communication to understand what this means. Substantially, the PDU is the base “data slice” handled by the PLC, if you need to transfer more data, the S7 protocol states that subsequent transactions (each containing a PDU) must be used.
The PDU variable is itself global, i.e. is visible from your sketch.
So you have two choice for optimizing the memory usage.
1. If you need to transfer more than 222 byte (the payload of a PDU) you need an external buffer.
2. If you want to transfer small amount of data, you can use an external buffer or use directly the PDU variable.
Let’s see an example (please refer to the S7Client functions syntax for further information).
This is the PDU as defined in Settimino.h:
byte H[Size_WR]; // PDU Header
byte DATA[MaxPduSize-Size_WR+Shift]; // PDU Data
TPDU PDU; // Declaration
The H array contains the protocol header, the DATA array contains the payload i.e. the raw data of the telegram.
// Large Data transfer
byte MyBuffer; // 1K array
Client.ReadArea(S7AreaDB, 24, 0, 1024, &MyBuffer);
We are saying to the Client to access to DB 24, to read 1024 bytes starting from the first (0) and to put them into MyBuffer.
// Small Data transfer
Client.ReadArea(S7AreaDB, 24, 0, 64, NULL);
Serial.println(PDU.DATA); // Print the first byte received
Serial.println(PDU.DATA); // Print the second… and so on
We are saying to the Client to access to DB 24, read 64 bytes starting from the first (0) and to leave them into the internal buffer.
Similarly for write operations, you put your data into a buffer or into PDU.DATA then call WriteArea().
The Client will safely trim the Amount parameter if you pass NULL as buffer pointer and Amount is greater than the size of PDU.DATA.
Siemens PLC data are Big-Endian, Arduino data are Little-Endian.
S7Helper is a global object that allows to extract right-formatted values from a byte buffer. The instance name is S7.
Let’s suppose to upload the following DB 100.
unsigned long Encoder;
// Get 10 bytes starting from 0
Client.ReadArea(S7AreaDB, 100, 0, 10, &MyBuffer);
MyBuffer now will contain a “disordered” series of bytes (Big-Endian).
To access the fields we can write:
Pressure = S7.FloatAt(&MyBuffer, 0);
Encoder = S7.DWordAt(&MyBuffer, 4);
Component = S7.IntegerAt(&MyBuffer, 8);
S7Helper has two overloaded methods for each field access, so
Encoder = S7.DWordAt(4);
will refer to PDU.DATA
For further optimizing the footprint, three memory models are available : Small, Normal and Extended.
Although the extended model runs fine in the ARDUINO UNO, you may want to further reduce the memory usage “by skipping” some features that you don’t need using in your project.
For example, Settimino Client can control the PLC putting it in STOP or RUN mode, but if you only need to read/write data, maybe you don’t need of these features.
To set the memory model you need simply to modify the directive at beginning of Settimino.h, writing:
The “small” model contains the minimum set of functions to connect to a PLC and reading/writing data.
The “normal” mode contains the S7Helper.
Finally the “Extended” model contains also the remaining extended functions.
By default Settimino is released as Extended.
These directives are visible from your sketch.