go-canopencanopen
This packagecanopen is an implementation of the CANopen protocol (CiA 301) written entirely in pure golang. Its goal isIt aims to be simple, yet and efficient. ItThis package can act as abe used for master on the bususage but it also supports implementation ofcreating regular canCANopen nodes.
Features
All the main components of CiA 301 are supported, these include :
- SDO server/client
- NMT master/slave
- HB producer/consumer
- TPDO/RPDO
- EMERGENCY producer/consumer
- SYNC producer/consumer
- TIME
CiA 309 (Network)
Partial support also exists for CiA 309, specifically :
- HTTP gateway
This implementationgo-canopen does not require the use of an external tool to generate some source code from an EDS file. EDS files can be loaded dynamically from disk to create local nodes with default supported objects.
Supported CAN transceivers
Currently this package only supports socketcan using : brutella/can However it can easily extended by creating your own driver. The following interface needs to be implemented
Feel free to contribute to add specific drivers, we will find a way to integrate them in this repo. This repo contains two implementation examples : socketcan.go
, and virtual.go
used for testing.
Example usage
Usage
Examples can be found in /cmd
Basic setup example :
network := canopen.NewNetwork(nil) e := network.Connect("socketcan", "can0", 500000) if e != nil { panic(e) } defer network.Disconnect()// Background processinggo func() { network.Process() }()// Load a remote node OD to be able to read values from strings e = network.AddNode(0x10, "../../testdata/base.eds") if e != nil { panic(e) } network.Read(0x10, "INTEGER16 value", "")
Work ongoing
- Improve documentation & examples
- More testing
- Adding support for kvaser (canlib)
- Reduce boilerplate as much as possible
- Improve API around "master" behaviour
Testing
Testing is done :
Credits
This work is heavily based on the C implementation by Janez ([https://github.com/CANopenNode/CANopenNode]) Testing is done usingand also inspired by the python implementation by Christian Sandberg ([https://github.com/christiansandberg/canopen])