The attached project demonstrates how to read process input data from IO-Link devices connected to the ifm electronic AL1352 IO-Link master via the REST API in the Mosaic programming environment. The example focuses primarily on real-world application: initiating a data read in prgMain, checking the result, and subsequently decoding the retrieved binary data for a specific sensor.
The attached function block handles only the retrieval of input data from the IO-Link master. The conversion of the retrieved binary data into a meaningful structure specific to the device must be implemented separately in accordance with the IODD of the given IO-Link sensor.
How to Use the Project
The main application logic is in the prgMain.ST file. Here, the function block is called with the IP address of the master and the number of ports in use:
Read_IO_Link( rqGetData := rqGet,
ipIfm := '10.1.1.251',
usedIfmPorts := 3);
The recommended procedure is as follows:
- Set up a read request using
rqGetData. - Pass the IP address of the AL1352 module in the
ipIfmparameter. - Set the number of actively used IO-Link ports in
usedIfmPorts. - Wait until the block sets
done := TRUE. - If
err := FALSEat the same time, go through the individual ports in theresponsefield. - For each port, verify that
response[i].code = 200. - Only then pass
response[i].data.binto your own decoding function for the specific sensor.
In prgMain.ST, this procedure is demonstrated directly within the application. After successfully loading the data, the program iterates through the ports in use and calls the corresponding decoding function based on the port number:
IF Read_IO_Link.done THEN
IF Read_IO_Link.err THEN
lastErr := Read_IO_Link.infoTx;
ELSE
lastErr := '';
FOR i := 1 TO Read_IO_Link.usedIfmPorts DO
IF Read_IO_Link.response[i].code = 200 THEN
CASE i OF
1 : VVB001 := DecodeVvb001ProcessDataIn( raw := void( Read_IO_Link.response[i].data.bin[1]));
2 : KTE101 := DecodeKte101ProcessDataIn( data := Read_IO_Link.response[i].data.bin[1]);
END_CASE;
ELSE
lastErr := 'IFM port ' + USINT_TO_STRING( i) + ' (cid=' + Read_IO_Link.response[i].cid +
'): response error: ' + UINT_TO_STRING( Read_IO_Link.response[i].code);
END_IF;
END_FOR;
Read_IO_Link( rqGetData := 0);
END_IF;
END_IF;
Function Block Interface
The block's source code is located in fbRead_IO_Link_Data.ST. For general use, it is not necessary to address its internal implementation; the important parameters are primarily the inputs, outputs, and the meaning of the returned data.
Inputs
rqGetDataThe request edge for reading data from the IO-Link master.ipIfmThe IP address of the ifm AL1352 IO-Link master.usedIfmPortsThe number of ports to be read. The block supports a maximum of 8 ports.
Outputs
doneReading of all requested ports is complete.busyCommunication with the module is in progress.errAn error occurred during reading.responseAn array of responses for individual ports. Each entry contains:cidcommunication identifier,data.valuedata returned by the module in ASCII HEX format,data.binthe same data converted to binary format,codeHTTP status code.
infoTxText information about the status or error.
The block reads process input data through an endpoint:
http:///iolinkmaster/port[n]/iolinkdevice/pdin/getdata
For further processing, the most important elements are `response[i].code` and `response[i].data.bin`.
Custom Decoding of Sensor Data
Each IO-Link sensor may have a different process data structure. Therefore, the function block does not perform a general conversion of the read data to the device’s application structure. After the data is read, it is necessary to create a custom decoding function that constructs a data type corresponding to the specific sensor from the byte array.
This decoding function must be designed in accordance with the device's IODD. The IODD specifies the meaning of individual bits and bytes of process data, their order, and any scaling of values.
The typical procedure is as follows:
- Determine the structure of the input process data for a specific sensor from the IODD.
-
Design a custom
STRUCTdata type that corresponds to the values required by the application. - Create a function that parses the binary data read from
response[i].data.bininto the individual elements of this structure. - Call this function in
prgMain.STafter the data has been successfully read.
Sample Decoding Functions
The DecodeKte101ProcessDataIn.ST file demonstrates a simple example of decoding a single byte of process data from the KTE101 sensor. The function constructs a structure from a single input byte that contains the device status and binary flags for the inputs and outputs.
The DecodeVvb001ProcessDataIn.ST file presents a more complex example for the VVB001 sensor, where several numerical values, temperature, and status bits must be reconstructed from multiple bytes.
These two functions serve as a template for processing the response[i].data.bin output. This is not a general solution for all IO-Link sensors.
Significant restrictions
- The function block only reads input process data.
- The block does not handle writing data to IO-Link devices.
- The block does not handle sensor parameterization.
- The block does not perform automatic generic decoding according to IODD.
- Conversion of the read data to the structure of a specific module must be implemented separately according to the IODD of the IO-Link sensor being used.
Main Project Files
prgMain.STMain example demonstrating data reading and calling decoding functions.fbRead_IO_Link_Data.STFunction block for reading process input data from the ifm AL1352.DecodeKte101ProcessDataIn.STExample of simple decoding of sensor input data.DecodeVvb001ProcessDataIn.STAn example of decoding more extensive sensor process data.
Project group archive containing an example for download: _PG_Example_IO_Link_2026-04-16_09-19-10.piz
