Querying CPU data (specific)
This sample demonstrates access to CPU data by the IPC diagnostics via the specific function block FB_MDP_CPU_Read.
This sample cannot be modified for access to other IPC diagnostics modules such as fan data.
Following the program code of the sample you will find the textual Description of the sample program.
Sample: access via the specific function block FB_MDP_CPU_Read
The specific function block FB_MDP_CPU_Read facilitates access to selected data of the CPU module in the Configuration Area of the IPC diagnostics.
Enumeration definition
//** = simply adjust these lines if modifying code for own purposes
// central definition of state machine states
// (supports easy program modification)
{attribute 'qualified_only'}
TYPE E_State :
(
Idle,
ReadCPUDataInit, //** initiate reading CPU data
ReadCPUDataProcess //** process reading CPU data
);
END_TYPE
Variable Declaration
PROGRAM MAIN
VAR
// internal use
sAmsNetId : STRING := ''; //** ADS Net ID (local = '')
eState : E_State; // Enum with index for state machine
bStart : BOOL := TRUE; // flag to trigger (re)start of statemachine
// FB instances
fbReadCPUData : FB_MDP_CPU_Read; // instance of FB for reading CPU data
// results of execution
bError : BOOL; // error flag (indicator: error occured)
nErrID : UDINT; // last error ID
stHeaderCpuMod : ST_MDP_ModuleHeader; // buffer for header data of CPU module
stCPUData : ST_MDP_CPU; // structure which will contain CPU data
END_VAR
Program code
// For an easy reuse of the following code for own purposes, parts of this sample program use
// "general" data names (and copy the results in specific variables after processing the code).
CASE eState OF
E_State.Idle:
IF bStart THEN
bStart := FALSE;
eState := E_State.ReadCPUDataInit; //** initiate first state
END_IF
E_State.ReadCPUDataInit: //** trigger FB: request CPU data
fbReadCPUData(
bExecute := TRUE, // Flag: trigger execution of FB
iModIdx := 0, //** Instance of desired module type (0 = first instance)
sAmsNetId := sAmsNetId); // AMS Net ID
eState := E_State.ReadCPUDataProcess; //** next state: process FB
E_State.ReadCPUDataProcess: //** process FB: request CPU data
fbReadCPUData(bExecute := FALSE); // Flag: Get execution state of FB
IF NOT fbReadCPUData.bBusy THEN // FB executed?
IF fbReadCPUData.bError THEN // Error?
bError := TRUE; // set error flag
nErrID := fbReadCPUData.nErrID; // store error id
eState := E_State.Idle; // finish state machine
ELSE // set parameters for next steps
bError := FALSE; // turn off error flag
stHeaderCpuMod := fbReadCPUData.stMDP_ModuleHeader; //** store CPU module header data
stCPUData := fbReadCPUData.stMDP_ModuleContent; //** store CPU data
eState := E_State.ReadCPUDataInit; //** read next set of CPU data
END_IF
END_IF
END_CASE
Description of the sample program
The function block "FB_MDP_CPU_READ" requires a minimum of two parameters:
- The AMS Net ID as input parameter for the address of the IPC (local: ‘‘)
- A structure stMDP_ModuleContent that contains the data after calling the function block.
the function block does not supply the CPU temperature; this can only be read via the generic sample program. The value "CPU temperature" is not supported by all IPCs.
The parameters and the function block are used at these points in the program:
The state machine
The states of the state machine are listed as constants in order to enable simple adaptation of the program. The desired "State" value thus only needs to be centrally changed once. The statuses are defined as enumeration declarations in the PLC project in subfolder "DUTs" as DUT under the name "E-State".
The various areas of the state machine and their functions are explained below: