Tc3_RRCS_Sample02

Wurde der GetState-Request aus dem vorherigen Beispiel erfolgreich beantwortet, kann die Funktionalität wie folgt erweitert werden:

Laden Sie das Beispiel hier herunter:
Tc3_RRCS_Sample02

Für dieses Beispiel wurden folgende ´Logic Sources´ erstellt:

Tc3_RRCS_Sample02 1:

Basierend auf dem vorherigen Beispiel deklarieren Sie weitere Variablen:

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

Der Programmablauf aus dem vorherigen Sample wurde hier in der Statemachine um weitere Zustände ergänzt:

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

Die Anzahl und der Zustand der ´Logic Sources´ wird pollend abgefragt. Die gefundenen werden wie folgt in Arrayform zur Verfügung gestellt:

Tc3_RRCS_Sample02 2:

Jede der ´Logic Sources´ ist mittels eindeutiger ObjektID ansprechbar.
Wird der Zustand der Variabe bState geändert, wird versucht, den Zustand dieser ´Logic Source´ auf den gewünschten Wert zu setzen.
Dies geschieht mit einer Instanz des Funktionsbausteins FB_SetLogicSource.

In der GUI des RRCS-Servers wird das Setzen des Wertes der LogicSource#5 wie folgt dargestellt:

Tc3_RRCS_Sample02 3: