Tc3_RRCS_Sample01
This simple sample is used exclusively to check the communication between TwinCAT and the RRCS server. Download the example here:
Tc3_RRCS_Sample01
All the required variables are declared in the variable declaration (MAIN program) and the address data is set in the same way as for the RRCS server. In this case:
- the RRCS server runs on a Beckhoff IPC with the IP address 192.168.42.59
- the RRCS server listens on port 8193
- the TwinCAT sample runs on a Beckhoff Embedded PC with the IP address 192.168.42.3
Variable declaration:
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);
{region 'Get States'}
(* functionblock used to get the state of the RRCS-Server *)
fbGetState: FB_GetState(pfbRRCscom := ADR(fbRRCScom));
{endregion}
END_VAR
The program is then created based on a state machine:
CASE eState OF
CHECK_GATEWAY:
tonRetry(IN := FALSE);
fbGetState(bExecute:= TRUE);
IF fbGetState.bError THEN
eState:= ERROR;
ELSIF NOT fbGetState.bBusy THEN
IF fbGetState.sGatewayState = 'Working' THEN
eState := IDLE;
ELSE
eState := ERROR;
END_IF
END_IF
ERROR:
fbGetState(bExecute:= FALSE);
tonRetry(In:= NOT tonRetry.Q);
IF tonRetry.Q THEN
eState:= CHECK_GATEWAY;
END_IF
END_CASE
IF NOT tonRetry.Q THEN
eState := SEL(fbRRCScom.eCommState = E_CommState.ERROR, eState, ERROR);
END_IF
If you start the program, the status of the state machine (eState) is IDLE. To query the state of the RRCS server, you must set the state of eState to CHECK_GATEWAY. See also: https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/2531621771.html.
If the request was successful, the state of the eState changes back to IDLE after a few cycles and the variable sGatewayState
receives the value 'Working'.
If an error occurs during the query, the state of the eState changes to ERROR and further attempts are made according to the time specified in tonRetry
.