Sample
In this sample, the ApplicationSpecificTag is written using the WriteApplicationspecificTag methods and then read and checked using the ReadApplicationSpecificTag method.
FUNCTION_BLOCK FB_Sample_04_IolStdVarSlave
VAR_INPUT
bExecute :BOOL := FALSE;
sApplicationTag :STRING(32) := '';
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) := '';
END_VAR
VAR
bExecuteOld :BOOL;
nState :INT := 0;
fbIolSlave :FB_IolStdVarSlave;
bInitDone :BOOL := FALSE;
hr :HRESULT;
sApplicationTagRead : STRING(32) := '';
END_VAR
////
// Init
//
IF NOT bInitDone THEN
bInitDone := TRUE;
fbIolSlave.MasterAoeNetId := F_CreateAmsNetId(GVL_IO.sTerm2AmsNetId); //Creates NETID String
fbIolSlave.Port := GVL_IO.nTerm2EPI1008;
fbIolSlave.Name := 'EPI1008';
END_IF
////
// Execute/Busy State Machine
//
IF bExecute AND NOT bExecuteOld AND NOT bBusy THEN
bBusy := TRUE;
nState := 10; // WRITE
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:;
// WRITE
10:
hr := fbIolSlave.WriteApplicationSpecificTag(sApplicationTag);
IF NOT F_IolIsBusy(hr) THEN
IF FAILED(hr) THEN
bBusy := FALSE;
bError := TRUE;
sErrorTxt := fbIolSlave.ErrorTxt; // TODO
nAdsError := F_IolGetAdsError(hr);
nIolError := F_IolGetIolError(hr);
nState := 0; // IDLE;
ELSE
nState := 20; // WRITE;
END_IF
END_IF
// READ
20:
hr := fbIolSlave.ReadApplicationSpecificTag(sApplicationTagRead);
IF NOT F_IolIsBusy(hr) THEN
IF FAILED(hr) THEN
bBusy := FALSE;
bError := TRUE;
sErrorTxt := fbIolSlave.ErrorTxt; // TODO
nAdsError := F_IolGetAdsError(hr);
nIolError := F_IolGetIolError(hr);
nState := 0; // IDLE;
ELSE
nState := 30; // CHECK;
END_IF
END_IF
// CHECK
30:
IF sApplicationTag <> sApplicationTagRead THEN
bBusy := FALSE;
bError := TRUE;
sErrorTxt := 'sApplicationTag and sApplicationTagRead are not equal!';
ELSE
bBusy := FALSE;
bDone := TRUE;
nState := 0;
END_IF
END_CASE
////
// call FBs
//
fbIolSlave();