Supported platforms: CODESYS 2.3, CODESYS 3.5
EMCY protocol is used to inform other network participants about device-internal errors.
Action name |
Description |
CreateErrorReg |
Generates an ErrorRegister value for index 16#1001 Creates an error register (1001h) value from the errors in the predefined error field. |
Init |
The action initializes the EMCY protocol.
The action creates type definition indexes 0005h, 0006h and 0007h and indexes 1001h(error register), 1003h(EMCY codes), 1014h(EMCY COB-ID) and 1015h (inhibit time).
The action sets the EMCY COB-ID to 80h if it is zero. |
SDO1003h |
SDO handler of index 1003h (EMCY codes). Provides the EMCY code for SDO reply. |
Send |
Sends EMCY messages. |
Update |
The update action of EMCY protocol. |
Update1003h |
Updates the amount of active EMCYs in the index 1003h (EMCY codes). |
This function block implements the CANopen.ICANopenProtocol interface. The function block maintains the pre-defined error field (1003h) and error register (1001h).
Methods
Method name |
Description |
Init |
The method initializes the EMCY protocol.
The method creates type definition indexes 0005h, 0006h and 0007h and indexes 1001h (error register), 1003h (EMCY codes), 1014h (EMCY COB-ID) and 1015h (inhibit time).
The method sets the EMCY COB-ID to 80h + node-ID if it is zero. |
Update |
The update method of EMCY protocol. |
EMCY protocol is up and running.
Definitions: |
|
VAR CANopenDeviceEmcyCodes:ARRAY [0..1] OF CANopenEMCYObject; (*Two EMCY objects*) Startimer: TON; (*Timer for demonstrating EMCY's*) Errorstate:BYTE; (*Variable for demonstrating EMCY's*) END_VAR
|
|
Init: |
|
(*Define first EMCY code 6201h with error register mask 81h i.e. when this EMCY is active in index 1001 there is data 81h*)
CANopenDeviceEmcyCodes[0].Details:=16#AAAA; CANopenDeviceEmcyCodes[0].ErrorCode:=16#6201; CANopenDeviceEmcyCodes[0].ErrorRegisterMask:=16#81;
(*Define second EMCY code 6202h with error register mask 41h i.e. when this EMCY is active in index 1001 there is data 41h*)
CANopenDeviceEmcyCodes[1].Details:=16#BBBB; CANopenDeviceEmcyCodes[1].ErrorCode:=16#6202; CANopenDeviceEmcyCodes[1].ErrorRegisterMask:=16#41;
(*Set first EMCY active*)
CANopenEMCYActivate(i_Device:=ADR(CANopenDevice), i_EmcyObject:=ADR(CANopenDeviceEmcyCodes[0])); Startimer(IN:=TRUE , PT:=T#2s); (*Wait 2 seconds*)
|
|
Code:
Code: |
|
Startimer(); IF Startimer.Q AND Errorstate=0 THEN (*After 2 seconds*) Startimer(in:=FALSE); (*Clear timer*)
(*Clear first EMCY*) CANopenEMCYPassive(i_Device:=ADR(CANopenDevice), i_EmcyObject:=ADR(CANopenDeviceEmcyCodes[0])); Errorstate:=1; (*Next state*) Startimer(in:=TRUE); (*Start timer 2s*) END_IF
IF Startimer.Q AND Errorstate=1 THEN (*After 2 seconds*) Startimer(in:=FALSE); (*Clear timer*)
(*Set second EMCY active*) CANopenEMCYActivate(i_Device:=ADR(CANopenDevice), i_EmcyObject:=ADR(CANopenDeviceEmcyCodes[1])); Errorstate:=2; (*Next state*) Startimer(in:=TRUE); (*Start timer 2s*) END_IF
IF Startimer.Q AND Errorstate=2 THEN (*After 2 seconds*) Startimer(in:=FALSE); (*Clear timer*)
(*Set first EMCY active*) CANopenEMCYActivate(i_Device:=ADR(CANopenDevice), i_EmcyObject:=ADR(CANopenDeviceEmcyCodes[0])); Errorstate:=3; (*Next state*) Startimer(in:=TRUE); (*Start timer 2s*) END_IF
IF Startimer.Q AND Errorstate=3 THEN (*After 2 seconds*) Startimer(in:=FALSE); (*Clear timer*)
(*Clear first EMCY*) CANopenEMCYPassive(i_Device:=ADR(CANopenDevice), i_EmcyObject:=ADR(CANopenDeviceEmcyCodes[0])); Errorstate:=4; (*Next state*) Startimer(in:=TRUE); (*Start timer 2s*) END_IF
|
|
Code: |
|
Startimer(); IF Startimer.Q AND Errorstate=0 THEN (*After 2 seconds*) Startimer(in:=FALSE); (*Clear timer*)
(*Clear first EMCY*) CANopenEMCYDeactivate(i_Device:=ADR(CANopenDevice), i_EmcyObject:=ADR(CANopenDeviceEmcyCodes[0])); Errorstate:=1; (*Next state*) Startimer(in:=TRUE); (*Start timer 2s*) END_IF
IF Startimer.Q AND Errorstate=1 THEN (*After 2 seconds*) Startimer(in:=FALSE); (*Clear timer*)
(*Set second EMCY active*) CANopenEMCYActivate(i_Device:=ADR(CANopenDevice), i_EmcyObject:=ADR(CANopenDeviceEmcyCodes[1])); Errorstate:=2; (*Next state*) Startimer(in:=TRUE); (*Start timer 2s*) END_IF
IF Startimer.Q AND Errorstate=2 THEN (*After 2 seconds*) Startimer(in:=FALSE); (*Clear timer*)
(*Set first EMCY active*) CANopenEMCYActivate(i_Device:=ADR(CANopenDevice), i_EmcyObject:=ADR(CANopenDeviceEmcyCodes[0])); Errorstate:=3; (*Next state*) Startimer(in:=TRUE); (*Start timer 2s*) END_IF
IF Startimer.Q AND Errorstate=3 THEN (*After 2 seconds*) Startimer(in:=FALSE); (*Clear timer*)
(*Clear first EMCY*) CANopenEMCYDeactivate(i_Device:=ADR(CANopenDevice), i_EmcyObject:=ADR(CANopenDeviceEmcyCodes[0])); Errorstate:=4; (*Next state*) Startimer(in:=TRUE); (*Start timer 2s*) END_IF
|
|
Source file Topic000188.htm
Last updated 4-Sep-2025