FB_IolRead

Function block for reading IO-Link parameters in a non-object-oriented solution.
Inputs
Name | Type | Description |
---|---|---|
bExecute | BOOL | Rising edge to start the function block |
sNetid | T-AmsNetid | AMS NETID of the IO-Link master |
nlolPort | IO-Link port of the IO-Link device | |
nIndex | WORD | Index of the IO-Link device parameter |
nSubindex | BYTE | Subindex of the IO-Link device parameter |
pDSTBuf | PVOID | Pointer to target buffer |
cbBufLen | UDINT | Size of the data bytes to be read |
tTimeout | TIME | Maximum allowed execution time |
Outputs
Name | Type | Description |
---|---|---|
bBusy | BOOL | Busy flag of the function block |
bDone | BOOL | Done flag of the function block |
bError | BOOL | Error flag of the function block |
hResult | HRESULT | Return value of this function block |
nADSError | E_AdsErr | ADS error code |
nIolError | IO-Link error code |
Sample
The following function block is part of the IoLink sample project. For more information, see the chapter Samples.
FUNCTION_BLOCK FB_Sample_01_IolRead
VAR_INPUT
bExecute :BOOL := FALSE;
END_VAR
VAR_OUTPUT
bBusy :BOOL := FALSE;
bDone :BOOL := FALSE;
bError :BOOL := FALSE;
nAdsError :E_AdsErr := E_AdsErr.NOERR;
nIolError :E_IolError := E_IolError.NoError;
sErrorTxt :STRING(255) := '';
sApplicationTag :STRING(32) := '';
END_VAR
VAR
bExecuteOld :BOOL;
nState :INT := 0;
fbIolRead :FB_IolRead;
END_VAR
////
// Execute/Busy State Machine
//
IF bExecute AND NOT bExecuteOld AND NOT bBusy THEN
bBusy := TRUE;
nState := 10; // READ
ELSIF NOT bExecute THEN
bBusy := FALSE;
bError := FALSE;
bDone := FALSE;
nAdsError := E_AdsErr.NOERR;
nIolError := E_IolError.NoError;
sErrorTxt := '';
END_IF
bExecuteOld := bExecute;
////
// FB State Machine
//
CASE nState OF
// IDLE
0:;
// READ
10:
sApplicationTag := '';
fbIolRead(bExecute := FALSE);
fbIolRead.sNetId := F_CreateAmsNetId(GVL_IO.sTerm2AmsNetId);
fbIolRead.nIolPort := E_IolPort.Port1;
fbIolRead.pDSTBuf := ADR(sApplicationTag);
fbIolRead.cbBufLen := SIZEOF(sApplicationTag);
fbIolRead.nIndex := 16#18;
fbIolRead.nSubindex := 0;
fbIolRead.bExecute := TRUE;
nState := 20; // WAIT_FOR_DONE
// WAIT_FOR_DONE
20:
IF fbIolRead.bDone THEN
bDone := TRUE;
bBusy := FALSE;
nState := 0; // IDLE
END_IF
END_CASE
////
// call FBs
//
fbIolRead();
////
// Error Handling
//
IF NOT bError AND bBusy THEN
IF fbIolRead.bError THEN
nState := 0;
bBusy := FALSE;
bError := TRUE;
nAdsError := fbIolRead.nAdsError;
nIolError := fbIolRead.nIolError;
sErrorTxt := F_IolGetErrorTxt(fbIolRead.hresult);
END_IF
END_IF
Requirements
Development environment | Required PLC library |
---|---|
TwinCAT from v3.1.4024.25 | Tc3_IoLink from v3.3.4.0 |