Documentation
¶
Overview ¶
This package is a pure golang implementation of the CANopen protocol
Index ¶
- Variables
- func NewBus(canInterfaceName string, channel string, bitrate int) (canopen.Bus, error)
- type Network
- func (network *Network) AddRemoteNode(nodeId uint8, odict any) (*n.RemoteNode, error)
- func (network *Network) Command(nodeId uint8, nmtCommand nmt.Command) error
- func (network *Network) Configurator(nodeId uint8) *config.NodeConfigurator
- func (network *Network) Connect(args ...any) error
- func (network *Network) CreateLocalNode(nodeId uint8, odict any) (*n.LocalNode, error)
- func (network *Network) Disconnect()
- func (network *Network) GetOD(nodeId uint8) (*od.ObjectDictionary, error)
- func (network *Network) Local(nodeId uint8) (*n.LocalNode, error)
- func (network *Network) ReadEDS(nodeId uint8, edsFormatHandler od.EDSFormatHandler) (*od.ObjectDictionary, error)
- func (network *Network) Remote(nodeId uint8) (*n.RemoteNode, error)
- func (network *Network) RemoveNode(nodeId uint8) error
- func (network *Network) Scan(timeoutMs uint32) (map[uint8]NodeInformation, error)
- type NodeInformation
- type ObjectDictionaryInformation
Constants ¶
This section is empty.
Variables ¶
var ErrIdConflict = errors.New("id already exists on network, this will create conflicts")
var ErrInvalidNodeType = errors.New("invalid node type")
var ErrNoNodesFound = errors.New("no nodes found on network when performing SDO scan")
var ErrNotFound = errors.New("node id not found on network, add or create it first")
Functions ¶
Types ¶
type Network ¶
type Network struct { *canopen.BusManager *sdo.SDOClient // contains filtered or unexported fields }
A Network is the main object of this package It should be created before doint anything else It acts as scheduler for locally created CANopen nodes But can also be used for controlling remote CANopen nodes
func NewNetwork ¶
Create a new Network using the given CAN bus
func (*Network) AddRemoteNode ¶
Add a [RemoteNode] with a given OD for master control od can be either a string : path to OD or OD object useLocal is used to define whether the supplied OD should be used or the remote node should be read to create PDO mapping If remote nodes PDO mapping is static and known, use useLocal = true otherwise, if PDO mapping is dynamic, use useLocal = false
func (*Network) Command ¶
Command can be used to send an NMT command to a specific nodeId nodeId = 0 is used as a broadcast command i.e. affects all nodes on the network
network.Command(0,nmt.CommandResetNode) // resets all nodes network.Command(12,nmt.CommandResetNode) // resets nodeId 12
func (*Network) Configurator ¶
func (network *Network) Configurator(nodeId uint8) *config.NodeConfigurator
Configurator creates a [NodeConfigurator] object for a given id using the networks internal sdo client
func (*Network) Connect ¶
Connects to CAN bus, this should be called before anything else. Custom CAN backend is possible using a custom "Bus" interface. Otherwise it expects an interface name, channel and bitrate. Currently only socketcan and virtualcan are supported.
func (*Network) CreateLocalNode ¶
Create a [LocalNode] a CiA 301 compliant node with a given OD od can be either a string : path to OD or an OD object. Processing is started immediately after creating the node. By default, node automatically goes to operational state if no errors are detected. First heartbeat, if enabled is started after 500ms
func (*Network) Disconnect ¶
func (network *Network) Disconnect()
Disconnects from the CAN bus and stops processing of CANopen stack
func (*Network) GetOD ¶
func (network *Network) GetOD(nodeId uint8) (*od.ObjectDictionary, error)
Get OD for a specific node id
func (*Network) ReadEDS ¶
func (network *Network) ReadEDS(nodeId uint8, edsFormatHandler od.EDSFormatHandler) (*od.ObjectDictionary, error)
Read object dictionary using object 1021 (EDS storage) of a remote node Optional callback can be provided to perform manufacturer specific parsing in case a custom format is used (format type != 0). By default, regular uncompressed ASCII will be used (format type of 0).
func (*Network) Remote ¶
func (network *Network) Remote(nodeId uint8) (*n.RemoteNode, error)
Get a remote node object in network, based on its id
func (*Network) RemoveNode ¶
RemoveNode gracefully exits any running go routine for this node It also removes any object associated with the node, including OD
func (*Network) Scan ¶
func (network *Network) Scan(timeoutMs uint32) (map[uint8]NodeInformation, error)
Scan network for nodes via SDO, and return map of found node ids and respective node information. Scanning is done in parallel and requires that the scanned nodes have an SDO server and that the identity object is implemented (0x1018) which is mandatory per CiA standard.
type NodeInformation ¶
type NodeInformation struct { config.ManufacturerInformation config.Identity }
NodeInformation contains manufacturer information and identity object
type ObjectDictionaryInformation ¶
type ObjectDictionaryInformation struct {
// contains filtered or unexported fields
}