Instantiating and initiating temperature control
For certain applications, only the temperature control should be used from the scope of the TwinCAT 3 Plastic Application. In this, but also in the normal use case, the temperature controller must be capable of being instantiated and initiated individually for this purpose. In the following sample, we will go through this process step by step.
- 1. Create a new task with a cycle time of 25 ms. This is not mandatory, but - based on experience - recommended.
- 2. Create an instance of
FB_Temperature
andFB_TemperatureHmi
and assign the mapping to the newly created task.
{attribute “qualified_only”}
VAR_GLOBAL
{attribute “TcHmiSymbol.Hide”}
{attribute “TcContextName”:=”TempTask”}
fbTemperature: FB_Temperature;
fbTemperatureHmi: FB_ TemperatureHmi;
END_VAR
- 3. Initialize the temperature classes. The following options are available for this:
- We recommend the use of FB_BaseRuntime. It is used to run through the initialization steps automatically. To do this, you only need to create an instance of the runtime (if it does not already exist), define the cycle calls and transfer the temperature classes to the runtime.
VAR_GLOBAL
fbRuntime: FB_BaseRuntime;
END_VAR
// Program with its task call referenced to PlcTask
PROGRAM PlcMain
// Build list of classes that should be called cyclically by the runtime
_Build();
// Standard call of Cyclic
fbRuntime.Cyclic();
// Program with its task call referenced to TempTask
PROGRAM TempMain
// Slow call for Temperature
fbRuntime.TemperatureCyclic()
// Method to define the runtime objects
METHOD _Build
VAR_INST
bBuild: BOOL; // Latch the Build only gets executed once
END_VAR
IF NOT bBuild THEN
bBuild := TRUE;
// Append temperature classes to be initialized and called by the runtime
fbRuntime.Append(fbTemperature, fbTemperatureHmi);
// Further objects to append
fbRuntime.Append(fbOtherObject, fbOtherObjectHmi);
END_IF
- Alternatively, you can also manually connect and initialize the objects. To do this, call the
SetHMI()
andInit()
methods of theFB_Temperature
and check the return value for successful execution. If this is the case, you can call theParamInit()
method for parameter initialization and the cycle method.
VAR
bInit: BOOL;
bInitFailed: BOOL;
bParamInit: BOOL;
hr: HRESULT;
END_VAR
IF NOT bInit AND NOT bInitFailed THEN
hr := fbTempCtrl.SetHMI(fbTempCtrlHmi);
hr := fbTempCtrl.Init();
IF SUCCEEDED(hr) THEN
bInit := TRUE;
ELSE
bInitFailed := TRUE;
END_IF
ELSIF bInit THEN
IF NOT bParamInit THEN
hr := fbTempCtrl.ParamInit();
IF SUCCEEDED(hr) THEN
bParamInit := TRUE;
END_IF
END_IF
fbTempCtrl.Cyclic();
END_IF