CAN_MESSAGE
The CAN_MESSAGE node sends a message onto CAN network through a slcan-compatible USB-to-CAN adapter.Inputs
------
message : Vector
The array of data to send to the CAN bus.Params:arbitration_id : intUnique ID for message being sent.is_extended_id : boolFlag that controls the size of the arbitration_id field.Returns:out : TextblobTraceback error
Python Code
import can, traceback, json
from can.interface import Bus
from flojoy import flojoy, SerialDevice, Vector, DataContainer, TextBlob
from typing import Optional
@flojoy(deps={"python-can": "4.2.2"})
def CAN_MESSAGE(
device: SerialDevice,
message: Vector | Optional[DataContainer] = None,
# arbitration_id: hex = 0xC0FFEE, TODO: Support hex inputs
is_extended_id: bool = True,
) -> TextBlob:
"""The CAN_MESSAGE node sends a message onto CAN network through a slcan-compatible USB-to-CAN adapter.
Inputs
------
message : Vector
The array of data to send to the CAN bus.
Parameters
----------
arbitration_id : int
Unique ID for message being sent.
is_extended_id : bool
Flag that controls the size of the arbitration_id field.
Returns
-------
Textblob
Traceback error
"""
s = ""
try:
can.rc["interface"] = "slcan"
can.rc["channel"] = device.get_port()
can.rc["bitrate"] = 500000
s = json.dumps(can.rc)
msg = can.Message(
data=message.v, arbitration_id=0xC0FFEE, is_extended_id=is_extended_id
)
with can.Bus() as bus:
bus.send(msg)
except:
s = traceback.format_exc()
return TextBlob(s)
Example
Having problem with this example app? Join our Discord community and we will help you out!