Tc3_RRCS_Sample02
If the GetState request from the previous sample was answered successfully, the functionality can be extended as follows:
- A query using
GetAlive
(This function checks whether the connection exists.) - The query
IsConnectedToArtist
(This is used to determine whether the RRCS server is connected to an artist matrix) - The cyclic querying of the states of the 'Logic Sources'.
- Setting the 'Logic Sources'.
Download the example here:
Tc3_RRCS_Sample02
The following 'Logic Sources' were created for this sample:
Based on the previous sample, declare further variables:
PROGRAM MAIN
VAR
(* the state of the statemachine *)
eState: E_RRCS_State := IDLE;
(* the IP-Address and port of the PC which runs the RRCS-Server *)
fbRRCScom: FB_RRCScom(
ipAddr_Server:= '192.168.42.59',
ipPort_Server:=8193):= (eTraceLevel := TcEventSeverity.Verbose);
(* Retry in case of errors *)
tonRetry: TON := (pt := T#5S);
tonWait: TON := (pt := T#70MS);
ui: UINT;
{region 'Get States'}
(* functionblock used to get the state of the RRCS-Server *)
fbGetState: FB_GetState(pfbRRCscom := ADR(fbRRCScom));
{endregion}
{region 'Get Alive'}
bExecuteGetAlive: BOOL := TRUE;
fbGetAlive: FB_GetAlive(pfbRRCscom := ADR(fbRRCScom));
{endregion}
{region 'Is connected to Artist'}
bExecuteGetConnectedToArtist: BOOL := TRUE;
fbIsConnectedToArtist: FB_IsConnectedToArtist(pfbRRCscom := ADR(fbRRCScom));
{endregion}
{region 'Get Logic Sources'}
bExecuteGetAllLogicSources: BOOL;
fbGetAllLogicSources_V2: FB_GetAllLogicSources_v2(pfbRRCscom := ADR(fbRRCScom));
tonGetLogicSourceStates: TON;
{endregion}
{region 'Set a Logic Source'}
bState: BOOL; // the required status
_bState: BOOL;
fbSetLogicSourceState: FB_SetLogicSourceState(pfbRRCscom := ADR(fbRRCScom));
{endregion}
bErrorObjId: BOOL;
END_VAR
The program sequence from the previous sample was supplemented with additional states in the state machine:
CASE eState OF
CHECK_GATEWAY:
tonRetry(IN := FALSE);
fbGetState(bExecute:= bExecuteGetState);
bExecuteGetState:= FALSE;
IF fbGetState.bError THEN
eState:= ERROR;
ELSIF NOT fbGetState.bBusy THEN
IF fbGetState.sGatewayState = 'Working' THEN
eState := CHECK_ALIVE;
ELSE
eState := ERROR;
END_IF
END_IF
CHECK_ALIVE:
fbGetAlive(bExecute:= bExecuteGetAlive);
bExecuteGetAlive:= FALSE;
IF fbGetAlive.bError THEN
eState:= ERROR;
ELSIF NOT fbGetAlive.bBusy THEN
IF fbGetAlive.bAlive THEN
bExecuteGetConnectedToArtist:= TRUE;
eState := CHECK_CONN_ARTIST;
ELSE
eState := ERROR;
END_IF
END_IF
CHECK_CONN_ARTIST:
fbIsConnectedToArtist(bExecute:= bExecuteGetConnectedToArtist);
bExecuteGetConnectedToArtist:= FALSE;
IF fbIsConnectedToArtist.bError THEN
eState:= ERROR;
ELSIF NOT fbIsConnectedToArtist.bBusy THEN
IF fbIsConnectedToArtist.bIsConnected THEN
eState := GET_SOURCES;
ELSE
eState := ERROR;
END_IF
END_IF
GET_SOURCES:
IF bState <> _bState THEN
_bState := bState;
eState := SET_SOURCE;
ELSE
tonGetLogicSourceStates(in := TRUE, pt:= T#50MS);
IF tonGetLogicSourceStates.Q THEN
tonGetLogicSourceStates(In := FALSE);
bExecuteGetAllLogicSources := TRUE;
END_IF
fbGetAllLogicSources_V2(bExecute:= bExecuteGetAllLogicSources);
bExecuteGetAllLogicSources := FALSE;
IF fbGetAllLogicSources_V2.bError THEN
fbGetAllLogicSources_V2(bExecute:= FALSE);
eState:= ERROR;
ELSIF NOT fbGetAllLogicSources_V2.bBusy AND bExecuteGetAllLogicSources THEN
fbGetAllLogicSources_V2(bExecute:= FALSE);
IF fbGetAllLogicSources_V2.eRRCS_ErrorCode <> E_RRCS_ErrorCodes.Success THEN
eState:= ERROR;
END_IF
END_IF
END_IF
SET_SOURCE:
FOR ui := 0 TO PL_RRCS.nMaxLogicSources - 1 DO
IF fbGetAllLogicSources_V2.aLogicSources[ui].sLabel_8Char = 'Mute A' THEN
EXIT;
END_IF
END_FOR
IF ui < PL_RRCS.nMaxLogicSources THEN // Logic Source found ....
fbSetLogicSourceState(bExecute := TRUE, bState := bState,
nObjectID := fbGetAllLogicSources_V2.aLogicSources[ui].nObjectID,
aLogicSources := fbGetAllLogicSources_V2.aLogicSources);
IF fbSetLogicSourceState.bError THEN
fbSetLogicSourceState(bExecute := FALSE, aLogicSources := fbGetAllLogicSources_V2.aLogicSources);
eState:= ERROR;
ELSIF NOT fbSetLogicSourceState.bBusy THEN
fbSetLogicSourceState(bExecute := FALSE, aLogicSources := fbGetAllLogicSources_V2.aLogicSources);
eState := WAIT;
END_IF
END_IF
WAIT:
tonWAIT(In := NOT tonWAIT.Q);
IF tonWAIT.Q THEN
tonWAIT(In := FALSE);
eState := GET_SOURCES;
END_IF
ERROR:
fbGetState(bExecute:= FALSE);
tonRetry(In:= NOT tonRetry.Q);
IF tonRetry.Q THEN
bExecuteGetState:= TRUE;
eState:= CHECK_GATEWAY;
END_IF
END_CASE
IF NOT tonRetry.Q THEN
eState := SEL(fbRRCScom.eCommState = E_CommState.ERROR, eState, ERROR);
END_IF
The number and state of the logic sources is polled. Those found are made available in array form as follows:
Each of the 'Logic Sources' can be addressed by means of a unique ObjectID.
If the state of the variable bState
is changed, an attempt is made to set the state of this 'Logic Source' to the desired value.
This is done with an instance of the function block FB_SetLogicSource.
In the GUI of the RRCS server, the setting of the value of LogicSource#5 is displayed as follows: