FetchPLC

Purpose

This processor is supposed to read specific register values from a PLC device, and to generate NiFi records from these readings.

General Concept

A minimum setup requires an enabled PLC4X Connection Pool, a Record Writer, and any number of registers defined in the Address Map (dynamic properties). During execution, it compiles the Address Map into an Avro schema, and connects to the device, specified by the Connection Pool. Then reads the addresses from the device, and converts the results into a NiFi record, on success. Failing to read any of the specified registers count as an error, and in this case no record is generated, even if there is a partial result.

User can supply input FlowFile to this processor, by connecting it after another one. In this case, the attributes or the contents of the input can be referred in the Address Map, using Expression Language. Please note that, if Expression Language is present in the Address Map, the address syntax is not validated.

Address Map

Address Map is defined as Dynamic Properties in the processor settings. Validation fails, if there is none defined. The generated record consists of fields, and the mapping defines which field should contain which PLC register's value. The name (key) defines the record field, the value defines the PLC register's address. (Please refer to the Driver documentation, to find the required address format.) You can define any number of fields, all of these are fetched in a single pass.

Schema Cache

The processor needs to compile the Address Map into an Avro Schema, which uses noticeable amount of the system resources for a short duration (a spike). Normally this is done only once, when the processor starts up.

With Expression Language, you can make the Address Map dynamic, that can require multiple schema versions to be generated, during execution. The Schema Cache stores these compilations in an associative FiFo array, so that the schemas are generated only once, if there are no more variations than the specified cache size.

Input

Providing input is not necessary. In case you do, the processor will only read data, when an input FlowFile is available, and you can refer to the attributes of this file, when specifying the Address Map.

If input is not provided, the processor reads data as per Run Schedule.

Output

In case of a successful reading, the emitted FlowFile contain a single NiFi record, written by the specified Record Writer. In case of failure, there is no output, if the processor has no ingress connection.

The failure relationship is only used, if the processor is driven by an input FlowFile, and was unable to read all the specified registers. In this case, the input FlowFile is forwarded as-is.

Note: Partial read results are always dropped.

Type Mapping

Due to the limitations of Avro, some data types are translated into plain string value, and the correct type information is not carried over in the generated records. You can find the exact mapping below:

Mapping of PLC4X data types to Avro field types
PLC Type Name Numeric Code (HEX) Avro Type
NULL0x00stringType
BOOL0x01booleanType
BYTE0x02intType
WORD0x03intType
DWORD0x04longType
LWORD0x05stringType
USINT0x11intType
UINT0x12intType
UDINT0x13longType
ULINT0x14stringType
SINT0x21intType
INT0x22intType
DINT0x23intType
LINT0x24longType
REAL0x31floatType
LREAL0x32doubleType
CHAR0x41stringType
WCHAR0x42stringType
STRING0x43stringType
WSTRING0x44stringType
TIME0x51stringType
LTIME0x52stringType
DATE0x53stringType
LDATE0x54stringType
TIME_OF_DAY0x55stringType
LTIME_OF_DAY0x56stringType
DATE_AND_TIME0x57stringType
LDATE_AND_TIME0x58stringType
Struct0x61stringType
List0x62array (of first element type)
RAW_BYTE_ARRAY0x71bytesType

PLC4X Documentation

PLC4X Support