Module: can

Module for CAN interface. ESP32 has a CAN controller included, all you need is a CAN transciever.
Source:

Classes

CAN

Members

(static) MODE_LISTEN_ONLY

For CAN interface constructor. Does not send anything, receives in any case only
Source:

(static) MODE_NO_ACK

For CAN interface constructor. Does not send ACKs on reception. For testing
Source:

(static) MODE_NORMAL

For CAN interface constructor. Fully functional mode (default)
Source:

(static) RECV_SELF

Flag for transmit(). Should be able to be received by itself
Source:

(static) REMOTE_TRANSMIT_REQUEST

Flag for transmit() and message event. Is a remote transmit request
Source:

(static) STATE_BUS_OFF

Too many errors occurred (rxError >= 256), interface no longer participates, intf.recover() must be called
Source:

(static) STATE_DESTROYED

intf.destroy() was called.
Source:

(static) STATE_ERR_ACTIVE

Now under 128 rxErrors or 128 txErrors
Source:

(static) STATE_ERR_PASSIVE

More than 128 rxError and 128 txError occurred
Source:

(static) STATE_RECOVERING

Recover is in progress (not finished until error count goes down)
Source:

(static) TIMING_25_KBITS

For CAN interface constructor. Default values for 25 kbit/s
Source:

Events

aboveErrorThreshold

txError and rxError are both above or equal to intf.errorThreshold (default 96). Can be used to monitor CAN bus quality.
Source:

belowErrorThreshold

One of txError and rxError is again under intf.errorThreshold (default 96). Can be used to monitor CAN bus quality.
Source:

belowTXQueueThreshold

TX queue is now smaller than intf.txQueueThreshold. New data can therefore be sent.
Source:

error

Might be called on generic error not to do with actions of user. If no callback was specified for an intf.transmit or intf.recover, errors of these calls are also reported here.
Parameters:
Name Type Description
err Error If err.code == 'CAN_TX_QUEUE_FULL', then too many transmit() calls are executed at the same time (see constructor option txQueueSize). If err.code == 'CAN_ARB_LOST', then another node has sent with priority. (should only possible if can.NO_RETRANSMISSION is set) If err.code == 'CAN_RECOVER_INITIATED', then a recover process was started. If err.code == 'CAN_DESTROYED', destroy() was already called. Callback is not called on existing transmits() on call of destroy() Otherwise there was a generic error
Source:

message

Fires on received message
Parameters:
Name Type Attributes Default Description
buffer Buffer The data, maximum 8 bytes
id Number The id of the recipient
id_len Number 11 or 29
flags Number <optional>
0 Bitfield of can.REMOTE_TRANSMIT_REQUEST is a remote transmit request
Source:

rxMissed

Too many messages in the RX queue, messages had to be thrown away before the event message could be called for them. Remedy: Increase rxQueueSize in the constructor, set filter to ID in the constructor or use less blocking code. Event might be called only once for multiple errors of this type.
Source:

stateChange

Fires on state change according to CAN2.0B Specification.
Parameters:
Name Type Description
state Number can.STATE_ERR_ACTIVE: Now under 128 rxErrors or 128 txErrors can.STATE_ERR_PASSIVE: More than 128 rxError and 128 txError occurred can.STATE_BUS_OFF: Too many errors occurred (rxError >= 256), interface no longer participates in the event. intf.recover() must be called can.STATE_RECOVERING: Recover is in progress (not finished until error count goes down). Data to be sent is buffered in the TX queue. can.STATE_DESTROYED: intf.destroy() was called.
Source: