Skip to content

EmcyMessage Class

A structured CANopen Emergency (EMCY) message, per CiA 301 §7.2.7.3.

public sealed class EmcyMessage

Inheritance Object → EmcyMessage

Remarks

The wire encoding is fixed at 8 bytes: - Bytes 0..1 — ErrorCode (little-endian). - Byte 2 — ErrorRegister, mirror of OD 0x1001. - Bytes 3..7 — manufacturer-specific error field (5 bytes).

The special error code 0x0000 is the "error reset / no error" indicator described in CiA 301 §7.2.7.3.1 — clients should treat it as an EMCY event just like non-zero codes and let higher layers decide how to react.

Constructors

EmcyMessage(byte, ushort, byte, ReadOnlySpan<byte>) Constructor

Constructs a new EMCY message. manufacturerSpecific must be zero to five bytes long; missing bytes are treated as zero.

public EmcyMessage(byte producerNodeId, ushort errorCode, byte errorRegister, System.ReadOnlySpan<byte> manufacturerSpecific=default(System.ReadOnlySpan<byte>));

Parameters

producerNodeId Byte

errorCode UInt16

errorRegister Byte

manufacturerSpecific ReadOnlySpan<Byte>

Fields

EmcyMessage.ManufacturerFieldLength Field

Length of the manufacturer-specific field.

public const int ManufacturerFieldLength = 5;

Field Value

Int32

EmcyMessage.WireSize Field

Fixed on-wire size of an EMCY frame.

public const int WireSize = 8;

Field Value

Int32

Properties

EmcyMessage.ErrorCode Property

Standardized error code (CiA 301 §7.2.7.3.1 Table 26).

public ushort ErrorCode { get; }

Property Value

UInt16

EmcyMessage.ErrorRegister Property

Content of the error register at the moment the EMCY was raised (mirror of OD 0x1001).

public byte ErrorRegister { get; }

Property Value

Byte

EmcyMessage.ManufacturerSpecific Property

Manufacturer-specific 5-byte error field (may be shorter for tests; padded on encode).

public byte[] ManufacturerSpecific { get; }

Property Value

Byte[]

EmcyMessage.ProducerNodeId Property

Node-id of the emergency producer (derived from COB-ID 0x080 + node-id). Zero when the frame does not carry a node association (i.e. anonymous EMCY on a bus scanner).

public byte ProducerNodeId { get; }

Property Value

Byte

Methods

EmcyMessage.Decode(byte, ReadOnlySpan<byte>) Method

Decodes an EMCY frame's payload. producerNodeId is derived from the COB-ID by the caller (cob-id - 0x080).

public static CanKit.Pro.CANopen.Emcy.EmcyMessage Decode(byte producerNodeId, System.ReadOnlySpan<byte> data);

Parameters

producerNodeId Byte

data ReadOnlySpan<Byte>

Returns

EmcyMessage

EmcyMessage.Encode() Method

Encodes the message into an 8-byte wire frame; the manufacturer-specific field is zero-padded to 5 bytes.

public byte[] Encode();

Returns

Byte[]