The prgSetTecoRouteTLS program automatically checks the connection settings between the Tecomat PLC and the TecoRoute service. If the PLC is not using port 8443, the program configures it for secure communication via TLS.
The check is performed after every PLC restart. Once a connection to the TecoRoute service has been successfully established, the program terminates.
Requirement: Communication with the TecoRoute server must be enabled in the PLC configuration.
Using the program
- Add the TecoRouteLib library to the project.
- Add the prgSetTecoRouteTLS program.
- Include an instance of the program in the project’s executable task.
- Compile the project and upload it to the PLC.
- Restart the PLC. The program will automatically check and, if necessary, adjust the TecoRoute settings.
Source code
PROGRAM prgSetTecoRouteTLS
VAR
setRoutePort : BOOL := TRUE; // Request to set up a secure connection
init : BOOL;
routerPar : TTecoRoutePar;
routerStat : TTecoRouteStat;
END_VAR
IF setRoutePort THEN
// Loads the current connection parameters for TecoRoute
fcGetTecoRoutePar(
rq := TRUE,
actParSet := routerPar
);
IF NOT init THEN
IF routerPar.destPort <> 8443 THEN
// Port for a secure connection
routerPar.destPort := 8443;
init := fcSetTecoRoutePar(
rq := TRUE,
newParSet := routerPar
);
ELSE
init := TRUE;
END_IF;
END_IF;
// Checks the current connection status with the TecoRoute service
fcGetTecoRouteStat(
rq := TRUE,
status := routerStat
);
IF init THEN
IF FIND(
IN1 := routerStat.serviceStat,
IN2 := 'connected'
) > 0 THEN
setRoutePort := FALSE;
END_IF;
END_IF;
END_IF;
END_PROGRAM
How It Works
When the PLC program starts, it:
- reads the current TecoRoute service parameters;
- checks the value of
routerPar.destPort; - sets port
8443if necessary; - monitors the communication status;
- stops further checks once it finds the text
connectedin the status information.
The value of setRoutePort is initialized when the program starts, so the check is repeated after every PLC restart.
