Supported platforms: CODESYS 2.3, CODESYS 3.5

 

CANopenCSDOTransfer (FB)

Description

This function block is implemented to handle access to CSDO channels.

It is possible to make several instances from this function block.

 

Functionality of the function block is as follows:

  1. The user starts the transfer by setting input parameters and enabling input i_Enable.

  2. The function block checks if there is a free CSDO channel to be used for the transfer. If there is a free channel, the state is moved to CSDOReqTransferOn, otherwise the state is moved to CSDOReqWaitChn.

  3. The function block stays in the state CSDOReqTransferOn until the transfer is executed, time out occurs or the execution is stopped by setting flag i_Stop to TRUE.

 

Limitations

CANopen302_SDOManager program must be initialized properly before using CANopenCSDOTransfer. In MultiTool Creator code template initializations are done automatically.

 

Do not make a SDO request to index 0h.

Inputs

CODESYS 2.3CODESYS 2.3

Input variable name

Data type

Range

Description

i_Enable

BOOL

TRUE/FALSE

CSDO transfer is started when i_Enable changes from FALSE to TRUE.

i_Channel

BYTE

0,1,2,..

CAN bus number 0,1,2,..

i_NodeID

BYTE

1 - 127

Unique ID number of the control unit. Can be changed between requests.

i_Index

WORD

 

CANopen OD main index.

i_SubIndex

BYTE

 

CANopen OD sub-index.

i_Data

DWORD

 

Pointer to data buffer for send/received data

i_Size

DWORD

 

Size of the data buffer.

i_Write

BOOL

TRUE/FALSE

TRUE - SDO download , FALSE - SDO upload

i_Stop

BOOL

TRUE/FALSE

Stops the SDO request.

i_TimeOut

TIME

 

Time out for action. This includes also time which is waited to get free CSDO channel. Time out for whole transfer sequence.

i_DontChgByteOrd

BOOL

 

Flag can be used to prevent swapping of the byte order. This has meaning only in case when MOTOROLA byte order flag is set.

i_TimeOut_ReqResp

TIME

 

Time out for one SDO request-response pair

 

 

CODESYS 3.5CODESYS 3.5

Input variable name

Data type

Range

Description

i_Enable

BOOL

TRUE/FALSE

CSDO transfer is started when i_Enable changes from FALSE to TRUE.

i_itfChannel

CANVXD_API.ICANVXD

 

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

i_NodeID

BYTE

1 - 127

Unique ID number of the control unit. Can be changed between requests.

i_Index

WORD

 

CANopen OD main index.

i_SubIndex

BYTE

 

CANopen OD sub-index.

i_pData

DWORD

 

Pointer to data buffer for send/received data

i_Size

DWORD

 

Size of the data buffer.

i_Write

BOOL

TRUE/FALSE

TRUE - SDO download , FALSE - SDO upload

i_Stop

BOOL

TRUE/FALSE

Stops the SDO request.

i_TimeOut

TIME

 

Time out for action. This includes also time which is waited to get free CSDO channel. Time out for whole transfer sequence.

i_DontChgByteOrd

BOOL

 

Flag can be used to prevent swapping of the byte order. This has meaning only in case when MOTOROLA byte order flag is set.

i_TimeOut_ReqResp

TIME

 

Time out for one SDO request-response pair

 

 

Outputs

Output variable name

Data type

Range

Description

o_State

CANopenCSDOTransferStates

0,1,2,3

Status of the function block instance.

Not the status of the used CSDO channel.

0 - Default value

1 - Wait for CSDO channel

2 - Transfer going

3 - Idle

o_Ready

BOOL

TRUE/FALSE

Set true when transfer is ready.

User must check out from o_Error if there has been problems in transfers.

o_AbortCode

DWORD

 

Possible abort code

o_Size

DWORD

 

Number of copied bytes

o_Error

INT

 

Possible error code

Actions

Action name

Description

CopyData

Used internally to copy data to/from internal CSDO clients.

Don't call directly.

StartTransfer

Used internally to start transfer.

Don't call directly.

Errors

Example code

CANopenSDOManager and CSDO instances array are initialized in MultiTool Creator code template.

 

 

CODESYS 2.3CODESYS 2.3

