English | 简体中文
QCanopenMaster is a lightweight CANopen master component based on Qt. It encapsulates core functionalities such as device drivers, NMT management, heartbeat monitoring, and SDO access. It provides a simple and consistent QObject/QML-friendly interface for easy and fast integration into Qt applications.
- Language/Framework: C++17 / Qt 5/6 (based on QtCore)
- Build System: CMake
- Suitable Scenarios: CANopen master control, device debugging, upper computer tools, automated testing
- Singleton management: QCanopenMaster::instance() global unique instance
- Device lifecycle: initDevice / openDevice / closeDevice / resetCanDevice
- Master periodic task: process() can be driven by external timer
- NMT control: Start / Stop / Pre-Operational / Reset Node / Reset Communication
- SDO access: read (uploadSDO) and write (downloadSDO)
- Raw CAN frame sending: sendRequest
- Event signals: error reporting, CAN frame reporting, SDO result reporting
- Q_INVOKABLE: easy to call directly from QML/Qt meta-object system
- QCanopenMaster_global.h: export macro definitions
- qcanopenmaster.h / .cpp: main class and external API
- CanOpen/
- driver.*: underlying CAN driver abstraction
- NMT.*: NMT management
- heartBeat.*: heartbeat monitoring
- SDO.*: SDO access implementation
- canopenObject.*: object dictionary/device abstraction
- utils/
- ByteParser.*: byte order and parsing utilities
- Qt 5.15+ or Qt 6.x (QtCore required)
- CMake 3.16+
- C++17 compiler
- Platform support depends on driver implementation (example parameters include SocketCAN, usable on Linux; Windows requires corresponding CAN driver support)
-
setCurrentNodeId(uint8_t nodeId)
Set the current working node ID. -
initDevice(QVariantMap params)
Initialize the device. Example parameters:{ "canType": "SocketCan", "channel": "0", "nominalBaudrate": "500000", "dataBaudrate": "2000000" } -
openDevice()
Open the device connection. -
closeDevice()
Close the device connection. -
resetCanDevice()
Reset the device.
sendRequest(QVariantMap params)
Send original CAN frame, example:{ "canId": 1537, "dlc": 4, "data": [11, 22, 33, 44, 55, 66, 77, 88], "time": 1723267200000 }sendNMT(uint8_t command)
Send NMT instruction:0x01Start0x02Stop0x80Pre-Operational0x81Reset Node0x82Reset Communication
-
uploadSDO(uint16_t nodeId, uint16_t index, uint8_t subIndex, QVariant data)
Read object dictionary data. -
downloadSDO(uint16_t nodeId, uint16_t index, uint8_t subIndex, QVariant data)
Write object dictionary data. -
resetSDOState()
Reset the SDO state machine.
-
sendErrorSig(QString error)
Error message reporting. -
sendCanFrameToUiSig(QVariantMap item)
Report to the UI when CAN frames are received and sent. -
sendSdoItemSig(uint16_t nodeId, uint16_t index, uint8_t subIndex, QVariantMap sdoItem)
Report when SDO data is received.
This project is open-sourced under the MIT License.
Please refer to the LICENSE file in the repository root for details.
When using this project’s code, please comply with the license terms.