IEC 104 Component

IEC 104 Communication Protocol

IEC 104 configuration in Shunya

ConfigDescription
Protocol TypeModbus is available in 2 variants RTU and TCP. Select the mode that you want to communicate
IP addressModbus server IP address (only for Modbus TCP type)
PortModbus server Port (only for Modbus TCP type)
DeviceModbus server Device node (only for Modbus RTU type)
Baud RateModbus server Baud rate (only for Modbus RTU type)

The configurations need to be set manually by the user before using the API's

For example:

A sample JSON snippet should contain

"iec104": {
"address": "",
"port": 8883,
"serverAddr": 1,
"originAddr" : 0,
"clientKey" : "",
"clientCert" : "",
"rootCert": "",
"serverCert" : "",
},

Commonly configured parameters

For example:

A typical IEC 104 configuration without security will look like this

"iec104": {
"address": "192.168.0.100",
"port": 8883,
"serverAddr": 1,
"originAddr" : 0,
"clientKey" : "",
"clientCert" : "",
"rootCert": "",
"serverCert" : "",
},

IEC 104 API's

To get the data from the device over modbus you can use these API's present in the Shunya Interfaces

APIDescriptionDetails
newIec104Client()Creates a new IEC 104 client InstanceRead More
iec104Connect()Connect to device over IEC 104Read More
iec104Read()Read IEC 104 address and get dataRead More
iec104Write()Write data to IEC 104 addressRead More
iec104Disconnect()Close connection with the IEC 104 deviceRead More

newIec104Client()

Description : Creates a new IEC 104 client Instance.

Parameters

  • name (char *) - Name of the JSON object.

Return-type : iec104ClientObj

Returns : iec104ClientObj Instance for IEC 104

Usage :

For example: Lets say your JSON file looks like

"modbus-tcp": {
"type": "tcp",
"ipaddr": "192.168.0.101",
"port": "5059",
},

So the usage of the API's will be

modbusObj plc1 = newModbus("modbus-tcp");

modbusRtuConnect()

Description : Connect to the device Connected via Serial

Parameters

  • *obj(modbusObj) - Pointer to the Modbus Instance.

Return-type : int

Usage :

/* Create new Modbus Instace */
modbusObj plc1 = newModbus("modbus");
/* Connect to the Serial device*/
modbusRtuConnect(&plc1);

modbusRtuRead()

Description : Read from PLC address connected via Serial

Parameters

  • *obj(modbusObj) - Pointer to the Modbus Instance.
  • addr(uint16_t) - coil address to read the value from

Return-type : int

Usage :

/* Create new Modbus Instace */
modbusObj plc1 = newModbus("modbus");
/* Connect to the Serial device*/
modbusRtuConnect(&plc1);
/* Read the 1000 modbus address*/
modbusRtuRead(&plc1, 1000);

modbusRtuWrite()

Description : Write to PLC address connected via Serial

Parameters

  • *obj(modbusObj) - Pointer to the Modbus Instance.
  • addr(uint16_t) - coil address to write the value
  • val(uint16_t) - value to write

Return-type : int

Usage :

/* Create new Modbus Instace */
modbusObj plc1 = newModbus("modbus");
/* Connect to the Serial device*/
modbusRtuConnect(&plc1);
/* Write value 8883 at the 1000 modbus address*/
modbusRtuWrite(&plc1, 1000, 8883);

modbusRtuDisconnect()

Description : Disconnect to the device Connected via Serial

Parameters

  • *obj(modbusObj) - Pointer to the Modbus Instance.

Return-type : int

Usage :

/* Disconnect to the Serial device*/
modbusRtuDisconnect(&plc1);

modbusTcpConnect()

Description : Connect to the device Connected via Ethernet

Parameters

  • *obj(modbusObj) - Pointer to the Modbus Instance.

Return-type : int

Usage :

/* Create new Modbus Instace */
modbusObj plc1 = newModbus("modbus");
/* Connect to the device*/
modbusTcpConnect(&plc1);

modbusTcpRead()

Description : Read from PLC address connected via TCP(Eth/wifi)

Parameters

  • *obj(modbusObj) - Pointer to the Modbus Instance.
  • addr(uint16_t) - coil address to read the value from

Return-type : int

Usage :

/* Create new Modbus Instace */
modbusObj plc1 = newModbus("modbus");
/* Connect to the Serial device*/
modbusRtuConnect(&plc1);
/* Read the 1000 modbus address*/
modbusTcpRead(&plc1, 1000);

modbusTcpWrite()

Description : Read from PLC address connected via TCP(Eth/wifi)

Parameters

  • *obj(modbusObj) - Pointer to the Modbus Instance.
  • addr(uint16_t) - coil address to read the value from
  • val(uint16_t) - value to write

Return-type : int

Usage :

/* Create new Modbus Instace */
modbusObj plc1 = newModbus("modbus");
/* Connect to the Serial device*/
modbusTcpConnect(&plc1);
/* Write value 8883 at the 1000 modbus address*/
modbusTcpWrite(&plc1, 1000, 8883);

modbusTcpDisconnect()

Description : Disconnect to the device Connected via Ehternet

Parameters

  • *obj(modbusObj) - Pointer to the Modbus Instance.

Return-type : int

Usage :

/* Disconnect to the Serial device*/
modbusTcpDisconnect(&plc1);