CODESYS - the IEC 61131-3 automation software
https://forum.codesys.com/

CANopen SDO_Write4
https://forum.codesys.com/viewtopic.php?f=11&t=9486
Page 1 of 1

Author:  stefno86 [ Tue Jan 29, 2019 9:25 am ]
Post subject:  CANopen SDO_Write4

Hi all,
i'm trying to send a sdo to a slave by using the following code... The SDO is transmitted correcly and also the slave received it correcly and answered with the acknoalge (60 xx xx xx xx xx xx xx) but the SDO_Write4.CONFIRM never rise up...
Do you have an idea about this strange behaviour?

IF xEnable = FALSE THEN
xLastEnable := TRUE;
xEnable := TRUE;

wsdo_index := 16#1400; // SDO write 0x1400 SUB index 1 à 7F 02 00 80 (Receive PDO disabled
wsdo_subindex := 16#0001;

SDOWrite4.DATA[1] := 16#7F;
SDOWrite4.DATA[2] := 16#02;
SDOWrite4.DATA[3] := 16#00;
SDOWrite4.DATA[4] := 16#80;

SDOWrite4(
NETWORK:= CANbus.NetId + 1, //CODESYS NetId starts by 0 (the number entered into the CANbus configurator); CiA405 NETWORK by 1; That is the reason why we have to increment it here.
ENABLE:= xEnable,
TIMEOUT:= 50, //Timeout for SDO read in ms. Here: 0 ==> no timeout
//DEVICE:= CANopen_Device_1.NodeID, // NodeID of destination device
DEVICE:= 126, // NodeID of destination device
CHANNEL:= 1, //SDO channel which should be used. 0 means auto channeling ==> the next free channel will be used. It depends on the slave which settings are working here but 0 and channel 1 is always working.
INDEX:= wsdo_index, //object index which should be read
SUBINDEX:= wsdo_subindex //object sub index which should be read
);



ELSE
IF SDOWrite4.CONFIRM THEN
xEnable := FALSE;
SDOWrite4(Enable := xEnable);
ELSIF SDOWrite4.ERROR <> CiA405.CANOPEN_KERNEL_ERROR.CANOPEN_KERNEL_NO_ERROR THEN
//Error occured
xEnable := FALSE;
SDOWrite4(Enable := xEnable);

END_IF

xLastEnable := xEnable;

END_IF

Author:  alwoso [ Wed Jan 30, 2019 3:55 pm ]
Post subject:  Re: CANopen SDO_Write4

Hi Stefno86!

I think, you should call the function block "SDOWRITE4" cyclical, i.e. outside of the IF ... ENDIF query. If I take your code, the easiest way is to move the call below the END_IF:

IF xEnable = FALSE THEN
xLastEnable := TRUE;
xEnable := TRUE;

wsdo_index := 16#1400; // SDO write 0x1400 SUB index 1 à 7F 02 00 80 (Receive PDO disabled
wsdo_subindex := 16#0001;

SDOWrite4.DATA[1] := 16#7F;
SDOWrite4.DATA[2] := 16#02;
SDOWrite4.DATA[3] := 16#00;
SDOWrite4.DATA[4] := 16#80;

ELSE
IF SDOWrite4.CONFIRM THEN
xEnable := FALSE;
// don't call here !!!! SDOWrite4(Enable := xEnable);
ELSIF SDOWrite4.ERROR <> CiA405.CANOPEN_KERNEL_ERROR.CANOPEN_KERNEL_NO_ERROR THEN
//Error occured
xEnable := FALSE;
// don't call here !!!! SDOWrite4(Enable := xEnable);

END_IF

xLastEnable := xEnable;

END_IF

SDOWrite4(
NETWORK:= CANbus.NetId + 1, //CODESYS NetId starts by 0 (the number entered into the CANbus configurator); CiA405 NETWORK by 1; That is the reason why we have to increment it here.
ENABLE:= xEnable,
TIMEOUT:= 50, //Timeout for SDO read in ms. Here: 0 ==> no timeout
//DEVICE:= CANopen_Device_1.NodeID, // NodeID of destination device
DEVICE:= 126, // NodeID of destination device
CHANNEL:= 1, //SDO channel which should be used. 0 means auto channeling ==> the next free channel will be used. It depends on the slave which settings are working here but 0 and channel 1 is always working.
INDEX:= wsdo_index, //object index which should be read
SUBINDEX:= wsdo_subindex //object sub index which should be read
);

Just try, and good luck!

Alfred

Page 1 of 1 All times are UTC+01:00
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/