Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY

 

CANopenSDOClient (FB)

Description

SDO client reads or writes data from/to a SDO server.

 

User starts transfer by setting input parameters and enabling input i_Enable.

 

The function block checks if there is free CSDO channel to be used for transfer. If there is free channel, o_State is changed to CSDOReqTransferOn, otherwise o_State is changed to CSDOReqWaitChn. The function block stays in this state until it gets free CSDO channel, a timeout occurs, or user stops execution by setting input i_Stop TRUE.

 

If the function block gets a free channel, it starts the transfer, and o_State changes to CSDOReqTransferOn.

In case of timeout or stop o_State changes to CSDOReqIdle. A timeout is indicated with Timeout error.

 

A new transaction is possible to start only in idle mode, i.e. o_State is CSDOReqIdle.

 

Limitations

CANopenSDOManager program must be initialized properly before using CANopenSDOClient.

In MultiTool Creator code template initializations are done automatically.

 

The function block implements also SDO manager functionality to access SDO channels, so no predefined channels are required.

 

SDO block transfer is not supported.

 

Inputs

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_pDevice

POINTER TO Device

> 0

Pointer to device.

i_NodeID

BYTE

1 - 127

Node ID number of the SDO server control unit. Can be changed between requests.

i_Index

UINT

> 0

CANopen OD main index.

i_SubIndex

USINT

 

CANopen OD sub-index.

i_pData

POINTER TO INT

> 0

Pointer to data buffer for send/received data

i_Size

UDINT

 

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_TransferTimeOut

TIME

 

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

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. For example, STRING data is in same order despite of the endianness of the system.

i_MessageTimeOut

TIME

 

Time out for one SDO request-response pair.

 

Outputs

Output variable name

Data type

Range

Description

o_State

ENUM

CANopenCSDOTransferStates

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.

o_AbortCode

DWORD

 

Possible SDO abort code.

o_Size

DWORD

 

Number of copied bytes.

o_Error

ENUM

Errors

Possible error code.

 

Error diagnostic

Error code

Description

COBIDAlreadyRegistered

COB-ID is already registered.

CallbackBufferFull

Number of callback FBs exceeded G_MAX_NUMBER_OF_COBIDS.

InternalError

Low level library returned error.

InputError

Device pointer or data buffer pointer NULL, or OD index 0.

Timeout

CSDO aborted to timeout.

SDOAbortReceived

Abort received from SDO server.

NotInitialized

SDO manager not initialized, or could not reserve a channel.

NoError

No errors.

 

Example code

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

 

Code template:

Definitions (included in code template):

 

 

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))];

 

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

 

 

Init (included in code template):

 

 

EPEC_CANopen.CANopenSDOManager.Init(

    i_pDevice:=ADR(G_CANopen_CAN1.Device),

    i_NodeId:=G_CANopen_CAN1.Device.NodeID,

    i_pCsdoArrayStart:=ADR(G_CANopen_CAN1.CSDOS),

    i_CsdoArraySize:=127,

    o_Error=>G_CANopen_CAN1_VAR.CSDO_Error

);

 

Application:

Definitions:

 

CSDO:EPEC_CANopen.CANopenSDOClient;

deviceTypeData: DWORD;

csdo_ready: BOOL := FALSE;

csdo_error: EPEC_CANopen.Errors;

 

 

Code:

 

 

CSDO(

    i_Enable := TRUE,

    i_pDevice := ADR(G_CANopen_CAN1.Device),

    i_NodeID := BYTE#2,

    i_Index := UINT#16#1000,

    i_SubIndex := USINT#0,

    i_pData := ADR(deviceTypeData),

    i_Size := UDINT#4,

    i_Write := FALSE,

    i_Stop := FALSE,

    i_TransferTimeOut := T#1S,

    i_DontChgByteOrd := FALSE,

    i_MessageTimeOut := 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

 

 

 

 

Source file topic001028.htm

Last updated 13-Jun-2024