FB_IolRead
Funktionsbaustein zum Lesen von IO-Link Parametern in einer nicht objektorientierten Lösung.
Eingänge
Name | Typ | Beschreibung |
---|---|---|
bExecute | BOOL | Steigende Flanke zum Starten des Funktionsblocks |
sNetid | T-AmsNetid | AMS NETID des IO-Link Masters |
nlolPort | IO-Link Port des IO-Link-Geräts | |
nIndex | WORD | Index des IO-Link-Geräteparameters |
nSubindex | BYTE | Subindex des IO-Link-Geräteparameters |
pDSTBuf | PVOID | Zeiger auf Zielpuffer |
cbBufLen | UDINT | Größe der zu lesenden Datenbytes |
tTimeout | TIME | Maximal zulässige Ausführungszeit |
Ausgänge
Name | Typ | Beschreibung |
---|---|---|
bBusy | BOOL | Busy-Flag des Funktionsblocks |
bDone | BOOL | Done-Merker des Funktionsblocks |
bError | BOOL | Fehlermerker des Funktionsblocks |
hResult | HRESULT | Rückgabewert dieses Funktionsblocks |
nADSError | E_AdsErr | ADS-Fehlercode |
nIolError | IO-Link-Fehlercode |
Beispiel
Der folgende FB ist Teil des IoLink Beispielprojekts. Weitere Informationen finden Sie im Kapitel Beispiele.
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
Voraussetzungen
Entwicklungsumgebung | Erforderliche SPS-Bibliothek |
---|---|
TwinCAT ab v3.1.4024.25 | Tc3_IoLink ab v3.3.4.0 |