IMDHMIControls LibraryShop main store

How-to

Map a 32-byte IO-Link PROFINET item to a PLCnext array

PLC programming Published 5 min read

Short answer

Expand the Process Data Item column and the input block's datatype shows as OctectString[32], which connects to one array of 32 bytes. Map the whole item to a single byte-array variable instead of scalars, then split it into eight 4-byte records in logic and accept each vibration value only when its record's PQI is valid.

On this page
  1. Read the datatype the item expects
  2. Declare the array and connect the item
  3. Worked example: splitting a 32-byte block into 4-byte records
  4. Decode one record and check its PQI
  5. Prove the mapping online
  6. Questions asked

Your PROFINET side is already healthy: the controller exchanges data with the IO-Link master and you read the sensor's other values. The vibration block is different only in shape. The item labelled input data 32 Bytes is one aggregate of 32 octets — expand the "Process Data Item" column and its datatype shows as OctectString[32] — so it connects to exactly one variable of matching size and shape: a byte array. Map the whole item to a single ARRAY[0..31] OF BYTE variable, then split that array in PLC logic into eight 4-byte records and check each record's PQI before you decode a vibration value. Scalars, lone four-byte variables and padded structures all fail because their size or layout does not match the item.

Read the datatype the item expects #

Click the > control at the top of the "Process Data Item" column in PLCnext Engineer and the view expands to show the datatype of every PROFINET variable. For the vibration block it reads OctectString[32]: a single aggregate of 32 octets, not eight separately mappable scalars. That display answers "which variable can I connect" by itself, because compatibility is decided by size and aggregate shape, never by the engineering meaning of the bytes inside.

PLC-side variable Connects to the item? Why
ARRAY[0..31] OF BYTE Yes Contiguous, 32 byte elements, no other members
One REAL or DWORD No Four bytes offered against a 32-byte item
Eight separate 4-byte variables No The item is one aggregate and cannot be split at this boundary
A structure with padding or extra members No Total size or member layout differs

Because the master hands the sensor's cyclic data over as ordinary PROFINET items, this path needs no IO-Link library on the controller; the controller-side library is a separate subject, covered in why the PLCnext IO-Link library will not run with a third-party master.

Declare the array and connect the item #

  1. Create a user-defined datatype in PLCnext Engineer: an array of BYTE with the bounds 0..31. PLCnext Engineer supports namespaces for user-defined data types, so the type can live under your application's namespace.
  2. Instantiate one variable of that type, for example InputBytes, in a scope the process-data mapping editor accepts.
  3. Compile the declarations. If the variable is not offered as a target later, check its scope, compilation state, element type and element count before changing anything else.
  4. In the mapping view select the input data 32 Bytes item and connect InputBytes to it. Do not connect individual records at this boundary: the boundary transfers the raw image and your logic performs the second stage.
  5. Compile the hardware and application configuration and download both to the controller.

Worked example: splitting a 32-byte block into 4-byte records #

Inputs, with where each comes from:

  • Item length: 32 bytes, read from the input data 32 Bytes item in your PROFINET configuration.
  • Record length: 4 bytes per record including PQI, from the sensor's process-data layout, the same layout you already consumed on your previous controller.
  • Record count: unknown, to be derived.

Rule in words: the record count is the item length divided by the record length, and record n occupies the byte indexes from (n − 1) × 4 up to n × 4 − 1.

Arithmetic:

  • 32 bytes ÷ 4 bytes per record = 8 records.
  • Record 1 covers bytes 0..3, record 2 covers bytes 4..7, record 3 covers bytes 8..11, and record 8 covers bytes 28..31.
  • First byte of record n = 4 × (n − 1); for the third record that is 4 × 2 = 8.

Result: the block holds eight records, and the third record lives in InputBytes[8] through InputBytes[11].

Decision: map the item once at the PROFINET boundary and decode at these fixed offsets in logic. Accept a record's vibration value only when its PQI evaluates to valid process data; any record that fails its PQI is discarded, never converted.

Decode one record and check its PQI #

The byte count tells you nothing about byte order, signedness, scaling or where the PQI sits; those come from the sensor's process-data description. Two things are fixed and save you time: IO-Link process data is little-endian, so a value's least significant byte sits at the record's lowest index, and the PQI position is identical in every record of the block, so you confirm it once and reuse the check throughout. Vibration values arrive as cyclic process data; reading the sensor's parameters (ISDU) is a separate acyclic path, covered in reading IO-Link ISDU parameters over PROFINET acyclic record data.

  1. Copy one record's raw bytes into a working buffer with plain indexed assignments. The names below are illustrative: InputBytes is your mapped array, Rec the record buffer, n the record counter.
