Class: CAN

can~CAN(options)

CAN interface

Constructor

new CAN(options)

Creates a CAN interface. Destroy explicitly with destroy() when the interface is no longer in use.
Parameters:
Name Type Description
options Object The options
Properties
Name Type Attributes Default Description
pinRX Number the RX pin. Use pin 24-26 on neonious one
pinTX Number the TX pin. Use pin 24-25 on neonious one
pinBusOff Number <optional>
optional output pin: High normally, low if interface is in BUS_OFF state
pinClkOut Number <optional>
optional output pin: The clock signal
mode Number <optional>
can.MODE_NORMAL can.MODE_NORMAL: fully functional (default) can.MODE_NO_ACK: does not send ACKs on reception. For testing can.MODE_LISTEN_ONLY: does not send anything, receives in any case only
rxQueueSize Number <optional>
128 number of messages to queue till sent to user program.
txQueueSize Number <optional>
128 number of messages to allow in send queue
timing Object <optional>
can.TIMING_500_KBITS timing parameters. Either one of can.TIMING_*, or an object with the properties brp, tseg_1, tseg_2, sjw, triple_sampling. For more information, see https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/can.html
filter Object <optional>
Allows the device to receive only data for certain CAN codes at the hardware level. Useful to avoid overloading the main program in JavaScript either {id: Number, id_len: Number} lets the interface receive only message from one ID, id_len should be 11 or 29 --- or {code: Number, mask: Number, single: Boolean} gives the interface the full flexibility of the CAN driver, with the option to filter multiple IDs. For an explanation of the subvalues of this full specification, see https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/c^ an.html To reference: To map from the simple to the complete specification: code := id << (32 - id_len) mask := ~((((1 << id_len) - 1) << (32 - id_len))) single := true
Properties:
Name Type Description
state Number The state of the interface according to CAN2.0B Specification. Can be one of 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) can.STATE_DESTROYED: intf.destroy() was called.
txQueueCount Number Number of messages that are to be sent (=intf.transmit calls that still have not caused a callback call
txQueueThreshold Number If intf.txQueueCount falls below this value again, the event belowTXQueueThreshold is called. Default: 0
rxQueueCount Number Number of messages that have been received but for which the message event could not be called yet.
errorThreshold Number If txError and rxError are above this value, the event aboveErrorThreshold is called, as soon as this is no longer the case, belowErrorThreshold is called. Default: 96
stats Object
Properties
Name Type Description
rxMissed Number Number of unsaved CAN messages due to too small RX buffer
arbLost Number Number of sent packets where another node has priority
busError Number Number of bus errors
rxError Number Number of receive errors after CAN2.0B. Also goes down, not only up
txError Number Number of transmit errors according to CAN2.0B. Also goes down, not only up
Source:
Fires:

Extends

  • events.EventEmitter

Methods

destroy()

Frees all resources of the interface, allowing the program to use the pins differently or construct a new interface with other parameters.
Source:

recover(clearTXQueueopt, callbackopt) → {CAN}

Switches from can.STATE_BUS_OFF to can.STATE_RECOVERING and then to can.STATE_ERR_ACTIVE as soon as error count has fallen. If another recover process is running, the processes merges and both callbacks are called after the recover. If no recover is necessary, the callback is called immediately, with no error.
Parameters:
Name Type Attributes Default Description
clearTXQueue Boolean <optional>
false If true, the TX queue is emptied if a recover is necessary.
callback CANCallback <optional>
If specified, it will be called as soon as the recover process is finished
Source:
Returns:
interface itself, to chain call other methods
Type
CAN

ref() → {CAN}

Tells the interface to keep the program running when a transfer is taking place. This is the default.
Source:
Returns:
interface itself, to chain call other methods
Type
CAN

transmit(buffer, id, id_len, flagsopt, callbackopt) → {CAN}

Sends a 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.NO_RETRANSMISSION do not resend if other node sends with priority can.RECV_SELF should be able to be received by itself can.REMOTE_TRANSMIT_REQUEST is a remote transmit request
callback CANCallback <optional>
If specified, it will be called as soon as the message is shipped.
Source:
Returns:
interface itself, to chain call other methods
Type
CAN

unref() → {CAN}

Tells the interface to not keep the program running when a transfer is taking place, but there is nothing else to do.
Source:
Returns:
interface itself, to chain call other methods
Type
CAN