Definitions (included in code template):

 

G_CAN1_CSDOinstances: ARRAY[1..4] OF CANopenCSDO := [ (* CSDO instances *)

    (i_NodeID := 2, i_Enable := FALSE, i_Channel:=0),

    (i_NodeID := 3, i_Enable := FALSE, i_Channel:=0),

    (i_NodeID := 4, i_Enable := FALSE, i_Channel:=0),

    (i_NodeID := 5, i_Enable := FALSE, i_Channel:=0)];

 

 

Definitions:

 

CSDO:CANopenCSDOTransfer;

index1000hData:DWORD;

csdo_error: CANopenCSDOErrors;

csdo_ready: BOOL := FALSE;

 

 

Init (included in code template)

 

(* Init CANopen302 manager*)

CANopen302_SDOManager.Init(

    i_CanBusNbr:=0,

    i_NodeId:=1,

    i_CsdoArrayStart:= ADR(G_CAN1_CSDOinstances),

    i_CsdoArraySize:= 4

);

 

 

Code:

 

 

CSDO(

    i_Enable := TRUE,

    i_Channel := 0,

    i_NodeID := BYTE#2,

    i_Index := WORD#16#1000,

    i_SubIndex := BYTE#0,

    i_Data := ADR(index1000hData),

    i_Size := UDINT#4,

    i_Write := FALSE,

    i_Stop := FALSE,

    i_TimeOut := T#1S,

    i_DontChgByteOrd := FALSE,

    i_TimeOut_ReqResp := T#100MS,

    o_State => ,

    o_Ready => csdo_ready,

    o_AbortCode => ,

    o_Size => ,

    o_Error => csdo_error

);

 

IF csdo_ready THEN

    

    (* Errors and abort codes can be handled here *)

 

    CSDO(i_Enable:=FALSE);  (* For rising edge of i_Enable *)

END_IF

 

 

 

 

CODESYS 3.5CODESYS 3.5

Definitions (included in code template):

 

G_CAN1_Channel: EPEC_CANL2.Channel;

 

G_CAN1_CSDOinstances: ARRAY[1..4] OF EPEC_CSDO.CANopenCSDO := [ (* CSDO instances *)

    (i_NodeID := 2, i_Enable := FALSE, i_itfChannel := G_CAN1_Channel),

    (i_NodeID := 3, i_Enable := FALSE, i_itfChannel := G_CAN1_Channel),

    (i_NodeID := 4, i_Enable := FALSE, i_itfChannel := G_CAN1_Channel),

    (i_NodeID := 5, i_Enable := FALSE, i_itfChannel := G_CAN1_Channel)];

 

 

Definitions:

 

CSDO:EPEC_CSDO.CANopenCSDOTransfer;

index1000hData:DWORD;

csdo_error: EPEC_CSDO.CANopenCSDOErrors;

csdo_ready: BOOL := FALSE;

 

 

Init (included in code template)

 

(* Init CANopen302 manager*)

CANopen302_SDOManager.Init(

    i_itfChannel:=G_CAN1_Channel,

    i_NodeId:=1,

    i_CsdoArrayStart:= ADR(G_CAN1_CSDOinstances),

    i_CsdoArraySize:= 4

);

 

 

Code:

 

 

CSDO(

    i_Enable := TRUE,

    i_itfChannel:=G_CAN1_Channel,

    i_NodeID := BYTE#2,

    i_Index := WORD#16#1000,

    i_SubIndex := BYTE#0,

    i_pData := ADR(index1000hData),

    i_Size := UDINT#4,

    i_Write := FALSE,

    i_Stop := FALSE,

    i_TimeOut := T#1S,

    i_DontChgByteOrd := FALSE,

    i_TimeOut_ReqResp := T#100MS,

    o_State => ,

    o_Ready => csdo_ready,

    o_AbortCode => ,

    o_Size => ,

    o_Error => csdo_error

);

 

IF csdo_ready THEN

    

    (* Errors and abort codes can be handled here *)

 

    CSDO(i_Enable:=FALSE);  (* For rising edge of i_Enable *)

END_IF

 

 

See also

CANopen302_SDOManager

 

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

 

 

Source file Topic000420.htm

Last updated 19-Dec-2024