Supported platforms: CODESYS 2.3, CODESYS 3.5
One instance of NM_NetworkManager function block can monitor and/or manage one CAN bus.
Before NM_NetworkManager can be initialized, an initialization CANopen HBConsumer data pointer must be set, but protocol should not be initialized yet.
A quantity of the data, must be same as the count of the nodes on a NM_Node array. If the NM_Node array node count is greater, initialization will fail, cause it can not initialize all the nodes on the NM_Node array. When CANopen HBConsumer data pointer is set, the Init action of the NetworkManager can be executed. The HBConsumer initializes the CANopen heartbeat data to the 1016h (+a sub index) OD index. The sub index corresponds the position of the NM_Node array.
This function output status o_BusOk is true, when all nodes with a mandatory flag TRUE are at operational state. When the heart beat receive interval goes over a ConsumerTime, the node is considered missing and the status is therefore set to -1. When mandatory flag is false, it does not affect the o_BusOk state, but still it's status is updated. The node status is updated to the array, and the node status and time since the last heartbeat is updated every time this function block is executed. The values of the State and the TimeSinceLastHeartbeat of the NM_Node array, are updated every time a NM_NetworkManager is executed.
The CANopen bus nodes are controlled when i_ThisIsMaster input is true and the master (this) node is in operational state. When the master node status is operational, the reset flag is true and the node is either in preoperational nor operational state, a CANopen reset command is sent. When the master node status is operational, keepalive flag is true and the node is not in operational state, a CANopen start command is sent. After the CANopen start command is sent, the next NMT command is sent after i_StartInterval (ms) period to the same node.
CANopen slave devices are configured, when it is in preoperational state after slave or master bootup (init state). After slave unit is configured it is started via NMT start command. Two methods is available for configuring multiple slave devices, one at the time (i_SimultaneousSlaveConfiguration = FALSE) or all simultaneously (i_SimultaneousSlaveConfiguration = TRUE). When one at the time is selected, only on slave device is configured at the time. When slave unit is configured, it continues with the next one.
When the o_BusOk status is FALSE, the application of the control unit should make sure that corresponding safety actions are taken care of. |
All changes on array of NM_Node boolean controls affects when instance of this function block is called. When the node-ID or ConsumerTime is changed, the Init action must be executed again. Every CAN bus with CANopen should have at least one instance of this function block. |
Input variable name |
Data type |
Range |
Description |
i_ThisIsMaster |
BOOL |
FALSE/TRUE |
Enables or disables master functionality. |
i_DrvNbr |
BYTE |
1..4 ( 1..2 ) |
Number of CAN bus to monitor/manage. |
i_StartInterval |
UINT |
0..65535 |
Interval of start messages (ms). |
i_pMonitoredNodes |
POINTER TO NM_Node |
address |
Pointer to the beginning of array of nodes to monitor. |
i_NumberOfNodes
|
BYTE |
1..254 |
Number of nodes to monitor/manage. This is the number of nodes in array which i_pMonitoredNodes points to. |
i_SimultaneousSlaveConfiguration |
BOOL |
FALSE/TRUE |
If TRUE, all slave units are configured simultaneously. If FALSE, NM_NetworkManager waits until slave is configured before starting the configurations of the next unit. |
Output variable name |
Data type |
Range |
Description |
o_BusOk |
BOOL |
FALSE / TRUE |
TRUE when all mandatory nodes are in operational state. Otherwise FALSE |
Action name |
Description |
Init |
Initializes the network manager. Init action sets CANopen heartbeat consumer data. This can be done after heart beta consumer data is set to the HBConsumer protocol. |
Definitions: |
|
G_NetworkManagerCan1:NM_NetworkManager; (* Instance of CAN bus 1 manager *)
(* Array of monitored nodes *) G_NodeMonitorsCan1: ARRAY[0..2] OF NM_Node := (NodeID:=2,KeepAlive:=TRUE,Reset:=TRUE,Mandatory:=TRUE,ConsumerTime:=1000,State:=-1,TimeSinceLastHeartbeat:=0), (NodeID:=3,KeepAlive:=TRUE,Reset:=TRUE,Mandatory:=TRUE,ConsumerTime:=1000,State:=-1,TimeSinceLastHeartbeat:=0), (NodeID:=4,KeepAlive:=TRUE,Reset:=TRUE,Mandatory:=TRUE,ConsumerTime:=1000,State:=-1,TimeSinceLastHeartbeat:=0);
(* Work area for CANopen heartbeat protocol. *) CANopenConsumingHBs:ARRAY [0..2] OF CANopenHeartBeat; (*Hearbeats to consumer, 3 nodes. *)
(* CANopen protocol entry, heartbeat consumer. *) HBProtocol:CANopenProtocolEntry;
|
Init:
HBProtocol.ProtocolType := HBCons; HBProtocol.Init := INDEXOF(CANopenHBConsumer.Init); HBProtocol.pDevice := G_CANopenDevice1; HBProtocol.Update := INDEXOF(CANopenHBConsumer.Update); HBProtocol.Data := ADR(Dev1Hccons);
(* Init CAN open heart beat consumer protocol. *) CANopenDeviceAddProtocol(i_pDev:=G_CANopenDevice1, i_pProtocol:=ADR(HBProtocol));
(* Gives works space for CANopen heartbeat consumer. *) FOR i:=0 TO (SIZEOF(CANopenConsumingHBs)/SIZEOF(CANopenConsumingHBs[0]))-1 DO CANopenConsumingHBs[i].i_NodeID:=i+128; (*Add heartbeat consumer to device*) CANopenConsumeHB(i_pDevice:=G_CANopenDevice1, i_pProducer:=ADR(CANopenConsumingHBs[i])); END_FOR
(* Initializes NetworkManager, set new data from G_NodeMonitorsCan1 to CANopen CANopenConsumingHBs *) |
|
G_NetworkManagerCan1.Init( i_ThisIsMaster :=TRUE, (* This is master, start's "keepalive" nodes *) i_DrvNbr :=1, (* CAN bus 1 *) i_StartInterval :=5000, (* NMTStart command interval of one managed node 5000ms.*) i_pMonitoredNodes:=ADR(G_NodeMonitorsCan1) ,(* Pointer to global array "G_NodeMonitorsCan1" *) i_NumberOfNodes :=SIZEOF(G_NodeMonitorsCan1)/SIZEOF(G_NodeMonitorsCan1[0]),(* Count of nodes ( 3 ) *) i_SimultaneousSlaveConfiguration:=FALSE);
|
Code: |
|
G_NetworkManagerCan1(o_BusOk=>CANbus1Status); (* refresh node status and sends NMT commands, if needed.*)
|
Input variable name |
Data type |
Range |
Description |
i_ThisIsMaster |
BOOL |
FALSE/TRUE |
Enables or disables master functionality. |
i_CanChannel |
CANVXD_API.ICANVXD |
|
CAN channel interface. |
i_StartInterval |
UINT |
0..65535 |
Interval of start messages (ms). |
i_pMonitoredNodes |
POINTER TO NM_Node |
address |
Pointer to the beginning of array of nodes to monitor. |
i_NumberOfNodes
|
BYTE |
1..254 |
Number of nodes to monitor/manage. This is the number of nodes in array which i_pMonitoredNodes points to. |
i_SimultaneousSlaveConfiguration |
BOOL |
FALSE/TRUE |
If TRUE, all slave units are configured simultaneously. If FALSE, NM_NetworkManager waits until slave is configured before starting the configurations of the next unit. |
Output variable name |
Data type |
Range |
Description |
o_BusOk |
BOOL |
FALSE / TRUE |
TRUE when all mandatory nodes are in operational state. Otherwise FALSE |
Action name |
Description |
Init |
Initializes the network manager. Init action sets CANopen heartbeat consumer data. This can be done after heart beat consumer data is set to the HBConsumer protocol. |
Definitions: |
|
G_CAN1_NetworkManager:NM_NetworkManager; (* Instance of CAN bus 1 manager *)
(* Array of monitored nodes *) G_CAN1_MonitoredNodes: ARRAY[0..2] OF NM_Node := (NodeID:=2,KeepAlive:=TRUE,Reset:=TRUE,Mandatory:=TRUE,ConsumerTime:=1000,State:=-1,TimeSinceLastHeartbeat:=0), (NodeID:=3,KeepAlive:=TRUE,Reset:=TRUE,Mandatory:=TRUE,ConsumerTime:=1000,State:=-1,TimeSinceLastHeartbeat:=0), (NodeID:=4,KeepAlive:=TRUE,Reset:=TRUE,Mandatory:=TRUE,ConsumerTime:=1000,State:=-1,TimeSinceLastHeartbeat:=0);
G_CAN1_CANopenDevice_HbConsumerNodes:ARRAY [1..1] OF CANopenHeartBeatProducer:= [(i_NodeID:=2,i_Time:=T#400MS,i_pNext:=0) (i_NodeID:=3,i_Time:=T#400MS,i_pNext:=0) (i_NodeID:=4,i_Time:=T#400MS,i_pNext:=0)];
(* CANopen protocol entry, heartbeat consumer. *) HBProtocol:CANopenProtocolEntry;
|
Init:
HBProtocol.ProtocolType := HBCons; HBProtocol.Init := INDEXOF(CANopenHBConsumer.Init); HBProtocol.pDevice := G_CANopenDevice1; HBProtocol.Update := INDEXOF(CANopenHBConsumer.Update); HBProtocol.Data := ADR(Dev1Hccons);
(* Init CAN open heart beat consumer protocol. *) CANopenDeviceAddProtocol(i_pDev:=G_CANopenDevice1, i_pProtocol:=ADR(HBProtocol));
(* Gives works space for CANopen heartbeat consumer. *) FOR i:=0 TO (SIZEOF(CANopenConsumingHBs)/SIZEOF(CANopenConsumingHBs[0]))-1 DO CANopenConsumingHBs[i].i_NodeID:=i+128; (*Add heartbeat consumer to device*) CANopenConsumeHB(i_pDevice:=G_CANopenDevice1, i_pProducer:=ADR(CANopenConsumingHBs[i])); END_FOR
(* Initializes NetworkManager, set new data from G_NodeMonitorsCan1 to CANopen CANopenConsumingHBs *) |
|
G_NetworkManagerCan1.Init( i_ThisIsMaster :=TRUE, (* This is master, start's "keepalive" nodes *) i_CanChannel :=G_CAN1_CANopenDevice.itfCanChannel, (* CAN bus 1 *) i_StartInterval :=5000, (* NMTStart command interval of one managed node 5000ms.*) i_pMonitoredNodes:=ADR(G_NodeMonitorsCan1) ,(* Pointer to global array "G_NodeMonitorsCan1" *) i_NumberOfNodes :=SIZEOF(G_NodeMonitorsCan1)/SIZEOF(G_NodeMonitorsCan1[0]),(* Count of nodes ( 3 ) *) i_SimultaneousSlaveConfiguration:=FALSE);
|
Code: |
|
G_NetworkManagerCan1(o_BusOk=>CANbus1Status); (* refresh node status and sends NMT commands, if needed.*)
|
Source file Topic000239.htm
Last updated 19-Dec-2024