Beckhoff#Let’s use Tc3_IoLink

The PLC library Tc3_IoLink is a library that can be used for communication with IoLink devices, and it supports the following profiles:

  • Common Profile
  • Smart Sensor Profile

Within this library, there are function blocks available that allow for the reading and writing of parameters.

System requirements

  • WinXP, WES, Win7, WES7, WEC7 IPC or CX, (x86, x64, ARM)
  • Min. TwinCAT Version:3.1.4024.25
  • Min. TwinCAT Level:TC1200 TC3 PLC

Reference Link

Beckhoff#Let’s use EL6224

Basic

Before using Tc3_IOLINK, let me guide you on how to read data from an IO-LINK device using the Beckhoff TwinCAT’s AoE screen. Please click on EL6224.

Open the AoE-Online Tab.

You can select a Port number from the Port Drop-Down List in the IO-Link Profile.

This time, we sent a Read command to Port 4, Index 16, SubIndex 0.The string “Contrinex AG” is returned in the Read-String.

In fact, you can check the Index, SubIndex, Data Type and Default value of each Index by checking the IO-LINK Device Manual of each company.


How to check the AMS Net-ID?

Open EL6224 and from >AoE-Onlne ,there is a field called NetId.

This number is the AMS Net-ID.

Add library

Add Tc3_IoLink library by Reference>Add Library.

Search for Tc3_IoLink and add Library with Ok.

DUT

Here are the DUTs used in this article.

E_IolPort

Specifies the port number.

Port11
Port22
Port33
Port44
Port55
Port66
Port77
Port89

E_IolPortError

This is the error content of IO-Link communication.

NoError0
WatchdogDetected1
InternalError2
InvalidDeviceID3
InvalidVendorID4
InvalidIOLinkVersion5
InvalidFrameCapability6
InvalidCycletime7
InvalidPdInLength8
InvalidPdOutLenght9
NoDeviceDetected10

E_IolPortState

This is the communication information of IO Link Port.

Disabled0
stDigIn1
stDigOut2
CommunicationOP3
CommunicationComstop4

Function

Here are the Functions used in this article.

F_IolGetChannelStateTxt

This function converts the IO-LINK Port status into text format.

VAR_INPUT

VariablesTypeDescription
nIolChStateUSINTIO-LINK channel status value
nPortE_IolPortPort number of the IO-LINK whose status you want to retrieve

VAR_OUTPUT

VariablesTypeDescription
F_IolGetChannelStateTxtString(255)Convert channel status into text information.

F_IolGetPortError

This function returns the error status of the IO-Link Port.

VAR_INPUT

VariablesTypeDescription
nIolChStateUSINTIO-LINK channel status value

VAR_OUTPUT

VariablesTypeDescription
F_IolGetPortErrorE_IolPortErrorIndicates IO Link Port error information

F_IolGetPortState

This function returns the status of the IO-Link Port.

VAR_INPUT

VariablesTypeDescription
nIolChStateUSINTIO-LINK channel status value

VAR_OUPUT

VariablesTypeDescription
E_IoLGetPortStateE_IolPortStateIndicates Port status

Function Block

Here is the Function Block used in this article.

FB_IolRead

This Function Block reads the parameters of the IO-link device.

VAR_INPUT

VariableTypeDescription
bExecuteBOOLRun at startup
sNetidT-AmsNetidIO Link Master’s AMS NET-ID
nlolPortE_lolPortIO-Link Port number you wish to access
nIndexWORDIndex of the IO-Link device you want to access
nSubindexBYTESubIndex of the IO-Link device you want to access
pDSTBufPVOIDMemory Offset where data read from the IoLink device is stored.
cbBufLenUDINTTotal Size of the storage location for data read from the IoLink device
tTimeoutTIMEMaximum execution time

VAR_OUTPUT

VariableTypeDescription
bBusyBOOLTrue=Executing
bDoneBOOLTrue=Execution succeeded
bErrorBOOLTrue=Error exists
hResultHRESULTReturn value of Function Block
nADSErrorE_AdsErrADS Error Code
nIolErrorE_IolErrorIO-Link error code

FB_IolWrite

This Function Block writes the parameters of the IO-link device.

VAR_INPUT

VariableTypeDescription
bExecuteBOOLRun at startup
sNetidT-AmsNetidIO Link Master’s AMS NET-ID
nlolPortE_lolPortIO-Link Port number you wish to access
nIndexWORDIndex of the IO-Link device you want to access
nSubindexBYTESubIndex of the IO-Link device you want to access
pSRCBufPVOIDMemory Offset of the destination for data to be written to the IoLink device.
cbBufLenUDINTTotal Size of the destination for data to be written to the IoLink device
tTimeoutTIMEMaximum execution time

