Industrial Shields library

January 4, 2019 by
Industrial Shields library
Boot & Work Corp. S.L., Support Team


Introduction

This is the Industrial Shields library for all the different Industrial Shields PLC’s .

Requirements 

Ethernet or 20 I/Os PLC:      Ethernet PLC     20 I/Os PLC


SimpleComm Industrial Shields Library:  SimpleComm Github repository


Usage

With the SimpleComm library, you can send data through any Arduino Stream: RS-485, RS-232, Ethernet… It is enough flexible to support different kinds of communication typologies: Ad-hoc, Master-Slave, Client-Server… Using an easy to use API..

The SimplePacket class encapsulates the data into a packet.

The setData function fills up the packet with the desired data for sending it to a remote device. It is possible to fill up the packet with different types of data: bool, char, unsigned char, int, unsigned int, long, unsigned long, double, string and even custom data types.


int num = 1234;
SimplePacket packet1;
packet1.setData(num);
SimplePacket packet2;
packet2.setData("text data");
typedef struct {
    int a;
    char b;
} customType;
customType customVar;
customVar.a = 1234;
customVar.b = 'B';
SimplePacket packet3;
packet3.setData(customVar, sizeof(customVar));

There are also getter functions, which return the data contained in the packet, depending on the data type. If length is specified, it returns the data length in bytes. 

int num = packet1.getInt();
const char *str = packet2.getString();
const customType *var = (const customType*) packet3.getData();

The SimpleComm class is the interface for sending and receiving packets through the desired Arduino Stream.

The begin(byte) function enables the communication system and sets the device's identifier/address. Each device has its own address which identifies it. Devices receive packets sent to them, using their address, but not to others.

byte address = 1234;
SimpleComm.begin(address);

It is possible to send packets to a device with an address, and optionally define the packet type.

byte destination = 87;
SimpleComm.send(RS485, packet, destination);
SimpleComm.send(RS485, packet, destination, 0x33);

To send packets to all devices it is possible to send a broadcast packet with the destination field set to 0 (zero).

byte destination = 0;
SimpleComm.send(RS485, packet, destination);

The receive function receives a packet from another device, using the stream. It returns true if a packet is really received.

SimplePacket rxPacket;
if (SimpleComm.receive(RS485, rxPacket)) { // A packet is received }

It is also possible to receive all the packets (sniffer mode) by setting the SimpleComm address to 0 (zero). This mode is useful when implementing a gateway node between Ethernet and RS-485.

byte address = 0;
SimpleComm.begin(address);


​Search in our Blog

Industrial Shields library
Boot & Work Corp. S.L., Support Team January 4, 2019
Share this post

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>