Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY
This function block implements both Heartbeat producer and consumer.
Sends current NMT status to CAN bus according to the Producer Heartbeat Time (i.e. SDO index 16#1017).
Registers a callback FBs to all listed heartbeat producers.
|
NMT and OD protocols must also be added to protocol stack and initialized before initializing HB with Init method. |
|
When Init method is called, it sends the first HB message, i.e. 'boot-up' message. The NMT status should be NMTState.BootUp at that time. |
Initializes HB protocol and adds OD indexes:
16#1017 Producer heartbeat time.
16#1016 Consumer heartbeat times (optional)
Sends the first HB message.
Input variable name |
Data type |
Description |
i_pDevice |
POINTER TO Device |
Pointer to device |
Output variable name |
Data type |
Range |
Description |
o_Error |
Errors (ENUM) |
|
Protocol error. |
Error |
Reason |
ODFull |
Object dictionary is full. Cannot add index. |
COBIDAlreadyRegistered |
COB-ID is already registered. |
CallbackBufferFull |
Number of registered COB-IDs exceeded G_MAX_NUMBER_OF_COBIDS when initializing callback. |
InterfaceError |
Device channel interface missing, or low level (CL2) library returned error. |
NotInitialized |
CAN channel not initialized, or not connected to given CANopen device. |
InputError |
Given pointer NULL or protocol data missing. |
NoError |
No errors. |
This method registers a callback handler for consumed heartbeat message COB-ID.
Input variable name |
Data type |
Description |
i_pDevice |
POINTER TO Device |
Pointer to device |
i_pCallback |
POINTER TO CANopenHBCallback |
Pointer to HB consumer handler instance. |
Output variable name |
Data type |
Range |
Description |
o_Error |
ENUM |
Errors |
Protocol error. |
Error |
Reason |
ProtocolDataMissing |
HB protocol not added to stack. |
InputError |
Given device or instance pointer null. |
InterfaceError |
Device channel interface missing, or low level (CL2) library returned error. |
NoError |
No errors. |
This method
Updates HB producer by sending heartbeat messages.
Updates HB consumer by checking timeouts of all consumed HBs (optional).
Input variable name |
Data type |
Description |
i_Enable |
BOOL |
Enable protocol operation. NOT IMPLEMENTED. |
Output variable name |
Data type |
Range |
Description |
o_Error |
Errors (ENUM) |
|
Protocol error. |
Error |
Reason |
ProtocolDataMissing |
NMT or HB protocol not added to stack. |
InterfaceError |
Device channel interface missing, or low level (CL2) library returned error. |
NotInitialized |
Protocol has not been initialized, or null device pointer given to init.. |
NoError |
No errors. |
The function block instance only contains protocol data. It has no functionality and no input or output parameters.
|
This function block is included in MultiTool Creator code template if CANopen is selected to use. |
Definitions: |
|
Device: EPEC_CANopen.Device; Protocols: ARRAY[1..n] OF EPEC_CANopen.ProtocolEntry; ProtocolAdded: ARRAY[1..n] OF BOOL := [n(0)];
HBCTimes: ARRAY[1..1] OF UDINT := [UDINT#400]; HB_Error: EPEC_CANopen.Errors := EPEC_CANopen.Errors.NotInitialized;
HBCallbacks: ARRAY[1..1] OF EPEC_CANopen.CANopenHBCallback := [ (i_NodeID := 2, i_Time := HBCTimes[1], i_pNext := 0)];
HB: EPEC_CANopen.HBData; (* Protocol data *) HB_Handler: EPEC_CANopen.CANopenHB; (* Protocol handler *)
|
Init: |
|
HB.HeartBeat.PT := T#200MS; (* HB producer time *) HB.pHBCTimes := ADR(HBCTimes); (* HB consumer times *)
Protocols[3].Protocol:=EPEC_CANopen.ProtocolType.HB; Protocols[3].pData:=ADR(HB); Protocols[3].itfProtocol:=HB_Handler; Protocols[3].pError:=ADR(HB_Error);
ProtocolAdded[3] := CANopenDeviceAddProtocol( (* Add to protocol stack *) i_pDevice:=ADR(Device), i_pProtocol:=ADR(Protocols[3]) ); IF ProtocolAdded[3] THEN HB_Handler.Init( i_pDevice := ADR(Device), o_Error => HB_Error );
(* Add monitored nodes only if consumer *) HB_Handler.AddCallbackToList( i_pDevice := ADR(Device), i_pCallback:=ADR(HBCallbacks[1]) );
ELSE HB_Error := EPEC_CANopen.Errors.ProtocolDataMissing; END_IF
|
Code: |
|
(* NOTE! The Update method call is needed for producer only. *)
HB_Handler.Update( i_Enable := TRUE, o_Error => HB_Error );
|
-
Source file topic001013.htm
Last updated 21-Feb-2025