### Basic cocomm Usage Examples Source: https://canopennode.github.io/CANopenLinux/md_cocomm_2README.html Demonstrates basic commands for getting help, reading, writing, saving configuration, and resetting a CANopen device. Node ID and object dictionary parameters are specified. ```bash cocomm --help ``` ```bash cocomm "help" ``` ```bash cocomm "help datatype" ``` ```bash cocomm "help lss" ``` ```bash cocomm "1 read 0x1017 0 u16" ``` ```bash cocomm "1 write 0x1017 0 u16 1000" ``` ```bash cocomm "1 w 0x1010 1 vs save" ``` ```bash cocomm "1 reset node" ``` -------------------------------- ### Install CANopenLinux Application Source: https://canopennode.github.io/CANopenLinux/index.html Install the compiled canopend application by copying it to the /usr/bin/ directory. ```bash sudo make install ``` -------------------------------- ### Compile and Install cocomm Source: https://canopennode.github.io/CANopenLinux/md_cocomm_2README.html Compile the cocomm utility and install it to the /usr/bin/ directory. Navigate to the cocomm directory before running make. ```bash cd cocomm make sudo make install ``` -------------------------------- ### Initialize CANopen Application Source: https://canopennode.github.io/CANopenPIC/CO__application_8h_source.html Application interface for starting CANopen. Similar to Arduino's setup, extended for CANopen and a real-time thread. It configures the bit rate, node ID, and error information. ```c CO_ReturnError_t app_programStart(uint16_t *bitRate, uint8_t *nodeId, uint32_t *errInfo) ``` -------------------------------- ### CANopen NMT and Storage Examples Source: https://canopennode.github.io/md_tutorial_2README.html This section provides examples of CANopen NMT commands and non-volatile storage operations. It demonstrates how to reset devices, load and save configurations, and observe the effects on communication. ```bash cocomm "4 reset communication" cocomm "4 start" cocomm "0 reset node" ``` ```bash cocomm "1 w 0x1011 1 vs load" cocomm "4 w 0x1011 1 vs load" cocomm "0 reset node" ``` ```bash cocomm "1 write 0x1017 0 u16 1000" cocomm "4 write 0x1017 0 u16 1000" cocomm "0 reset node" ``` ```bash cocomm "1 write 0x1017 0 u16 1000" cocomm "4 write 0x1017 0 u16 1000" cocomm "1 w 0x1010 1 vs save" cocomm "4 w 0x1010 1 vs save" cocomm "0 reset node" ``` -------------------------------- ### Install CAN Utilities Source: https://canopennode.github.io/CANopenLinux/index.html Install the SocketCAN userspace utilities and tools for interacting with CAN devices on Linux. ```bash sudo apt-get install can-utils ``` -------------------------------- ### app_programStart Source: https://canopennode.github.io/CANopenPIC/globals_func.html Starts the program execution. ```APIDOC ## app_programStart ### Description Starts the program execution. This function should be called to begin the main program loop or a specific task within the application. ### Signature `void app_programStart(void);` ### File CO_application.h ``` -------------------------------- ### Install Documentation Generation Tools and Update Docs Source: https://canopennode.github.io/ Install the necessary tools (doxygen, graphviz, pdf2svg) for generating HTML documentation and then execute the script to update the documentation files. This process is required for generating the documentation for CANopenNode, CANopenLinux, and CANopenDemo. ```bash sudo apt install doxygen graphviz pdf2svg ./update_docs.sh ``` -------------------------------- ### Install and Run Candump Source: https://canopennode.github.io/md_tutorial_2README.html Installs the 'can-utils' package and runs 'candump' to display raw CAN messages on the 'can0' interface. This is useful for monitoring network traffic. ```bash sudo apt-get install can-utils candump -td can0 ``` -------------------------------- ### CO_SDOclientDownloadInitiate Source: https://canopennode.github.io/CANopenNode/group__CO__SDOclient.html Starts the SDO download process by sending the initial command to the server. ```APIDOC ## CO_SDOclientDownloadInitiate ### Description Initiate SDO download communication. ### Signature ```c CO_SDO_return_t CO_SDOclientDownloadInitiate (CO_SDOclient_t *SDO_C, uint16_t index, uint8_t subIndex, size_t sizeIndicated, uint16_t SDOtimeoutTime_ms, bool_t blockEnable) ``` ### Parameters * **SDO_C**: Pointer to the SDO client object. * **index**: The index of the object to download. * **subIndex**: The sub-index of the object to download. * **sizeIndicated**: The total size of the data to be downloaded. * **SDOtimeoutTime_ms**: The timeout in milliseconds for the SDO transfer. * **blockEnable**: Enable or disable block transfer mode. ``` -------------------------------- ### app_programStart Source: https://canopennode.github.io/CANopenADI/globals_func.html Starts a programming operation. ```APIDOC ## app_programStart() ### Description Starts a programming operation. ### Method Function Call ### Parameters None ### Response None specified ``` -------------------------------- ### CO_SDOclientUploadInitiate Source: https://canopennode.github.io/CANopenNode/group__CO__SDOclient.html Starts the SDO upload process by sending the initial command to the server. ```APIDOC ## CO_SDOclientUploadInitiate ### Description Initiate SDO upload communication. ### Signature ```c CO_SDO_return_t CO_SDOclientUploadInitiate (CO_SDOclient_t *SDO_C, uint16_t index, uint8_t subIndex, uint16_t SDOtimeoutTime_ms, bool_t blockEnable) ``` ### Parameters * **SDO_C**: Pointer to the SDO client object. * **index**: The index of the object to upload. * **subIndex**: The sub-index of the object to upload. * **SDOtimeoutTime_ms**: The timeout in milliseconds for the SDO transfer. * **blockEnable**: Enable or disable block transfer mode. ``` -------------------------------- ### CO_SDOclientDownloadInitiate Source: https://canopennode.github.io/CANopenNode/CO__SDOclient_8h.html Starts an SDO download transfer to the specified index and sub-index. ```APIDOC ## CO_SDOclientDownloadInitiate ### Description Initiate SDO download communication. ### Signature CO_SDO_return_t CO_SDOclientDownloadInitiate(CO_SDOclient_t *SDO_C, uint16_t index, uint8_t subIndex, size_t sizeIndicated, uint16_t SDOtimeoutTime_ms, bool_t blockEnable) ### Parameters * **SDO_C**: Pointer to the SDO client object. * **index**: Index of the OD entry to download. * **subIndex**: Sub-index of the OD entry to download. * **sizeIndicated**: The total size of the data to be downloaded. * **SDOtimeoutTime_ms**: Timeout for the SDO transfer in milliseconds. * **blockEnable**: Enable or disable block transfer mode. ### Returns * CO_SDO_return_t: Indicates the status of the download initiation. ``` -------------------------------- ### CO_SDOclientUploadInitiate Source: https://canopennode.github.io/CANopenNode/CO__SDOclient_8h.html Starts an SDO upload transfer from the specified index and sub-index. ```APIDOC ## CO_SDOclientUploadInitiate ### Description Initiate SDO upload communication. ### Signature CO_SDO_return_t CO_SDOclientUploadInitiate(CO_SDOclient_t *SDO_C, uint16_t index, uint8_t subIndex, uint16_t SDOtimeoutTime_ms, bool_t blockEnable) ### Parameters * **SDO_C**: Pointer to the SDO client object. * **index**: Index of the OD entry to upload. * **subIndex**: Sub-index of the OD entry to upload. * **SDOtimeoutTime_ms**: Timeout for the SDO transfer in milliseconds. * **blockEnable**: Enable or disable block transfer mode. ### Returns * CO_SDO_return_t: Indicates the status of the upload initiation. ``` -------------------------------- ### app_programRt Source: https://canopennode.github.io/CANopenPIC/globals.html Starts a real-time programming operation. ```APIDOC ## app_programRt ### Description Initiates a real-time programming operation on the device. ### Signature `uint32_t app_programRt(uint16_t device_index, uint32_t program_index, uint8_t *data, uint32_t data_len); ` ### File CO_application.h ``` -------------------------------- ### CO_SDOserver_initCallbackPre Source: https://canopennode.github.io/CANopenNode/group__CO__SDOserver.html Initializes an optional callback function that should immediately start processing of CO_SDOserver_process(). ```APIDOC ## CO_SDOserver_initCallbackPre() ### Description Initializes the optional callback function, which should immediately start processing of CO_SDOserver_process() function. The callback is called after an SDO server message is received from the CAN bus or when a new call without delay is necessary (e.g., during SDO block transfer). ### Parameters - **SDO** (*CO_SDOserver_t* *) - Pointer to the SDO server object. - **object** (*void* *) - Pointer to the object that will be passed to pFunctSignalPre(). Can be NULL. - **pFunctSignalPre** (*void(*)(void *object)*) - Pointer to the callback function. Not called if NULL. ### Returns void ``` -------------------------------- ### app_programStart Source: https://canopennode.github.io/CANopenADI/CO__application_8h_source.html Initializes the CANopen application and communication stack. This function is similar to Arduino's setup() but extended for CANopen and a real-time thread. ```APIDOC ## app_programStart ### Description Initializes the CANopen application and communication stack. This function is similar to Arduino's setup() but extended for CANopen and a real-time thread. ### Signature CO_ReturnError_t app_programStart(uint16_t *bitRate, uint8_t *nodeId, uint32_t *errInfo) ### Parameters * **bitRate** (uint16_t *) - Pointer to store the CAN bit rate. * **nodeId** (uint8_t *) - Pointer to store the CANopen Node ID. * **errInfo** (uint32_t *) - Pointer to store error information. ### Return Value Returns CO_ReturnError_t indicating success or failure. ``` -------------------------------- ### Get Eeprom Address Source: https://canopennode.github.io/CANopenNode/group__CO__storage__eeprom.html Gets a free address within the Eeprom for data storage. This is a target system specific function. ```APIDOC ## CO_eeprom_getAddr ### Description Get free address inside eeprom, target system specific function. ### Signature ```c size_t CO_eeprom_getAddr(void *storageModule, bool_t isAuto, size_t len, bool_t *overflow) ``` ### Parameters * `storageModule` (void *) - Pointer to the storage module specific data. * `isAuto` (bool_t) - Flag indicating if this is for auto storage. * `len` (size_t) - The length of data to be stored. * `overflow` (bool_t *) - Pointer to a flag indicating if an overflow occurred. ``` -------------------------------- ### Get Eeprom Block CRC Source: https://canopennode.github.io/CANopenNode/group__CO__storage__eeprom.html Gets the CRC checksum of a block of data stored in the Eeprom. This is a target system specific function. ```APIDOC ## CO_eeprom_getCrcBlock ### Description Get CRC checksum of the block of data stored in the eeprom, target system specific function. ### Signature ```c uint16_t CO_eeprom_getCrcBlock(void *storageModule, size_t eepromAddr, size_t len) ``` ### Parameters * `storageModule` (void *) - Pointer to the storage module specific data. * `eepromAddr` (size_t) - The starting address of the block in the Eeprom. * `len` (size_t) - The length of the block. ``` -------------------------------- ### Run CANopen Linux Demo Source: https://canopennode.github.io/md_demo_2README.html Instructions to compile and run the CANopen Linux demo device. Ensure you are in the 'demo' directory and specify the CAN interface and node ID. ```bash cd demo make ./demoLinuxDevice can0 -i 4 ``` -------------------------------- ### Application Program Start Function Declaration Source: https://canopennode.github.io/CANopenADI/CO__application_8h_source.html Declares the function to start the CANopen application. It takes pointers to bit rate, node ID, and error information. ```c CO_ReturnError_t app_programStart(uint16_t *bitRate, uint8_t *nodeId, uint32_t *errInfo); ``` -------------------------------- ### CAN Bit Rate Initializers for FCY = 70MHz (Example) Source: https://canopennode.github.io/CANopenPIC/PIC24__dsPIC33_2CO__driver__target_8h_source.html Example of CAN bit rate initializers for a 70MHz FCY clock. This specific set of values is used for configuring the CAN module's timing parameters. ```c {1, 64, TQ_x_25, 0}, {1, 64, TQ_x_25, 20}, {1, 35, TQ_x_20, 50}, {1, 14, TQ_x_20, 125}, {1, 7, TQ_x_20, 250}, {1, 5, TQ_x_14, 500}, {1, 3, TQ_x_15, 0}, {1, 2, TQ_x_17, 0} ``` -------------------------------- ### domainDemo_init() Source: https://canopennode.github.io/globals_func.html Initializes the domain demo functionality. ```APIDOC ## domainDemo_init() ### Description Initializes the domain demo functionality. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Source File domainDemo.c, domainDemo.h ``` -------------------------------- ### CAN Bit Rate Initializers for FCY = 64MHz (Example) Source: https://canopennode.github.io/CANopenPIC/PIC24__dsPIC33_2CO__driver__target_8h_source.html Example of CAN bit rate initializers for a 64MHz FCY clock. This specific set of values is used for configuring the CAN module's timing parameters. ```c {1, 64, TQ_x_25, 0}, {1, 64, TQ_x_25, 20}, {1, 40, TQ_x_16, 50}, {1, 16, TQ_x_16, 125}, {1, 8, TQ_x_16, 250}, {1, 4, TQ_x_16, 500}, {1, 2, TQ_x_20, 800}, {1, 2, TQ_x_16, 1000} ``` -------------------------------- ### Setup USB/PCI CAN Interface Source: https://canopennode.github.io/CANopenLinux/index.html Set up a physical CAN interface like USB or PCI. Ensure your interface is supported by the Linux kernel. ```bash sudo ip link set up can0 type can bitrate 250000 ``` -------------------------------- ### CO_GTWA_init Source: https://canopennode.github.io/CANopenNode/group__CO__CANopen__309__3.html Initializes the Gateway-ASCII object with necessary parameters for SDO client, NMT, LSS master, and LEDs. ```APIDOC ## CO_GTWA_init() ### Description Initialize Gateway-ascii object. ### Parameters - **gtwa** (CO_GTWA_t *) - This object will be initialized - **SDO_C** (CO_SDOclient_t *) - SDO client object - **SDOclientTimeoutTime_ms** (uint16_t) - Default timeout in milliseconds, 500 typically - **SDOclientBlockTransfer** (bool_t) - If true, block transfer will be set by default - **NMT** (CO_NMT_t *) - NMT object - **LSSmaster** (CO_LSSmaster_t *) - LSS master object - **LEDs** (CO_LEDs_t *) - LEDs object - **dummy** (uint8_t) - dummy argument, set to 0 ### Returns - CO_ReturnError_t: CO_ERROR_NO or CO_ERROR_ILLEGAL_ARGUMENT ``` -------------------------------- ### CAN Bit Rate Initializers for FCY = 56MHz (Example) Source: https://canopennode.github.io/CANopenPIC/PIC24__dsPIC33_2CO__driver__target_8h_source.html Example of CAN bit rate initializers for a 56MHz FCY clock. This specific set of values is used for configuring the CAN module's timing parameters. ```c {1, 61, TQ_x_23, 0}, {1, 61, TQ_x_23, 20}, {1, 35, TQ_x_16, 50}, {1, 14, TQ_x_16, 125}, {1, 7, TQ_x_16, 250}, {1, 4, TQ_x_14, 500}, {1, 5, TQ_x_7 , 800}, {1, 2, TQ_x_14, 1000} ``` -------------------------------- ### CAN Bit Rate Initializers for FCY = 48MHz (Example) Source: https://canopennode.github.io/CANopenPIC/PIC24__dsPIC33_2CO__driver__target_8h_source.html Example of CAN bit rate initializers for a 48MHz FCY clock. This specific set of values is used for configuring the CAN module's timing parameters. ```c {1, 63, TQ_x_19, 0}, {1, 63, TQ_x_19, 20}, {1, 30, TQ_x_16, 50}, {1, 12, TQ_x_16, 125}, {1, 6, TQ_x_16, 250}, {1, 3, TQ_x_16, 500}, {1, 2, TQ_x_15, 800}, {1, 2, TQ_x_12, 1000} ``` -------------------------------- ### CAN Bit Rate Initializers for FCY = 32MHz (Example) Source: https://canopennode.github.io/CANopenPIC/PIC24__dsPIC33_2CO__driver__target_8h_source.html Example of CAN bit rate initializers for a 32MHz FCY clock. This specific set of values is used for configuring the CAN module's timing parameters. ```c {1, 64, TQ_x_25, 10}, {1, 50, TQ_x_16, 20}, {1, 20, TQ_x_16, 50}, {1, 8, TQ_x_16, 125}, {1, 4, TQ_x_16, 250}, {1, 2, TQ_x_16, 500}, {1, 2, TQ_x_10, 800}, {1, 1, TQ_x_16, 1000} ``` -------------------------------- ### Prepare and Upload Data for Writing Source: https://canopennode.github.io/md_tutorial_2SDO.html Create a file (`file_write`) ten times larger than the read data by concatenating `file_read`. Then, upload this data to the demo device using `cocomm` with the write command. The data must be a correct sequence of numbers (0-255) for the demo device to accept it. ```bash for n in {1..10}; do cat file_read >> file_write; done pv file_write | base64 -w0 | cocomm -i "w 0x2122 0 d" ``` -------------------------------- ### CAN Bit Rate Initializers for FCY = 24MHz (Example) Source: https://canopennode.github.io/CANopenPIC/PIC24__dsPIC33_2CO__driver__target_8h_source.html Example of CAN bit rate initializers for a 24MHz FCY clock. This specific set of values is used for configuring the CAN module's timing parameters. ```c {1, 63, TQ_x_19, 10}, {1, 40, TQ_x_15, 20}, {1, 15, TQ_x_16, 50}, {1, 6, TQ_x_16, 125}, {1, 3, TQ_x_16, 250}, {1, 2, TQ_x_12, 500}, {1, 1, TQ_x_15, 800}, {1, 1, TQ_x_12, 1000} ``` -------------------------------- ### CO_SDOclientDownloadInitiate() Source: https://canopennode.github.io/CANopenNode/group__CO__SDOclient.html Initiates an SDO download communication to a remote server. This is a non-blocking function. ```APIDOC ## CO_SDOclientDownloadInitiate() ### Description Initiates SDO download communication with the server specified in the CO_SDOclient_init() function. Data will be written to the remote node. This function is non-blocking. ### Parameters - **SDO_C** (CO_SDOclient_t *) - This object. - **index** (uint16_t) - Index of the object in the object dictionary of the remote node. - **subIndex** (uint8_t) - Subindex of the object in the object dictionary of the remote node. - **sizeIndicated** (size_t) - Optionally indicates the size of data to be downloaded. Actual data are written with one or multiple CO_SDOclientDownloadBufWrite() calls. If sizeIndicated is different from 0, the total number of bytes written by CO_SDOclientDownloadBufWrite() will be compared against sizeIndicated, and this info will be passed to the server for verification. In case of mismatch, an SDO abort message will be generated. If sizeIndicated is 0, the actual data size will not be verified. - **SDOtimeoutTime_ms** (uint16_t) - Timeout time for SDO communication in milliseconds. - **blockEnable** (bool_t) - Enables or disables block transfer initiation. ### Returns - CO_SDO_return_t: Return status of the operation. ``` -------------------------------- ### CAN Bit Rate Initializers for FCY = 16MHz (Example) Source: https://canopennode.github.io/CANopenPIC/PIC24__dsPIC33_2CO__driver__target_8h_source.html Example of CAN bit rate initializers for a 16MHz FCY clock. This specific set of values is used for configuring the CAN module's timing parameters. ```c {1, 50, TQ_x_16, 10}, {1, 25, TQ_x_16, 20}, {1, 10, TQ_x_16, 50}, {1, 4, TQ_x_16, 125}, {1, 2, TQ_x_16, 250}, {1, 1, TQ_x_16, 500}, {1, 1, TQ_x_10, 800}, {1, 1, TQ_x_8 , 1000} ``` -------------------------------- ### CAN Bit Rate Initializers for FCY = 12MHz (Example) Source: https://canopennode.github.io/CANopenPIC/PIC24__dsPIC33_2CO__driver__target_8h_source.html Example of CAN bit rate initializers for a 12MHz FCY clock. This specific set of values is used for configuring the CAN module's timing parameters. ```c {2, 63, TQ_x_19, 10}, {1, 20, TQ_x_15, 20}, {2, 15, TQ_x_16, 50}, {1, 3, TQ_x_16, 125}, {2, 3, TQ_x_16, 250}, {1, 1, TQ_x_12, 500}, {2, 1, TQ_x_15, 800}, {2, 1, TQ_x_12, 1000} ``` -------------------------------- ### CO_SDOclient_setup Source: https://canopennode.github.io/CANopenNode/group__CO__SDOclient.html Configures the SDO client with the necessary CAN IDs and the node ID of the SDO server. ```APIDOC ## CO_SDOclient_setup ### Description Setup SDO client object. ### Signature ```c CO_SDO_return_t CO_SDOclient_setup (CO_SDOclient_t *SDO_C, uint32_t COB_IDClientToServer, uint32_t COB_IDServerToClient, uint8_t nodeIDOfTheSDOServer) ``` ### Parameters * **SDO_C**: Pointer to the SDO client object. * **COB_IDClientToServer**: The COB-ID for client-to-server SDO messages. * **COB_IDServerToClient**: The COB-ID for server-to-client SDO messages. * **nodeIDOfTheSDOServer**: The node ID of the SDO server. ``` -------------------------------- ### CAN Bit Rate Initializers for FCY = 10MHz (Example) Source: https://canopennode.github.io/CANopenPIC/PIC24__dsPIC33_2CO__driver__target_8h_source.html Example of CAN bit rate initializers for a 10MHz FCY clock. This specific set of values is used for configuring the CAN module's timing parameters. ```c {1, 25, TQ_x_20, 10}, {2, 25, TQ_x_20, 20}, {1, 5, TQ_x_20, 50}, {2, 5, TQ_x_16, 125}, {1, 1, TQ_x_20, 250}, {2, 1, TQ_x_20, 500}, {2, 1, TQ_x_20, 0}, {2, 1, TQ_x_10, 1000} ``` -------------------------------- ### CO_SDOclient_setup Source: https://canopennode.github.io/CANopenNode/CO__SDOclient_8h.html Configures the SDO client object with communication parameters. ```APIDOC ## CO_SDOclient_setup ### Description Setup SDO client object. ### Signature CO_SDO_return_t CO_SDOclient_setup(CO_SDOclient_t *SDO_C, uint32_t COB_IDClientToServer, uint32_t COB_IDServerToClient, uint8_t nodeIDOfTheSDOServer) ### Parameters * **SDO_C**: Pointer to the SDO client object. * **COB_IDClientToServer**: COB ID for client-to-server communication. * **COB_IDServerToClient**: COB ID for server-to-client communication. * **nodeIDOfTheSDOServer**: Node ID of the remote SDO server. ### Returns * CO_SDO_return_t: Indicates the status of the setup operation. ``` -------------------------------- ### CAN Bit Rate Initializers for FCY = 8MHz (Example) Source: https://canopennode.github.io/CANopenPIC/PIC24__dsPIC33_2CO__driver__target_8h_source.html Example of CAN bit rate initializers for an 8MHz FCY clock. This specific set of values is used for configuring the CAN module's timing parameters. ```c {1, 25, TQ_x_16, 10}, {2, 25, TQ_x_16, 20}, {1, 5, TQ_x_16, 50}, {1, 2, TQ_x_16, 125}, {1, 1, TQ_x_16, 250}, {2, 1, TQ_x_16, 500}, {2, 1, TQ_x_10, 800}, {2, 1, TQ_x_8 , 1000} ``` -------------------------------- ### CAN Bit Rate Initializers for FCY = 6MHz (Example) Source: https://canopennode.github.io/CANopenPIC/PIC24__dsPIC33_2CO__driver__target_8h_source.html Example of CAN bit rate initializers for a 6MHz FCY clock. This specific set of values is used for configuring the CAN module's timing parameters. ```c {1, 20, TQ_x_15, 10}, {1, 10, TQ_x_15, 20}, {1, 4, TQ_x_15, 50}, {2, 3, TQ_x_16, 125}, {1, 1, TQ_x_12, 250}, {2, 1, TQ_x_12, 500}, {2, 1, TQ_x_12, 0}, {2, 1, TQ_x_6 , 1000} ``` -------------------------------- ### CAN Bit Rate Initializers for FCY = 5MHz (Example) Source: https://canopennode.github.io/CANopenPIC/PIC24__dsPIC33_2CO__driver__target_8h_source.html Example of CAN bit rate initializers for a 5MHz FCY clock. This specific set of values is used for configuring the CAN module's timing parameters. ```c {2, 25, TQ_x_20, 10}, {1, 5, TQ_x_25, 20}, {2, 5, TQ_x_20, 50}, {1, 1, TQ_x_20, 125}, {2, 1, TQ_x_20, 250}, {2, 1, TQ_x_10, 500}, {2, 1, TQ_x_10, 0}, {2, 1, TQ_x_5 , 500} ``` -------------------------------- ### app_programStart Source: https://canopennode.github.io/CANopenLinux/CO__application_8h_source.html Initializes the CANopen application. This function is called once on program startup, after the Object Dictionary is initialized and before CAN communication begins. It configures the bit rate and Node ID. ```APIDOC ## app_programStart ### Description Function is called once on the program startup, after Object dictionary initialization and before CAN communication. ### Signature CO_ReturnError_t app_programStart(uint16_t* bitRate, uint8_t* nodeId, uint32_t* errInfo) ### Parameters * **bitRate**: Pointer to a uint16_t to store the CAN bit rate. * **nodeId**: Pointer to a uint8_t to store the CANopen Node ID. * **errInfo**: Pointer to a uint32_t for error information. ### Return Value Returns CO_ReturnError_t indicating success or failure. ``` -------------------------------- ### CAN Bit Rate Initializers for FCY = 20MHz (Example) Source: https://canopennode.github.io/CANopenPIC/PIC24__dsPIC33_2CO__driver__target_8h_source.html Example of CAN bit rate initializers for a 20MHz FCY clock. This specific set of values is used for configuring the CAN module's timing parameters. ```c {1, 50, TQ_x_20, 10}, {1, 50, TQ_x_20, 20}, {1, 25, TQ_x_16, 50}, {1, 10, TQ_x_16, 125}, {1, 5, TQ_x_16, 250}, {1, 2, TQ_x_20, 500}, {1, 1, TQ_x_25, 800}, {1, 1, TQ_x_20, 1000} ``` -------------------------------- ### SDO Client Setup (C) Source: https://canopennode.github.io/CANopenNode/group__CO__SDOclient.html Sets up the SDO client object with CAN IDs for communication and the node ID of the SDO server. This function should be called before initiating SDO transfers. ```c CO_SDO_return_t CO_SDOclient_setup(CO_SDOclient_t *SDO_C, uint32_t COB_IDClientToServer, uint32_t COB_IDServerToClient, uint8_t nodeIDOfTheSDOServer) ``` -------------------------------- ### CO_SDOclient_setup() Source: https://canopennode.github.io/CANopenNode/group__CO__SDOclient.html Sets up the SDO client object with communication parameters. This function can be called before new SDO communication and is also invoked internally by CO_SDOclient_init(). ```APIDOC ## CO_SDOclient_setup() ### Description Sets up the SDO client object with communication parameters. This function can be called before new SDO communication and is also invoked internally by CO_SDOclient_init(). If the parameters are the same as before, the CAN bus is not reconfigured. ### Parameters - **SDO_C** (CO_SDOclient_t *) - This object. - **COB_IDClientToServer** (uint32_t) - COB-ID for client-to-server communication. - **COB_IDServerToClient** (uint32_t) - COB-ID for server-to-client communication. - **nodeIDOfTheSDOServer** (uint8_t) - Node-ID of the SDO server. If it is the same as the node-ID of this node, data will be exchanged without CAN communication. ### Returns - CO_SDO_return_t: CO_SDO_RT_ok_communicationEnd or CO_SDO_RT_wrongArguments. ``` -------------------------------- ### CO_SDOserver_init Source: https://canopennode.github.io/CANopenNode/CO__SDOserver_8h.html Initializes the SDO server object with the provided parameters. ```APIDOC ## CO_SDOserver_init ### Description Initializes the SDO server object. ### Parameters - **SDO** (*CO_SDOserver_t* *) - Pointer to the SDO server object. - **OD** (*OD_t* *) - Pointer to the Object Dictionary. - **OD_1200_SDOsrvPar** (*OD_entry_t* *) - Pointer to the OD entry for SDO server parameters. - **nodeId** (*uint8_t*) - The CANopen node ID. - **SDOtimeoutTime_ms** (*uint16_t*) - Timeout for SDO communication in milliseconds. - **CANdevRx** (*CO_CANmodule_t* *) - Pointer to the CAN module for receiving. - **CANdevRxIdx** (*uint16_t*) - Index of the CAN receive object. - **CANdevTx** (*CO_CANmodule_t* *) - Pointer to the CAN module for transmitting. - **CANdevTxIdx** (*uint16_t*) - Index of the CAN transmit object. - **errInfo** (*uint32_t* *) - Pointer to a variable for error information. ### Returns - **CO_ReturnError_t** - Indicates the success or failure of the initialization. ``` -------------------------------- ### OD_get_value Source: https://canopennode.github.io/CANopenNode/CO__ODinterface_8h.html Gets a variable from the Object Dictionary. ```APIDOC ## OD_get_value ### Description Get variable from Object Dictionary. ### Signature ODR_t OD_get_value (const OD_entry_t *entry, uint8_t subIndex, void *val, OD_size_t len, bool_t odOrig) ``` -------------------------------- ### CO_CANopenInit Source: https://canopennode.github.io/CANopenNode/CANopen_8h_source.html Initializes the CANopen communication stack. ```APIDOC ## CO_CANopenInit ### Description Initializes the CANopen communication stack. This function sets up the core CANopen services like NMT, Error Control, SDO, and Heartbeat. ### Signature ```c CO_ReturnError_t CO_CANopenInit(CO_t* co, CO_NMT_t* NMT, CO_EM_t* em, OD_t* od, OD_entry_t* OD_statusBits, uint16_t NMTcontrol, uint16_t firstHBTime_ms, uint16_t SDOserverTimeoutTime_ms, uint16_t SDOclientTimeoutTime_ms, bool_t SDOclientBlockTransfer, uint8_t nodeId, uint32_t* errInfo); ``` ### Parameters * `co` (CO_t*): Pointer to the CANopen object. * `NMT` (CO_NMT_t*): Pointer to the NMT service object. * `em` (CO_EM_t*): Pointer to the Error Management object. * `od` (OD_t*): Pointer to the Object Dictionary. * `OD_statusBits` (OD_entry_t*): Pointer to the OD entry for status bits. * `NMTcontrol` (uint16_t): NMT control bits. * `firstHBTime_ms` (uint16_t): The first heartbeat time in milliseconds. * `SDOserverTimeoutTime_ms` (uint16_t): Timeout for SDO server transfers in milliseconds. * `SDOclientTimeoutTime_ms` (uint16_t): Timeout for SDO client transfers in milliseconds. * `SDOclientBlockTransfer` (bool_t): Enable or disable SDO client block transfer. * `nodeId` (uint8_t): The Node ID of this CANopen device. * `errInfo` (uint32_t*): Pointer to a variable for error information. ### Returns `CO_ReturnError_t`: Indicates the success or failure of the initialization. ``` -------------------------------- ### CO_storageEeprom_init Source: https://canopennode.github.io/CANopenNode/group__CO__storage__eeprom.html Initializes the EEPROM storage object. This function should be called after program startup and before CO_CANopenInit(). It sets up the storage object, OD extensions for parameter storage and restoration, reads data from the EEPROM, verifies it, and writes it to specified addresses. ```APIDOC ## CO_storageEeprom_init() ### Description Initializes data storage object (block device (eeprom) specific). This function should be called by application after the program startup, before CO_CANopenInit(). This function initializes storage object, OD extensions on objects 1010 and 1011, reads data from file, verifies them and writes data to addresses specified inside entries. This function internally calls CO_storage_init(). ### Parameters - **storage** (*CO_storage_t*): This object will be initialized. It must be defined by application and must exist permanently. - **CANmodule** (*CO_CANmodule_t*): CAN device, for optional usage. - **storageModule** (*void*): Pointer to storage module passed to CO_eeprom functions. - **OD_1010_StoreParameters** (*OD_entry_t*): OD entry for 0x1010 - "Store parameters". Entry is optional, may be NULL. - **OD_1011_RestoreDefaultParam** (*OD_entry_t*): OD entry for 0x1011 - "Restore default parameters". Entry is optional, may be NULL. - **entries** (*CO_storage_entry_t*): Pointer to array of storage entries, see CO_storage_init. - **entriesCount** (*uint8_t*): Count of storage entries, must not be larger than CO_CONFIG_STORAGE_MAX_ENTRIES_COUNT. - **storageInitError** (*uint32_t*): [out] If function returns CO_ERROR_DATA_CORRUPT, then this variable contains a bit mask from subIndexOD values, where data was not properly initialized. If other error, then this variable contains index or erroneous entry. If there is hardware error like missing eeprom, then storageInitError is 0xFFFFFFFF and function returns CO_ERROR_DATA_CORRUPT. ### Returns CO_ERROR_NO, CO_ERROR_DATA_CORRUPT if data can not be initialized, CO_ERROR_ILLEGAL_ARGUMENT or CO_ERROR_OUT_OF_MEMORY. ``` -------------------------------- ### Heartbeat Consumer Configuration Example Source: https://canopennode.github.io/CANopenNode/group__CO__STACK__CONFIG__NMT__HB.html An example of configuring the Heartbeat consumer with multiple flags, including enabling the consumer, callback preprocessing, timer next calculation, and dynamic OD configuration. Note that CO_CONFIG_HB_CONS_CALLBACK_CHANGE and CO_CONFIG_HB_CONS_CALLBACK_MULTI cannot be used together. ```c (CO_CONFIG_HB_CONS_ENABLE | CO_CONFIG_GLOBAL_FLAG_CALLBACK_PRE | CO_CONFIG_GLOBAL_FLAG_TIMERNEXT \ | CO_CONFIG_GLOBAL_FLAG_OD_DYNAMIC) ``` -------------------------------- ### Clone and Initialize CANopenLinux Project Source: https://canopennode.github.io/CANopenLinux/index.html Clone the CANopenLinux project from its git repository and initialize its submodules. ```bash git clone https://github.com/CANopenNode/CANopenLinux.git cd CANopenLinux git submodule init git submodule update ``` -------------------------------- ### Compile and Run demoDevice Source: https://canopennode.github.io/md_tutorial_2README.html Instructions to compile and execute the demoDevice application on a Linux system. This device will act as a sample CANopen node. ```bash cd demo make rm *.persist ./demoLinuxDevice can0 ``` -------------------------------- ### OD_get_f64 Source: https://canopennode.github.io/CANopenNode/CO__ODinterface_8h.html Gets a float64_t variable from the Object Dictionary. ```APIDOC ## OD_get_f64 ### Description Get float64_t variable from Object Dictionary, see OD_get_value. ### Signature static ODR_t OD_get_f64 (const OD_entry_t *entry, uint8_t subIndex, float64_t *val, bool_t odOrig) ``` -------------------------------- ### app_programStart Function Source: https://canopennode.github.io/CANopenLinux/CO__application_8h_source.html This function is called once on program startup, after Object Dictionary initialization and before CAN communication begins. It initializes CANopen parameters. ```c CO_ReturnError_t app_programStart(uint16_t *bitRate, uint8_t *nodeId, uint32_t *errInfo) ``` -------------------------------- ### OD_get_f32 Source: https://canopennode.github.io/CANopenNode/CO__ODinterface_8h.html Gets a float32_t variable from the Object Dictionary. ```APIDOC ## OD_get_f32 ### Description Get float32_t variable from Object Dictionary, see OD_get_value. ### Signature static ODR_t OD_get_f32 (const OD_entry_t *entry, uint8_t subIndex, float32_t *val, bool_t odOrig) ``` -------------------------------- ### CO_GTWA_init Function Source: https://canopennode.github.io/CANopenNode/CO__gateway__ascii_8h.html Initializes the Gateway-ascii object with the provided parameters. ```APIDOC ## Functions --- CO_ReturnError_t | CO_GTWA_init (CO_GTWA_t *gtwa, CO_SDOclient_t *SDO_C, uint16_t SDOclientTimeoutTime_ms, bool_t SDOclientBlockTransfer, CO_NMT_t *NMT, CO_LSSmaster_t *LSSmaster, CO_LEDs_t *LEDs, uint8_t dummy) | Initialize Gateway-ascii object. ``` -------------------------------- ### OD_get_u64 Source: https://canopennode.github.io/CANopenNode/CO__ODinterface_8h.html Gets a uint64_t variable from the Object Dictionary. ```APIDOC ## OD_get_u64 ### Description Get uint64_t variable from Object Dictionary, see OD_get_value. ### Signature static ODR_t OD_get_u64 (const OD_entry_t *entry, uint8_t subIndex, uint64_t *val, bool_t odOrig) ``` -------------------------------- ### OD_get_u32 Source: https://canopennode.github.io/CANopenNode/CO__ODinterface_8h.html Gets a uint32_t variable from the Object Dictionary. ```APIDOC ## OD_get_u32 ### Description Get uint32_t variable from Object Dictionary, see OD_get_value. ### Signature static ODR_t OD_get_u32 (const OD_entry_t *entry, uint8_t subIndex, uint32_t *val, bool_t odOrig) ``` -------------------------------- ### OD_get_u16 Source: https://canopennode.github.io/CANopenNode/CO__ODinterface_8h.html Gets a uint16_t variable from the Object Dictionary. ```APIDOC ## OD_get_u16 ### Description Get uint16_t variable from Object Dictionary, see OD_get_value. ### Signature static ODR_t OD_get_u16 (const OD_entry_t *entry, uint8_t subIndex, uint16_t *val, bool_t odOrig) ``` -------------------------------- ### Run CANopen Linux with ASCII Interface Source: https://canopennode.github.io/CANopenLinux/index.html Start the `canopend` service with the ASCII command interface enabled on `stdio` for direct command input. Basic commands like `help`, `write`, and `reset` are shown. ```bash canopend can0 -i 1 -c "stdio" help 1 write 0x1010 1 vs save 1 reset node ``` -------------------------------- ### Display canopend Help Options Source: https://canopennode.github.io/CANopenLinux/index.html Display the available command-line options for the canopend application. ```bash canopend --help ``` -------------------------------- ### OD_get_u8 Source: https://canopennode.github.io/CANopenNode/CO__ODinterface_8h.html Gets a uint8_t variable from the Object Dictionary. ```APIDOC ## OD_get_u8 ### Description Get uint8_t variable from Object Dictionary, see OD_get_value. ### Signature static ODR_t OD_get_u8 (const OD_entry_t *entry, uint8_t subIndex, uint8_t *val, bool_t odOrig) ``` -------------------------------- ### OD_get_i64 Source: https://canopennode.github.io/CANopenNode/CO__ODinterface_8h.html Gets an int64_t variable from the Object Dictionary. ```APIDOC ## OD_get_i64 ### Description Get int64_t variable from Object Dictionary, see OD_get_value. ### Signature static ODR_t OD_get_i64 (const OD_entry_t *entry, uint8_t subIndex, int64_t *val, bool_t odOrig) ``` -------------------------------- ### Initialize EEPROM and Reset Node Source: https://canopennode.github.io/md_demo_2README.html Use these commands to initialize the EEPROM, save configuration, and reset the CANopen node. Ensure the device is connected to the CANopen network and configured for 250kbps with NodeId=4. ```cocomm cocomm "4 w 0x1011 1 vs load" cocomm "4 reset node" cocomm "4 w 0x1010 1 vs save" cocomm "4 reset node" ``` -------------------------------- ### app_programStart Source: https://canopennode.github.io/CANopenADI/CO__application_8h.html Initializes the CANopenNode application. This function is called once on program startup, after Object Dictionary initialization and before CANopen initialization. It allows for overriding default bit rate and Node ID. ```APIDOC ## app_programStart() ### Description Application interface, similar to Arduino, extended to CANopen and additional, realtime thread. Function is called once on the program startup, after Object dictionary initialization and before CANopen initialization. ### Parameters - **bitRate** (uint16_t *) - [in,out] - Stored CAN bit rate, can be overridden. - **nodeId** (uint8_t *) - [in,out] - Stored CANopen NodeId, can be overridden. - **errInfo** (uint32_t *) - [out] - Variable may indicate error information - index of erroneous OD entry. ### Returns - CO_ReturnError_t - CO_ERROR_NO in case of success. ``` -------------------------------- ### OD_get_i32 Source: https://canopennode.github.io/CANopenNode/CO__ODinterface_8h.html Gets an int32_t variable from the Object Dictionary. ```APIDOC ## OD_get_i32 ### Description Get int32_t variable from Object Dictionary, see OD_get_value. ### Signature static ODR_t OD_get_i32 (const OD_entry_t *entry, uint8_t subIndex, int32_t *val, bool_t odOrig) ``` -------------------------------- ### Basic NMT, SDO, and Heartbeat Test Source: https://canopennode.github.io/md_test_2test__report.html Verifies basic CANopen functionalities including NMT states, SDO reads, and heartbeat monitoring. Assumes a 250 kbps CAN bus. ```bash Running 'basic_NMT_SDO_heartbeat.bats': ✓ NMT: all preoperational ✓ SDO: read heartbeat D1 ✓ SDO: read heartbeat D2 ✓ SDO: disable heartbeats ✓ candump: no communication, 2sec ✓ Heartbeats: all present ✓ NMT: reset communication - one ✓ NMT: reset communication - two ✓ NMT: reset communication - three ✓ all preoperational ✓ SDO: disable all PDOs on D1 ✓ SDO: disable all PDOs on D2 ✓ NMT: pre-operational D1 ✓ NMT: operational D1 ✓ NMT: pre-operational D2 ✓ NMT: operational D2 ✓ finish: NMT all preoperational 17 tests, 0 failures ```