Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY

 

CANopenSDOManager (PRG)

Description

SDO manager program is used to reserve and release CSDO channels.

The application needs to define an array of CANopenCSDO instances; one instance for every node-ID (i.e. SDO server).

 

SDO manager needs to be initialized with its Init action. Init action has to be done for each used CAN bus.

 

Limitations

To make a SDO client request in CAN bus, it is mandatory to reserve a CSDO instance with action Reserve.

 

  • SDO manager needs to be initialized with Init action for every used CAN bus.

  • The maximum number of node-IDs depends on the size of the CANopenCSDO instance array and vice versa. It is recommended to define as many instances as there are CANopen devices in the bus.

  • SDO manager only handles access to CANopenCSDO instances, it doesn’t update the instance.

  • SDO manager doesn't have timeouts. The user must always free used CSDO instance after usage, otherwise no other user can send a SDO request for reserved node id.

 

 

Inputs

Input variable name

Data type

Range

Description

i_pDevice

POINTER TO Device

> 0

Pointer to device.

i_NodeId

BYTE

1..127

Node Id for which CSDO is wanted to reserve.

i_pCsdoArrayStart

POINTER TO CANopenCSDO

> 0

Pointer to the start of the CSDO instance array which is defined in the PLCopen application.

i_CsdoArraySize

BYTE

-

Size of the array pointer to which was given above with input variable i_pCsdoArrayStart.

 

Outputs

Output variable name

Data type

Description

o_Error

Erros

Error code.

o_pCSDOHandle

POINTER TO CANopenCSDO

Handle to CSDO instance that is reserved for use. The pointer is set to NULL, if there is not free CSDO instance.

 

Actions

Action name

Used inputs/outputs

Description

Init

i_itfChannel

i_pCsdoArrayStart

i_CsdoArraySize

o_Error

Action initializes CANopenCSDO instance array that is defined in the application. Init action is required for all used CAN buses.

Reserve

i_itfChannel

i_NodeId

o_Error

o_pCSDOHandle

Action reserves CSDO instance for defined node-ID.

When CSDO instance is reserved successfully, a pointer of the instance is returned to o_pCSDOHandle and o_Error is set to NoError. Otherwise o_pCSDOHandle is set to NULL and o_Error is set to NoFreeCsdoInstance.

 

NOTE! Action Release is required if this action is used.

Release

i_itfChannel

i_NodeId

o_Error

Releases the defined CSDO instance.

 

Errors

Error code

Description

NotInitialized

CSDO not initialized for given CAN channel.

NoFreeCsdoInstance

Node-ID not found from reserved CSDO instance list, or CSDO instance has communication ongoing.

InputError

No CSDO array or device pointer given.

InvalidChannel

Device interface returned invalid CAN channel number.

NoError

No errors.

 

Example code

This program is included in MultiTool Creator code template.

 

Definitions:

 

Device: EPEC_CANopen.Device;

CSDOS: ARRAY[1..127] OF EPEC_CANopen.CANopenCSDO := [ (* CSDO instances *)

    (i_NodeID := 2, i_Enable := FALSE, i_pDevice := ADR(Device)),

    (i_NodeID := 3, i_Enable := FALSE, i_pDevice := ADR(Device)),

    (i_NodeID := 4, i_Enable := FALSE, i_pDevice := ADR(Device)),

    (i_NodeID := 5, i_Enable := FALSE, i_pDevice := ADR(Device))];

 

CSDOHandle: POINTER TO CANopenCSDO := 0;

CSDO_Error: EPEC_CANopen.Errors := EPEC_CANopen.Errors.NotInitialized;

 

 

Init:

 

 

EPEC_CANopen.CANopenSDOManager.Init(

    i_pDevice:=ADR(Device),

    i_NodeId:=Device.NodeID,

    i_pCsdoArrayStart:=ADR(CSDOS),

    i_CsdoArraySize:=127,

    o_Error=>CSDO_Error

);

 

 

CANopenSDOClient uses CANopenSDOManager internally for CSDO channel reservation. Code below is needed only if user uses CANopenCSDO directly and handles CSDO channels manually.

 

Definitions:

 

csdoHandle:POINTER TO CANopenCSDO := 0;

 

 

Code:

 

(* Get handle by defining bus and node id *)

CANopenSDOManager.Reserve(

    i_pDevice:= CSDOS[i].i_pDevice,

    i_NodeID:= CSDOS[i].i_NodeID,

    o_pCSDOHandle=> CSDOHandle

);

 

(* Make needed action by using CSDO instance. *)

...

CSDOHandle^.i_pDevice := CSDOS[i].i_pDevice;

CSDOHandle^.i_NodeID := CSDOS[i].i_NodeID;

CSDOHandle^.i_SDOMux := UINT_TO_DWORD(i_Index) * DWORD#256 + USINT_TO_DWORD(i_SubIndex);

CSDOHandle^.i_pData := i_pData;

CSDOHandle^.i_Size := i_Size;

CSDOHandle^.i_Write := i_Write;

CSDOHandle^.i_Enable := TRUE;

CSDOHandle^.i_Stop := FALSE;

CSDOHandle^.i_TransferTimeoutStatus := FALSE;

CSDOHandle^.i_Timeout := i_MessageTimeOut;

CSDOHandle^.i_DontChgByteOrd := i_DontChgByteOrd;

CSDOHandle^();

CSDOHandle^.i_Enable:=FALSE;

 

...

 

(* Release handle *)

CANopenSDOManager.Release(

    i_pDevice:= CSDOS[i].i_pDevice,

    i_NodeID:= CSDOS[i].i_NodeID,

);

 

 

 

 

See also

 

 

Source file topic001029.htm

Last updated 13-Jun-2024