FC_DiagMsgRead - General Information

Overview

Type:

Function

Available as of:

SystemInterface_1.32.6.0

Versions:

Current version

Task

Read the diagnostic information.

Description

The function reads the diagnostic buffer (FIFO buffer) of the controller once.

This provides you a history of diagnostic messages since the last restart of the controller or flush of the buffer (FC_DiagFlush).

If there is no diagnostic message inside the buffer, the function waits until a diagnostic message is received or the timeout, specified in i_diTimeout has expired.

If i_diTimeout = 0, the function waits for a message without a timeout, and blocks the corresponding task.

The diagnostic buffer can contain a maximum of 200 messages. The oldest message is presented first for reading (FIFO). When the buffer is full, any new message replaces the oldest message.

Reading the buffer does not delete any pending diagnostic message, the other messages will be deleted from the buffer after reading.

If there is no message in the buffer and the timeout has expired, the function returns -3 as result, otherwise 0 if a message could be read.

The diagnostic messages with the class 1 to 7 since the start-up (restart) of the controller can be read.

Interface

Input

Data type

Description

i_diTimeout

DINT

Maximum waiting period in Systemticks.

The Systemticks parameter is specified in the Parameters tab of the device editor of the controller. Systemticks are defined in CPU (Central Processing Unit) ticks per second. Systemticks define the number of clock interrupts per second of the CPU. One systemtick is the minimum time a task can wait.

If i_diTimeout = 0 , the function waits for a message without a timeout, and blocks the corresponding task.

See example code below.

Input/Output

Data type

Description

iq_diNr

DINT

Diagnostic number

iq_diClass

DINT

Diagnostic class

iq_stLogAdr

DINT

Logical address of the controller.

Return Value

Data type

Description

DINT

0: OK. A message could be read from the buffer.

-3: Timeout. No message read. See example code below.

The result is reflected in a structure that is returned by a pointer.

Example Code

PROGRAM SR_Diag
VAR
   xReadDiag: BOOL := FALSE;   (* Trigger reading process *)
   diReturn: DINT;   (* -3 if in timeout time, no diagnostic could be read *)
   diTimeout: DINT := 4000;   (* Waitingtime for incoming diagnostic message to the queue in Systemticks *)
   diDiagNr: DINT;   (* read diagnostic number *)  
   diClass: DINT;   (* read diagnostic class *)  
   stLogAdr: ST_LogicalAddress;
   arstDiag: ARRAY [1..200] OF stDiag;   (* Diagnostic buffer *)  
   uiIndex: UINT := 0;
   uiState: UINT := 0;
   iTaskRunning: INT;
END_VAR
(* Diagnostic classes:
4 Detected fatal error with complete stop (high priority)
3 Detected error with single shutdown (if the detected error is triggered by one axis)
2 Warning  
1 Message (low priority)
0 deactivated
stLogicalAddress:
udiType UDINT Type, as specified in the lower 12 bits of the module type in the ConnectorMapList.
udiInstance, UDINT: Instance number (based on the module type)
udiParameterId, UDINT: Identification number of the parameter
*)
iTaskRunning := iTaskRunning+1;
IF xReadDiag AND uiState = 0 THEN
   uiState := 1;
   xReadDiag := FALSE;
ELSE
   xReadDiag := FALSE;
END_IF
CASE uiState OF
0:  (* wait and reset *)
   diReturn := -1;
   diDiagNr := 0;
   diClass := 0;
   stLogAdr.udiInstance := 0;
   stLogAdr.udiParameterId := 0;
   stLogAdr.udiType := 0;
1: diReturn := SystemInterface.FC_DiagMsgRead(diTimeout, diDiagNr,diClass, stLogAdr);
   uiState := 2;   (* Keep in mind: using diTimeout 0 the task stops here until a diagnostic can be read from the function *)
2: IF diReturn = 0 THEN
      uiState := 3;
   ELSIF diReturn = -3 THEN
      uiState := 4;
   ELSE
      uiState := 99;
   END_IF
3:(* OK, diagnostic was read *)
   arstDiag[uiIndex].diClass := diClass;
   arstDiag[uiIndex].diDiagNr := diDiagNr;
   arstDiag[uiIndex].stLogAdr := stLogAdr;
   uiIndex := uiIndex+1;
   uiState := 0;
4:  (* Timeout without receiving a diagnostic *)
   uiState := 0;
99:  (* ERROR DETECTED *)
   ;
END_CASE