Coder Social home page Coder Social logo

Comments (2)

Ashenoneq avatar Ashenoneq commented on June 25, 2024

Hello! Our device has a high requirement for real-time performance and cannot be blocked for too long, so I have the same concern. Currently, my approach is to have the caller poll this function multiple times until it returns either success or failure before exiting.

extern SdoAbortCode writeSdoClientNoBlock(uint8_t nodeId, uint16_t index, \         
                                          uint8_t subIndex, uint8_t* data,\         
                                          size_t dataSize)                          
{                                                                                   
    static uint8_t  first_entry = 0;                                                
                                                                                    
    static bool_t bufferPartial = false;                                            
                                                                                    
    CO_SDO_return_t SDO_ret;                                                        
    CO_SDOclient_t* SDO_C = CO->SDOclient;                                          
                                                                                    
    if (first_entry == 0)                                                           
    {                                                                               
        first_entry = 1;                                                            
                                                                                    
        // setup client (this can be skipped, if remote device is the same)         
        SDO_ret = CO_SDOclient_setup(SDO_C,                                         
                                     CO_CAN_ID_SDO_CLI + nodeId,                    
                                     CO_CAN_ID_SDO_SRV + nodeId,                    
                                     nodeId);                                       
        if (SDO_ret != CO_SDO_RT_ok_communicationEnd)                               
        {                                                                           
            return USER_ERR_CODE;                                                   
        }                                                                           
                                                                                    
        // initiate download                                                        
        SDO_ret = CO_SDOclientDownloadInitiate(SDO_C, index, subIndex,              
                                               dataSize, 1000, false);              
        if (SDO_ret != CO_SDO_RT_ok_communicationEnd)                               
        {                                                                           
            return USER_ERR_CODE;                                                   
        }                                                                           
                                                                                    
        // fill data                                                                
        size_t nWritten = CO_SDOclientDownloadBufWrite(SDO_C, data, dataSize);      
        if (nWritten < dataSize)                                                    
        {                                                                           
            bufferPartial = true;                                                   
            // If SDO Fifo buffer is too small, data can be refilled in the loop.   
        }                                                                           
    }                                                                               
                                                                                    
    //download data                                                                 
    CO_SDO_abortCode_t abortCode = CO_SDO_AB_NONE;                                  
    uint32_t timeDifference_us = 1000;                                              
    SDO_ret = CO_SDOclientDownload(SDO_C,                                           
                                   timeDifference_us,                               
                                   false,                                           
                                   bufferPartial,                                   
                                   &abortCode,                                      
                                   NULL, NULL);                                     
                                                                                    
    if (SDO_ret == 0) //success                                                     
    {                                                                               
        first_entry = 0;                                                            
        bufferPartial = false;                                                      
        return REDEF_CO_SDO_AB_NONE;                                                
    }                                                                               
    else if (SDO_ret > 0)                                                           
    {                                                                               
        return SDO_NO_BLOCK_WAIT_CODE;//Self-defined return values                  
    }                                                                               
    else                                                                            
    {                                                                               
        first_entry = 0;                                                            
        bufferPartial = false;                                                      
        return (SdoAbortCode)abortCode;                                             
    }                                                                               
}

from canopennode.

CANopenNode avatar CANopenNode commented on June 25, 2024

SDO client is quite complex and has to be implemented properly and well integrated into OS. In CANopenLinux it works really fast, no delays, very reliable. See there and also CANopenDemo.

from canopennode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.