Supported platforms: CODESYS 2.3, CODESYS 3.5

 

CANopen302_SDOManager (PRG)

Description

CANopen302_SDOManager handles access to CSDO channels. The application needs to define an array of CANopenCSDO instances; one instance for every node-ID.

 

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

 

Limitations

  • 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

CODESYS 2.3CODESYS 2.3

 

Input variable name

Data type

Range

Description

i_CanBusNbr

BYTE

0,1,2..

Number of used CAN bus.  

i_NodeId

BYTE

1..127

Node Id for which CSDO is wanted to reserve.

i_CsdoArrayStart

POINTER TO CANopenCSDO

 

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_CsdoArrayStart.

 

CODESYS 3.5CODESYS 3.5

 

Input variable name

Data type

Range

Description

i_itfChannel

CANVXD_API.ICANVXD

 

CAN interface.  (From Code_Template_globals, for example, G_CAN1_Channel: EPEC_CANL2.Channel;)

i_NodeId

BYTE

1..127

Node Id for which CSDO is wanted to reserve.

i_pCsdoArrayStart

POINTER TO CANopenCSDO

 

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

CODESYS 2.3CODESYS 2.3

 

Output variable name

Data type

Description

o_Error

CANopen302_ErrorCodes

Error code

o_CSDOHandle

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.

 

CODESYS 3.5CODESYS 3.5

 

Output variable name

Data type

Description

o_Error

CANopen302_ErrorCodes

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

CODESYS 2.3CODESYS 2.3

 

Action name

Used inputs/outputs

Description

Init

i_CanBusNbr

i_CsdoArrayStart

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_CanBusNbr

i_NodeId

o_Error

o_CSDOHandle

Action reserves CSDO instance for defined node-ID.

When CSDO instance is reserved successfully, a pointer of the instance is returned to o_CSDOHandle and o_Error is set to CANopen302ErrorSuccess. Otherwise o_CSDOHandle is set to NULL and o_Error is set to CanOpen302ErrorNoFreeCsdoInstance.

 

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

Release

i_CanBusNbr

i_NodeId

o_Error

Releases  the defined CSDO instance.

 

CODESYS 3.5CODESYS 3.5

 

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 CANopen302ErrorSuccess. Otherwise o_pCSDOHandle is set to NULL and o_Error is set to CanOpen302ErrorNoFreeCsdoInstance.

 

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

Release

i_itfChannel

i_NodeId

o_Error

Releases  the defined CSDO instance.

 

Errors

 

Example code

CODESYS 2.3CODESYS 2.3

 

Definitions:

 

CAN1_MyCsdos:ARRAY [1..10] OF CANopenCSDO;

 

Init:

 

(*In the beginning of the PLCopen application use init action *)

 

CANopen302_SDOManager.Init( i_CanBusNbr:= 0,i_CsdoArrayStart:= ADR(Can1_myCsdos),i_CsdoArraySize:= 10);

 

Code:

 

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

CANopen302_SDOManager.Reserve( i_CanBusNbr:= 0 ,i_NodeId:= 2,o_CSDOHandle=>myCsdoHandle);

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

...

...

(* Release handle *)

CANopen302_SDOManager.Release( i_CanBusNbr:= 0 ,i_NodeId:= 2);

 

 

 

CODESYS 3.5CODESYS 3.5

 

Definitions:

 

CAN1_MyCsdos:ARRAY [1..10] OF CANopenCSDO;

 

Init:

 

(*In the beginning of the PLCopen application use init action *)

 

CANopen302_SDOManager.Init( i_itfChannel:= G_CAN1_CANopenDevice.itfCanChannel,

                            i_CsdoArrayStart:= ADR(Can1_myCsdos),

                            i_CsdoArraySize:= 10);

 

Code:

 

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

CANopen302_SDOManager.Reserve( i_itfChannel:= G_CAN1_CANopenDevice.itfCanChannel ,i_NodeId:= 2, o_CSDOHandle=>myCsdoHandle);

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

...

...

(* Release handle *)

CANopen302_SDOManager.Release( i_itfChannel:= G_CAN1_CANopenDevice.itfCanChannel, i_NodeId:= 2);

 

 

 

See also

CANopen302_ErrorCodes

 

CANopen initialization and transfer code examples for CODESYS 2.3 or CODESYS 3.5.

 

Source file Topic000409.htm

Last updated 13-Jun-2024