The following properties applies to all Plc4x Processors:
s7://10.105.143.7:102?remote-rack=0&remote-slot=1&controller-type=S7_1200
or a valid Expression Language (Expression Language NiFi documentation) such as ${plc4x.connection_string}
.Properties as Addreses: For each variable, add a new property to the processor where the property name matches the variable name, and the variable value corresponds to the address tag.
An example of these properties for reading values from a S7-1200:
Address Text: Property Address Text must be supplied in JSON format that contains variable name and address tag. Expression Language is supported.
Using the same example as before:
{ "var1" : "%DB1:DBX0.0:BOOL", "var2" : "%DB1:DBX0.1:BOOL", "var3" : "%DB1:DBB01:BYTE", "var4" : "%DB1:DBW02:WORD", "var5" : "%DB1:DBW04:INT" }
If this JSON is in an attribute plc4x.addresses
it can be accessed with Address Text=${plc4x.addresses}
.
Address File: Property Address File must be supplied with a path to a file in JSON format that contains variable name and address tag. Expression Language is supported.
For example a file in:
/home/nifi/s7addresses.json
{ "var1" : "%DB1:DBX0.0:BOOL", "var2" : "%DB1:DBX0.1:BOOL" }
If the file name is in an attribute plc4x.addresses_file
it can be accessed with Address File=${plc4x.addresses_file}
.
When reading from a PLC the response is used to create a mapping between Plc types into Avro. The mapping is done as follows:
Table of data mapping between plc data and Avro types (as specified in Avro specification).
PLC type | Avro Type |
---|---|
PlcBOOL | boolean |
PlcBYTE | bytes |
PlcSINT | int |
PlcINT | int |
PlcLINT | long |
PlcREAL | float |
PlcLREAL | double |
PlcCHAR | string |
PlcDATE_AND_TIME | string |
PlcDATE | string |
PlcDINT | string |
PlcDWORD | string |
PlcLTIME | string |
PlcLWORD | string |
PlcNull | string |
PlcSTRING | string |
PlcTIME_OF_DAY | string |
PlcTIME | string |
PlcUDINT | string |
PlcUINT | string |
PlcULINT | string |
PlcUSINT | string |
PlcWCHAR | string |
PlcWORD | string |
ELSE | string |
Also, it is important to keep in mind the Processor Scheduling Configuration. Using the parameter Run Schedule (for example to 1 sec), the reading frequency can be set. Note that by default, this value is defined to 0 sec (as fast as possible).
This processor is record oriented, reads from a formated input flowfile content using a Record Reader (for further information see NiFi Documentation).
The Plc4xSinkRecord Processor can be configured using the common properties defined above and the following property:
For the Record Reader property, any reader included in NiFi could be used, such as JSON, CSV, etc (also custom readers can be created).
This processor is record oriented, formatting output flowfile content using a Record Writer (for further information see NiFi Documentation).
The Plc4xSourceRecord Processor can be configured using the common properties defined above and the following properties:
This processor is record oriented, formatting output flowfile content using a Record Writer (for further information see NiFi Documentation).
The Plc4xListenRecordProcessor can be configured using the common properties defined above and the following properties:
An example for reading values from a S7-1200:
Reading values using OPCUA:
For the Record Writer property, any writer included in NiFi could be used, such as JSON, CSV, etc (also custom writers can be created). In this example, an Avro Writer is supplied, configured as follows:
The output flowfile will contain the PLC read values. This information is included in the flowfile content, following the Record Oriented presentation using a schema and the configuration specified in the Record Writer (format, schema inclusion, etc). In the schema, one tag will be included for each of the variables defined taking into account the specified datatype. Also, a ts (timestamp) field is additionally included containing the read date. An example of the content of a flowfile for the previously defined properties:
[ { "var1" : true, "var2" : false, "var3" : "\u0005", "var5" : 1992, "var4" : "4", "timestamp" : 1628783058433 } ]