📹

06- Interfacing ctrlX CORE with IO-Link master using EtherCAT

Bosch rexroth
This video will teach you how to interface ctrlX CORE with IO-Link master using EtherCAT. The following are the examples covered in the video:

Video Timeline:

0:00 - Introduction 0:50 - What are we going to see? 1:25 - Connections 2:11 - Adding IO-Link master in the networks 6:28 - Assign memories for IO-Link devices 11:27 - Example 1: Actuating Signal Lamp using Distance sensor 19:45 - Example 2: Reading Vendor and Product ID of the IO-Link device using AoE 28:35 - Example 3: Reading the set-point of the sensor using AoE 31:52 - Example 4: Writing the set-point of the sensor using AoE 34:10 - Example 5: Visualizing IO-Link data on the Node-RED dashboard 37:49 - Outroduction

Hardware and Software information

  • Software: ctrlX Works Software Version: 1.18.1
  • Hardware: ctrlX CORE Plus
GVL declaration
1
{attribute 'qualified_only'}
2
VAR_GLOBAL
3
//Distance Sensor
4
rawbyte0 AT %IB0 : BYTE;
5
rawbyte1 AT %IB1 : BYTE;
6
7
//SignalLamp
8
//Segment1
9
segment1 AT %QB5 : BYTE;
10
segment2 AT %QB4 : BYTE;
11
segment3 AT %QB3 : BYTE;
12
segment4 AT %QB2 : BYTE;
13
segment5 AT %QB1 : BYTE;
14
END_VAR
PLC variable declaration
1
PROGRAM PLC_PRG
2
VAR
3
wData : WORD;
4
iDistance : INT;
5
bOutput : BOOL;
6
bySegment1 : BYTE;
7
END_VAR
PLC code
1
// -------------------- Reading Distance sensor process output --------------------
2
3
//Concatinate the byte 0 and byte 1
4
wData := IL_ConcatByte(GVL.rawbyte0,GVL.rawbyte1);
5
6
//Right shift the word by 4 bit
7
iDistance := WORD_TO_INT(SHR(wData,4));
8
9
//Defining limits
10
IF iDistance > 200 THEN
11
iDistance := 200;
12
END_IF
13
14
IF iDistance < 5 THEN
15
iDistance := 5;
16
END_IF
17
18
//Set point output
19
bOutput := GVL.rawbyte1.0;
20
21
//SignalLamp condition
22
IF bOutput = TRUE THEN
23
// 2= Green
24
GVL.segment1 := 2;
25
GVL.segment2 := 2;
26
GVL.segment3 := 2;
27
GVL.segment4 := 2;
28
GVL.segment5 := 2;
29
ELSE //4= RED
30
GVL.segment1 := 4;
31
GVL.segment2 := 4;
32
GVL.segment3 := 4;
33
GVL.segment4 := 4;
34
GVL.segment5 := 4;
35
END_IF
GVL declaration
1
{attribute 'qualified_only'}
2
VAR_GLOBAL
3
//Distance Sensor
4
rawbyte0 AT %IB0 : BYTE;
5
rawbyte1 AT %IB1 : BYTE;
6
7
//SignalLamp
8
//Segment1
9
segment1 AT %QB5 : BYTE;
10
segment2 AT %QB4 : BYTE;
11
segment3 AT %QB3 : BYTE;
12
segment4 AT %QB2 : BYTE;
13
segment5 AT %QB1 : BYTE;
14
END_VARde
PLC variable declaration
1
PROGRAM PLC_PRG
2
VAR
3
wData : WORD;
4
iDistance : INT;
5
bOutput : BOOL;
6
bySegment1 : BYTE;
7
8
// ---------------- Read AoE -----------------------------
9
10
//Name of instance
11
strMasterName : STRING := 'ethercatmaster';
12
13
//Ethercat address of ifm AL1332
14
uiEthercatAddr : UINT := 1005;
15
strTargetNetId : IL_ECAT_AOE_NET_ID := (Byte0:= 172, Byte1:=31, Byte2:= 254, Byte3:= 254, Byte4:= 0, Byte5:= 1);
16
17
//Vendor variable declaration for IO Link read
18
strVendor : STRING(32) := ''; //Variable in which the read result (vendor) value will be copied
19
fbIOLinkRead_Vendor: IL_ECATAoeRead;
20
21
uiIoLinkPortNbr_Vendor : UINT := 1;//X1 = Plug, the IO-Link device is connected
22
wIoLinkIndex_Vendor : WORD := 16; //IO-Link index = 16 (vendor)
23
byIoLinkSubIndex_Vendor : BYTE := 0; //IO-Link Subindex = 0 (vendor)
24
25
bVendor_Error: BOOL;
26
bVendor_Done: BOOL;
27
bRead_Vendor: BOOL;
28
29
30
// X01 Product ID variable declaration for IO Link Read
31
strProductID : STRING(32) := ''; //Variable in which the read result (Product ID) value will be copied
32
fbIOLinkRead_ProductID: IL_ECATAoeRead;
33
34
uiIoLinkPortNbr_ProductID : UINT := 1; //X1 = Plug, the IO-Link device is connected
35
wIoLinkIndex_ProductID : WORD := 19;//IO-Link index = 19 (product ID)
36
byIoLinkSubIndex_ProductID : BYTE :=0;//IO-Link Subindex = 0 (product ID)
37
38
bProductID_Error: BOOL;
39
bProductID_Done: BOOL;
40
bRead_ProductID: BOOL;
41
42
END_VAR
PLC code
1
//Read Aoe vendor ID
2
//Read function
3
fbIOLinkRead_Vendor(
4
Execute:= bRead_Vendor, //Execute bit
5
MasterName:= ADR(strMasterName), //Instance name
6
SlaveAddress:= uiEthercatAddr, //EtherCAT address of IO-Link master
7
TargetNetId:= strTargetNetId , //Refer from ctrlX I/O
8
TargetPort:= 16#1000 + uiIoLinkPortNbr_Vendor, //ADS communication port = 16#1000 + IO-Link port number
9
IndexGroup:= 16#F302, //Fixed for IFM IO-Link
10
//IDXOFFS Index Offset
11
//Bits 0-7: IO-Link subindex
12
//Bits 8-15: 00000000
13
//Bits 16-31: IO-Link index
14
IndexOffset:= (16#FFFF0000 AND SHL(ANY_TO_UDINT(wIoLinkIndex_Vendor),16))
15
OR (16#000000FF AND ANY_TO_UDINT(byIoLinkSubIndex_Vendor)),
16
SizeOfValue:= SIZEOF(strVendor), //Byte requirement
17
ValueAdr:= ADR(strVendor)); //Value
18
19
IF TRUE = fbIOLinkRead_Vendor.Done THEN
20
bVendor_Error := FALSE; // Reset error
21
bVendor_Done := TRUE;
22
END_IF;
23
24
IF TRUE = fbIOLinkRead_Vendor.Error THEN
25
bVendor_Error := TRUE; // Error handling
26
bVendor_Done := FALSE;
27
END_IF;
28
29
//Read Aoe Product ID
30
fbIOLinkRead_ProductID(
31
Execute:= bRead_ProductID,
32
MasterName:= ADR(strMasterName),
33
SlaveAddress:= uiEthercatAddr,
34
TargetNetId:= strTargetNetId ,
35
TargetPort:= 16#1000 + uiIoLinkPortNbr_ProductID,
36
IndexGroup:= 16#F302,
37
IndexOffset:= (16#FFFF0000 AND SHL(ANY_TO_UDINT(wIoLinkIndex_ProductID),16))
38
OR (16#000000FF AND ANY_TO_UDINT(byIoLinkSubIndex_ProductID)),
39
SizeOfValue:= SIZEOF(strProductID),
40
ValueAdr:= ADR(strProductID),
41
);
42
43
// -------------------- Reading Distance sensor process output --------------------
44
45
//Concatinate the byte 0 and byte 1
46
wData := IL_ConcatByte(GVL.rawbyte0,GVL.rawbyte1);
47
48
//Right shift the word by 4 bit
49
iDistance := WORD_TO_INT(SHR(wData,4));
50
51
//Defining limits
52
IF iDistance > 200 THEN
53
iDistance := 200;
54
END_IF
55
56
IF iDistance < 5 THEN
57
iDistance := 5;
58
END_IF
59
60
//Set point output
61
bOutput := GVL.rawbyte1.0;
62
63
//SignalLamp condition
64
IF bOutput = TRUE THEN
65
GVL.segment1 := 2;
66
GVL.segment2 := 2;
67
GVL.segment3 := 2;
68
GVL.segment4 := 2;
69
GVL.segment5 := 2;
70
ELSE
71
GVL.segment1 := 4;
72
GVL.segment2 := 4;
73
GVL.segment3 := 4;
74
GVL.segment4 := 4;
75
GVL.segment5 := 4;
76
END_IF

Example 3: How to read the Set-Point of distance sensor in crtlX CORE?

GVL declaration
1
{attribute 'qualified_only'}
2
VAR_GLOBAL
3
//Distance Sensor
4
rawbyte0 AT %IB0 : BYTE;
5
rawbyte1 AT %IB1 : BYTE;
6
7
//SignalLamp
8
//Segment1
9
segment1 AT %QB5 : BYTE;
10
segment2 AT %QB4 : BYTE;
11
segment3 AT %QB3 : BYTE;
12
segment4 AT %QB2 : BYTE;
13
segment5 AT %QB1 : BYTE;
14
END_VAR
PLC variable declaration
1
PROGRAM PLC_PRG
2
VAR
3
wData : WORD;
4
iDistance : INT;
5
bOutput : BOOL;
6
bySegment1 : BYTE;
7
8
// ---------------- Read AoE -----------------------------
9
10
//Name of instance
11
strMasterName : STRING := 'ethercatmaster';
12
13
//Ethercat address of ifm AL1332
14
uiEthercatAddr : UINT := 1005;
15
strTargetNetId : IL_ECAT_AOE_NET_ID := (Byte0:= 172, Byte1:=31, Byte2:= 254, Byte3:= 254, Byte4:= 0, Byte5:= 1);
16
17
//Vendor variable declaration for IO Link read
18
strVendor : STRING(32) := ''; //Variable in which the read result (vendor) value will be copied
19
fbIOLinkRead_Vendor: IL_ECATAoeRead;
20
21
uiIoLinkPortNbr_Vendor : UINT := 1; //X1 = Plug, the IO-Link device is connected
22
wIoLinkIndex_Vendor : WORD := 16; //IO-Link index = 16 (vendor)
23
byIoLinkSubIndex_Vendor : BYTE := 0; //IO-Link Subindex = 0 (vendor)
24
25
bVendor_Error: BOOL;
26
bVendor_Done: BOOL;
27
bRead_Vendor: BOOL;
28
29
30
// X01 Product ID variable declaration for IO Link Read
31
strProductID : STRING(32) := ''; //Variable in which the read result (Product ID) value will be copied
32
fbIOLinkRead_ProductID: IL_ECATAoeRead;
33
34
uiIoLinkPortNbr_ProductID : UINT := 1; //X1 = Plug, the IO-Link device is connected
35
wIoLinkIndex_ProductID : WORD := 19; //IO-Link index = 19 (product ID)
36
byIoLinkSubIndex_ProductID : BYTE :=0; //IO-Link Subindex = 0 (product ID)
37
38
bProductID_Error: BOOL;
39
bProductID_Done: BOOL;
40
bRead_ProductID: BOOL;
41
42
// X01 Set point of Variable declaration for IO Link Read
43
uiSetPointRead: UINT;
44
uiSetPointRead_swap: UINT; //Varible for byte swap output
45
bRead_SetPoint: BOOL;
46
47
fbIOLinkRead_ProductID_SetPoint: IL_ECATAoeRead;
48
49
uiIoLinkPortNbr_ProductID_SetPoint : UINT := 1; //X1 = Plug, the IO-Link device is connected
50
wIoLinkIndex_ProductID_SetPoint : WORD := 60; //IO-Link index = 60 (Set Point)
51
byIoLinkSubIndex_ProductID_SetPoint : BYTE := 1; //IO-Link Subindex = 1 (Set Point)
52
53
bProductID_SetPoint_Error: BOOL;
54
bProductID_SetPoint_Done: BOOL;
55
56
END_VAR
PLC code
1
//Read Aoe vendor ID
2
3
//Read function
4
fbIOLinkRead_Vendor(
5
Execute:= bRead_Vendor, //Execute bit
6
MasterName:= ADR(strMasterName), //Instance name
7
SlaveAddress:= uiEthercatAddr, //EtherCAT address of IO-Link master
8
TargetNetId:= strTargetNetId , //Refer from ctrlX I/O
9
TargetPort:= 16#1000 + uiIoLinkPortNbr_Vendor, //ADS communication port = 16#1000 + IO-Link port number
10
IndexGroup:= 16#F302, //Fixed for IFM IO-Link
11
//IDXOFFS Index Offset
12
//Bits 0-7: IO-Link subindex
13
//Bits 8-15: 00000000
14
//Bits 16-31: IO-Link index
15
IndexOffset:= (16#FFFF0000 AND SHL(ANY_TO_UDINT(wIoLinkIndex_Vendor),16))
16
OR (16#000000FF AND ANY_TO_UDINT(byIoLinkSubIndex_Vendor)),
17
SizeOfValue:= SIZEOF(strVendor), //Byte requirement
18
ValueAdr:= ADR(strVendor)); //Value
19
20
IF TRUE = fbIOLinkRead_Vendor.Done THEN
21
bVendor_Error := FALSE; // Reset error
22
bVendor_Done := TRUE;
23
END_IF;
24
25
IF TRUE = fbIOLinkRead_Vendor.Error THEN
26
bVendor_Error := TRUE; // Error handling
27
bVendor_Done := FALSE;
28
END_IF;
29
30
//Read Aoe Product ID
31
fbIOLinkRead_ProductID(
32
Execute:= bRead_ProductID,
33
MasterName:= ADR(strMasterName),
34
SlaveAddress:= uiEthercatAddr,
35
TargetNetId:= strTargetNetId ,
36
TargetPort:= 16#1000 + uiIoLinkPortNbr_ProductID,
37
IndexGroup:= 16#F302,
38
IndexOffset:= (16#FFFF0000 AND SHL(ANY_TO_UDINT(wIoLinkIndex_ProductID),16))
39
OR (16#000000FF AND ANY_TO_UDINT(byIoLinkSubIndex_ProductID)),
40
SizeOfValue:= SIZEOF(strProductID),
41
ValueAdr:= ADR(strProductID),
42
);
43
44
//Read Aoe Product ID Set Point
45
fbIOLinkRead_ProductID_SetPoint(
46
Execute:= bRead_SetPoint,
47
MasterName:= ADR(strMasterName),
48
SlaveAddress:= uiEthercatAddr,
49
TargetNetId:= strTargetNetId ,
50
TargetPort:= 16#1000 + uiIoLinkPortNbr_ProductID_SetPoint,
51
IndexGroup:= 16#F302,
52
IndexOffset:= (16#FFFF0000 AND SHL(ANY_TO_UDINT(wIoLinkIndex_ProductID_SetPoint),16))
53
OR (16#000000FF AND ANY_TO_UDINT(byIoLinkSubIndex_ProductID_SetPoint)),
54
SizeOfValue:= SIZEOF(uiSetPointRead),
55
ValueAdr:= ADR(uiSetPointRead),
56
);
57
58
//Byte swap of Set Point read
59
uiSetPointRead_swap := WORD_TO_UINT(IL_SwapWord(uiSetPointRead));
60
61
IF TRUE = fbIOLinkRead_ProductID_SetPoint.Done THEN
62
bProductID_SetPoint_Error := FALSE; // Reset error
63
bProductID_SetPoint_Done := TRUE;
64
END_IF;
65
66
IF TRUE = fbIOLinkRead_ProductID_SetPoint.Error THEN
67
bProductID_SetPoint_Error := TRUE; // Error handling
68
bProductID_SetPoint_Done := FALSE;
69
END_IF;
70
71
// -------------------- Reading Distance sensor process output --------------------
72
73
//Concatinate the byte 0 and byte 1
74
wData := IL_ConcatByte(GVL.rawbyte0,GVL.rawbyte1);
75
76
//Right shift the word by 4 bit
77
iDistance := WORD_TO_INT(SHR(wData,4));
78
79
//Defining limits
80
IF iDistance > 200 THEN
81
iDistance := 200;
82
END_IF
83
84
IF iDistance < 5 THEN
85
iDistance := 5;
86
END_IF
87
88
//Set point output
89
bOutput := GVL.rawbyte1.0;
90
91
//SignalLamp condition
92
IF bOutput = TRUE THEN
93
GVL.segment1 := 2;
94
GVL.segment2 := 2;
95
GVL.segment3 := 2;
96
GVL.segment4 := 2;
97
GVL.segment5 := 2;
98
ELSE
99
GVL.segment1 := 4;
100
GVL.segment2 := 4;
101
GVL.segment3 := 4;
102
GVL.segment4 := 4;
103
GVL.segment5 := 4;
104
END_IF

Example 4: How to write the Set-Point of distance sensor in crtlX CORE?

GVL declaration
1
{attribute 'qualified_only'}
2
VAR_GLOBAL
3
//Distance Sensor
4
rawbyte0 AT %IB0 : BYTE;
5
rawbyte1 AT %IB1 : BYTE;
6
7
//SignalLamp
8
//Segment1
9
segment1 AT %QB5 : BYTE;
10
segment2 AT %QB4 : BYTE;
11
segment3 AT %QB3 : BYTE;
12
segment4 AT %QB2 : BYTE;
13
segment5 AT %QB1 : BYTE;
14
END_VAR
PLC variables declaration
1
PROGRAM PLC_PRG
2
VAR
3
4
wData : WORD;
5
iDistance : INT;
6
bOutput : BOOL;
7
bySegment1 : BYTE;
8
9
// ---------------- Read AoE -----------------------------
10
//Name of instance
11
strMasterName : STRING := 'ethercatmaster';
12
//Ethercat address of ifm AL1332
13
uiEthercatAddr : UINT := 1005; strTargetNetId : IL_ECAT_AOE_NET_ID := (Byte0:= 172, Byte1:=31, Byte2:= 254, Byte3:= 254, Byte4:= 0, Byte5:= 1);
14
15
//Vendor variable declaration for IO Link read
16
strVendor : STRING(32) := ''; //Variable in which the read result (vendor) value will be copied
17
fbIOLinkRead_Vendor: IL_ECATAoeRead;
18
uiIoLinkPortNbr_Vendor : UINT := 1;//X1 = Plug, the IO-Link device is connected
19
wIoLinkIndex_Vendor : WORD := 16; //IO-Link index = 16 (vendor)
20
byIoLinkSubIndex_Vendor : BYTE := 0; //IO-Link Subindex = 0 (vendor)
21
bVendor_Error: BOOL;
22
bVendor_Done: BOOL;
23
bRead_Vendor: BOOL;
24
25
// X01 Product ID variable declaration for IO Link Read
26
strProductID : STRING(32) := ''; //Variable in which the read result (Product ID) value will be copied
27
fbIOLinkRead_ProductID: IL_ECATAoeRead;
28
uiIoLinkPortNbr_ProductID : UINT := 1; //X1 = Plug, the IO-Link device is connected
29
wIoLinkIndex_ProductID : WORD := 19; //IO-Link index = 19 (product ID)
30
byIoLinkSubIndex_ProductID : BYTE :=0; //IO-Link Subindex = 0 (product ID)
31
bProductID_Error: BOOL;
32
bProductID_Done: BOOL;
33
bRead_ProductID: BOOL;
34
35
// X01 Set point of Variable declaration for IO Link Read
36
uiSetPointRead: UINT;
37
uiSetPointRead_swap: UINT; //Varible for byte swap output
38
bRead_SetPoint: BOOL;
39
fbIOLinkRead_ProductID_SetPoint: IL_ECATAoeRead;
40
uiIoLinkPortNbr_ProductID_SetPoint : UINT := 1;//X1 = Plug, the IO-Link device is connected
41
wIoLinkIndex_ProductID_SetPoint : WORD := 60;//IO-Link index = 60 (Set Point)
42
byIoLinkSubIndex_ProductID_SetPoint : BYTE := 1; //IO-Link Subindex = 1 (Set Point)
43
bProductID_SetPoint_Error: BOOL;
44
bProductID_SetPoint_Done: BOOL;
45
46
//------------------Write AoE-------------------------
47
uiSetPointWrite : UINT := 25;
48
uiSetPointWrite_swap: UINT;
49
bWrite_SetPoint: BOOL;
50
fbIOLinkWrite_ProductID_SetPoint_write: IL_ECATAoeWrite;
51
bProductID_SetPoint_Write_Error: BOOL;
52
bProductID_SetPoint_Write_Done: BOOL;
53
54
END_VAR
PLC code
1
//Read Aoe vendor ID
2
3
//Read function
4
fbIOLinkRead_Vendor(
5
Execute:= bRead_Vendor, //Execute bit
6
MasterName:= ADR(strMasterName), //Instance name
7
SlaveAddress:= uiEthercatAddr, //EtherCAT address of IO-Link master
8
TargetNetId:= strTargetNetId , //Refer from ctrlX I/O
9
TargetPort:= 16#1000 + uiIoLinkPortNbr_Vendor, //ADS communication port = 16#1000 + IO-Link port number
10
IndexGroup:= 16#F302, //Fixed for IFM IO-Link
11
//IDXOFFS Index Offset
12
//Bits 0-7: IO-Link subindex
13
//Bits 8-15: 00000000
14
//Bits 16-31: IO-Link index
15
IndexOffset:= (16#FFFF0000 AND SHL(ANY_TO_UDINT(wIoLinkIndex_Vendor),16))
16
OR (16#000000FF AND ANY_TO_UDINT(byIoLinkSubIndex_Vendor)),
17
SizeOfValue:= SIZEOF(strVendor), //Byte requirement
18
ValueAdr:= ADR(strVendor)); //Value
19
20
IF TRUE = fbIOLinkRead_Vendor.Done THEN
21
bVendor_Error := FALSE; // Reset error
22
bVendor_Done := TRUE;
23
END_IF;
24
25
IF TRUE = fbIOLinkRead_Vendor.Error THEN
26
bVendor_Error := TRUE; // Error handling
27
bVendor_Done := FALSE;
28
END_IF;
29
30
//Read Aoe Product ID
31
fbIOLinkRead_ProductID(
32
Execute:= bRead_ProductID,
33
MasterName:= ADR(strMasterName),
34
SlaveAddress:= uiEthercatAddr,
35
TargetNetId:= strTargetNetId ,
36
TargetPort:= 16#1000 + uiIoLinkPortNbr_ProductID,
37
IndexGroup:= 16#F302,
38
IndexOffset:= (16#FFFF0000 AND SHL(ANY_TO_UDINT(wIoLinkIndex_ProductID),16))
39
OR (16#000000FF AND ANY_TO_UDINT(byIoLinkSubIndex_ProductID)),
40
SizeOfValue:= SIZEOF(strProductID),
41
ValueAdr:= ADR(strProductID),
42
);
43
44
//Read Aoe Product ID Set Point
45
fbIOLinkRead_ProductID_SetPoint(
46
Execute:= bRead_SetPoint,
47
MasterName:= ADR(strMasterName),
48
SlaveAddress:= uiEthercatAddr,
49
TargetNetId:= strTargetNetId ,
50
TargetPort:= 16#1000 + uiIoLinkPortNbr_ProductID_SetPoint,
51
IndexGroup:= 16#F302,
52
IndexOffset:= (16#FFFF0000 AND SHL(ANY_TO_UDINT(wIoLinkIndex_ProductID_SetPoint),16))
53
OR (16#000000FF AND ANY_TO_UDINT(byIoLinkSubIndex_ProductID_SetPoint)),
54
SizeOfValue:= SIZEOF(uiSetPointRead),
55
ValueAdr:= ADR(uiSetPointRead),
56
);
57
58
//Byte swap of Set Point read
59
uiSetPointRead_swap := WORD_TO_UINT(IL_SwapWord(uiSetPointRead));
60
61
IF TRUE = fbIOLinkRead_ProductID_SetPoint.Done THEN
62
bProductID_SetPoint_Error := FALSE; // Reset error
63
bProductID_SetPoint_Done := TRUE;
64
END_IF;
65
66
IF TRUE = fbIOLinkRead_ProductID_SetPoint.Error THEN
67
bProductID_SetPoint_Error := TRUE; // Error handling
68
bProductID_SetPoint_Done := FALSE;
69
END_IF;
70
71
72
//Write Aoe Product ID Set Point
73
//uiSetPointWrite_conv := ROR(SetPointWrite,8);
74
uiSetPointWrite_swap := WORD_TO_UINT(IL_SwapWord(uiSetPointWrite));
75
fbIOLinkWrite_ProductID_SetPoint_write(
76
Execute:= bWrite_SetPoint,
77
MasterName:= ADR(strMasterName),
78
SlaveAddress:= uiEthercatAddr,
79
TargetNetId:= strTargetNetId,
80
TargetPort:= 16#1000 + uiIoLinkPortNbr_ProductID_SetPoint,
81
IndexGroup:= 16#F302,
82
IndexOffset:= (16#FFFF0000 AND SHL(ANY_TO_UDINT(wIoLinkIndex_ProductID_SetPoint),16))
83
OR (16#000000FF AND ANY_TO_UDINT(byIoLinkSubIndex_ProductID_SetPoint)),
84
ValueAdr:= ADR(uiSetPointWrite_swap),
85
SizeOfValue:= SIZEOF(uiSetPointWrite_swap),
86
//SizeOfValue:= 2,
87
);
88
89
IF TRUE = fbIOLinkWrite_ProductID_SetPoint_write.Done THEN
90
bProductID_SetPoint_Write_Error := FALSE;// FB Finished -> Product name was read,
91
bProductID_SetPoint_Write_Done := TRUE;
92
END_IF;
93
94
IF TRUE = fbIOLinkWrite_ProductID_SetPoint_write.Error THEN
95
bProductID_SetPoint_Write_Error := TRUE;// Error handling
96
bProductID_SetPoint_Write_Done := FALSE;
97
END_IF;
98
99
100
// -------------------- Reading Distance sensor process output --------------------
101
102
//Concatinate the byte 0 and byte 1
103
wData := IL_ConcatByte(GVL.rawbyte0,GVL.rawbyte1);
104
105
//Right shift the word by 4 bit
106
iDistance := WORD_TO_INT(SHR(wData,4));
107
108
//Defining limits
109
IF iDistance > 200 THEN
110
iDistance := 200;
111
END_IF
112
113
IF iDistance < 5 THEN
114
iDistance := 5;
115
END_IF
116
117
//Set point output
118
bOutput := GVL.rawbyte1.0;
119
120
//SignalLamp condition
121
IF bOutput = TRUE THEN
122
GVL.segment1 := 2;
123
GVL.segment2 := 2;
124
GVL.segment3 := 2;
125
GVL.segment4 := 2;
126
GVL.segment5 := 2;
127
ELSE
128
GVL.segment1 := 4;
129
GVL.segment2 := 4;
130
GVL.segment3 := 4;
131
GVL.segment4 := 4;
132
GVL.segment5 := 4;
133
END_IF

Example 5: Visualize the parameters on the Node-RED dashboard

Node-RED Dashboard
Node-RED Dashboard
Node-RED-IO_Link_withctrlXCORE.txt
25KB
Text
Node-RED flow