VAR
    InputBytes : ARRAY[0..31] OF BYTE;  (* mapped to the item "input data 32 Bytes" *)
    Rec        : ARRAY[0..3] OF BYTE;   (* raw bytes of one record *)
    n          : INT := 3;              (* record counter, 1 to 8; example: record 3 *)
    k          : INT := 0;              (* byte index within the record *)
END_VAR

FOR k := 0 TO 3 DO
    Rec[k] := InputBytes[4 * (n - 1) + k];
END_FOR
  1. Evaluate that record's PQI per the sensor description before you touch the value bytes.
  2. Only on valid PQI, assemble the value bytes in the documented order and apply the documented representation and scaling to reach engineering units.
  3. Repeat at each record offset.

The test that proves the copy: with n left at 3, Rec[0] must follow InputBytes[8] and Rec[3] must follow InputBytes[11] while the earlier bytes keep their own behavior. If Rec instead tracks the block's first bytes, the offset arithmetic is off by one record.

Prove the mapping online #

  1. Put InputBytes in an online watch view and watch every element, not only the ones you expect to move.
  2. Record the online states of the IO-Link port and the PROFINET device.
  3. Change the vibration condition on one sensor port: that record's value bytes must change while the other records stay logically independent.
  4. Break the sensor connection under controlled commissioning conditions, machine stopped and never on a running safety function, and confirm your logic discards the value through PQI instead of holding it as good data.
  5. Restore the connection and confirm valid PQI, moving bytes and a plausible decoded value together.

If the watched array is all zero or frozen, separate two cases before you change any datatype: the mapping may be inactive, or the master may be delivering a valid but unchanged image. The online port status and the PQI content tell the two apart.

Questions asked

Can I map eight separate 4-byte variables instead of one array?

Only if the master's device description offers the block as separate submodules you can configure. When the configuration exposes one aggregate item, the PLC side must be one variable of matching size and the split happens in logic. Check whether a smaller submodule can be selected in the PROFINET configuration before writing any code, because that would remove the second-stage decoding entirely.

Does the same method work for a 16-byte or 64-byte item?

Yes, with the same rule: connect an array with exactly the element count the datatype shows, then divide by the record length from the sensor's process-data description. For example, a 16-byte item with 4-byte records holds four records at byte offsets 0, 4, 8 and 12, and a 64-byte item with the same record length holds sixteen. The record length is the only number you take from the device documentation.

Where do the scaling and engineering units come from?

From the sensor's process-data definition, the IODD or the sensor manual, never from the array. The bytes you mapped are transport only: the definition fixes the value width, signedness, resolution per bit and the resulting unit, and you apply those only after the record's PQI check passes. The array itself carries no units at all.

What about data going the other way, to the sensor?

The same size-and-shape rule applies to output items. An output item of a given byte count connects to one array of exactly that many bytes, and your logic fills those bytes before the master transmits them. Map the whole output item as one array and compose the record layouts in code, mirroring what you did on the input side.

Keep reading

  • Troubleshooting

    Reading IO-Link ISDU parameters over PROFINET acyclic record data

    If cyclic IO-Link process data exchanges normally, leave out the connect section of IOL_CALL and address the identification and ISDU calls with the hardware ID of the proxy submodule for the target port, read straight from the PROFINET device configuration. A valid connect result such as 8 proves only that a lookup succeeded, not that it selected your port's submodule.

    PLC programming

  • How-to

    Pass a PLC byte array to a C++ module via its TMC data area

    A TwinCAT 3 PLC compiler refuses array arguments in an external function call with the error 'Structured value types not allowed in external function calls'. Pass the array instead through an Input-Destination data area declared in the module's .tmc file: declare a byte array member there, rebuild, instantiate the module, link the data area to a matching PLC array, and activate the configuration.

    PLC programming

  • How-to

    Map physical I/O channels in CODESYS V3.5

    Add the device description for the controller and every I/O module, insert each module under the bus interface it physically hangs on, and bind channel to variable in the device's I/O Mapping tab. Match the variable's type to the channel's exposed type, convert raw values in code, and treat a successful login as proof of nothing about the I/O.

    PLC programming