ENP-CAN
can
library implements CAN bus communication for the ENP-CAN module.
can.init
#
Initializes hardware for CAN communication. Must be called before any other communication function.
baudrate
should be provided in kbps with value options: 1000
,800
, 500
, 250
, 100
.
Optional handler
function can be provided. It will be called every time a CAN packet is received. The function must receive CAN message ID as a first argument and Lua table as the second argument, it will contain CAN data frame (up to 8 bytes), see example below.
Returns 0
if initialization is performed successfully, otherwise returns error code (use can.err_to_str
to convert it to string representation).
#
Examplecan.send
#
Sends CAN frame to CAN bus. Data must be a string of up to 8 bytes.
Returns 0
if data was sent successfully, otherwise returns error code (use can.err_to_str
to convert it to string representation).
#
Examplecan.err_to_str
#
Returns string representation of can
function return code.