can.listen()
can.listen(callback)
Registers a receive handler for incoming CAN frames.
The callback receives a message object with the frame id and data
payload. Decode binary payloads with the bin functions.
Arguments
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| callback | function | yes | — | Callback function(msg){ … } — msg = { id, data }. |
Example
can.listen(function(msg){
print(string(msg)); // {"id":164242,"data":"hello from canbus"}
});