Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

CANopen SDO_Write4

stefno86
2019-01-29
2019-01-30
  • stefno86 - 2019-01-29

    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
    
     
  • alwoso - 2019-01-30

    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

     

Log in to post a comment.