VAR_OUTPUT

VariableTypeDescription
bBusyBOOLTrue=Executing
bDoneBOOLTrue=Execution succeeded
bErrorBOOLTrue=Error exists
hResultHRESULTReturn value of Function Block
nADSErrorE_AdsErrADS Error Code
nIolErrorE_IolErrorIO-Link error code

Implementation1-F_IolGetChannelStateTxt

F_IolGetChannelStateTxt Function is used to take the current Port state.

Program

The StateCh4 variable should actually be linked to the State variable of the EL6224.

VAR
      StateCh4     AT %I*:USINT;
      nPort           :E_IolPort:=E_IolPort.Port4;
      sChannelStateTxt      :STRING;
END_VAR

//F_IolGetChannelStateTxt
sChannelStateTxt:=F_IolGetChannelStateTxt(
nIolChState:=StateCh4
,nPort:=nPort
);

Result

When the IOLINK device is communicating normally, the text “Port4 is state CommunicationOP ” will return.

However, when I unplug the cable that is connected to the IO LINK device, the text changes to “Port 4 is state Disabled and has error NoDevice Detected”.

Implementation2-F_IolGetPortError

F_IolGetPortError Function is used to take the error status of the current Port.

Program

The StateCh4 variable should actually be linked to the State variable of the EL6224.

VAR
StateCh4 AT %I*:USINT;
sPortError :E_IolPortError

END_VAR

//F_IolGetPortError
sPortError:=F_IolGetPortError(
nIolChState:=StateCh4
);

Result

NoErrorOP’ returns when the IO LINK device is communicating normally.

However, when I unplug the cable connected to the IO LINK device, it changes to “NoDevice”.

Implementation3-F_IolGetPortState

F_IolGetPortState Function is used to take the current Port state.

Program

The StateCh4 variable should actually be linked to the State variable of the EL6224.

VAR
      StateCh4 AT %I*:USINT;
sPortState        :STRING;
END_VAR

//F_IolGetPortState
sPortState:=F_IolGetPortState(
nIolChState:=StateCh4
);

Result

When the IO LINK device is communicating normally, “CommunicationOP” will return.

However, when I disconnect the cable connected to the IO LINK device, it changes to “Disabled”.

Implementation4-FB_IolRead

We will use FB_IolRead Function Block to read the status of Index 16#10 and SubIndex 16#0 of the IO LINK device currently connected to the Port.

Program

VAR

    FB_IolRead           :FB_IolRead;
    DSBuffer :STRING(255);
    nPort             :E_IolPort:=E_IolPort.Port4;
    FB_IolRead_Execute   :BOOL;
END_VAR

//FB_IolRead

FB_IolRead.bExecute:=FB_IolRead_Execute;
FB_IolRead.sNetId:=’169.254.141.157.2.6′;
FB_IolRead.nIolPort:=nPort;
FB_IolRead.pDSTBuf:=ADR(DSBuffer);
FB_IolRead.cbBufLen:=SIZEOF(DSBuffer);
FB_IolRead.nIndex:=16#10;
FB_IolRead.nSubindex:=0;

FB_IolRead();

Result

Done!Contrinex returned.

Implementation5-FB_IolWrite

we will use FB_IolWrite Function Block to change the current value of Index 16#40 and SubIndex 16#3 of the IO LINK devices currently connected to the Port.

Program

VAR
FB_IolWrite:FB_IolWrite;
FB_IolWrite_Execute:BOOL;
SensorMode :USINT;
      nPort :E_IolPort:=E_IolPort.Port4
END_VAR

SensorMode:=16#18;
SrcBuff:=’Beckhoff’;
FB_IolWrite.bExecute:=FB_IolWrite_Execute;
FB_IolWrite.sNetId:=’169.254.141.157.2.6′;
FB_IolWrite.nIolPort:=nPort;
FB_IolWrite.pSRCBuf:=ADR(SensorMode);
FB_IolWrite.cbBufLen:=sizeof(SensorMode);
FB_IolWrite.nIndex:=16#40;
FB_IolWrite.nSubindex:=3;

FB_IolWrite();

Result

Done!Function Block was successfully executed without error.

Open EL6224 and check it from the AoE-Online screen.

Done! I was able to confirm the 18 I had just written.

Footer_Basic

Please Support some devices for my blog

Amazon Gift List

Find ME

Twitter:@3threes2
Email:soup01threes*gmail.com (* to @)
YoutubeChannel:https://www.youtube.com/channel/UCQ3CHGAIXZAbeOC_9mjQiWQ

シェアする

  • このエントリーをはてなブックマークに追加

フォローする