Supported platforms: CODESYS 3.5

 

IPGNCallbackHandler (ITF)

Description

This is the interface to PGN handling POU. The interface is used as a receive callback and has method HandlePGN.

 

HandlePGN method is executed each time when PGN is received if callback interface is defined.

Typically this is used by higher level libraries.

 

Limitations

This interface and it's methods are used only in CODESYS 3.5.

 

 

Method HandlePGN

Inputs

Input variable name

Data type

Description

i_pData

DWORD

Callback data pointer.

 

 

Example

The following example shows how to define callback to PGN and update data from the callback.

 

The following defines data struct which is given as data pointer to callback.

 

Data struct

 

 

TYPE Pgn_CallbackData :

STRUCT

   pPGN_Data: POINTER TO J1939_PGN;

   msgCount: BYTE;

END_STRUCT

END_TYPE

 

 

The following shows a callback POU.

 

Callback function block

 

 

FUNCTION_BLOCK PGNCallback IMPLEMENTS IPGNCallbackHandler

 

 

HandlePGN method

 

 

METHOD HandlePGN

VAR_INPUT

  (* Callback data pointer *)

  i_pData : DWORD;

END_VAR

VAR

  pCallBackData: POINTER TO Pgn_CallbackData;

END_VAR

 

 

Code in HandlePGN

 

 

IF i_pData <> 0 THEN

  pCallBackData := i_pData;

  pCallBackData^.msgCount := pCallBackData^.msgCount + 1;

END_IF

 

The following initializes callback and callback data to PGN.

 

Definitions

 

VAR

  PGNCallback: PGNCallback; // Callback instance

  CallbackData: Pgn_CallbackData; // Callback data

END_VAR

 

 

Note: The definition of receive PGN is not shown in this example, the RxPGN variable can be replaced by the PGN struct from code template.

 

Init code

 

CallBackData.pPGN_Data := ADR(RxPGN);

CallBackData.MsgCount := 0;

 

RxPGN.itfCallback:=PGNCallback;

RxPGN.pCallbackData:=ADR(CallBackData);

 

See also

 

 

Source file topic001081.htm

Last updated 19-Dec-2024