SEND_CAN_MESSAGE
Download Flojoy Studio to try this app
Send a message to a CAN system. Send a message to a CAN device. This block should be compatible with all devices that support the CAN interface.
A connection to the device is required. Use a CAN_CONNECT block to connect to a CAN device. Params: CAN_address : str The CAN device address to connect to. message : Stateful A list of messages to send to the CAN device. Returns: out : DataContainer Optional: None
Python Code
from typing import Optional
from flojoy import flojoy, DeviceConnectionManager, Stateful, DataContainer
import can
@flojoy(deps={"python-can": "4.3.1"})
def SEND_CAN_MESSAGE(
CAN_address: str, message: Stateful, default: Optional[DataContainer] = None
) -> Optional[DataContainer]:
"""Send a message to a CAN system.
Send a message to a CAN device. This block should be compatible with all devices that support the CAN interface.
A connection to the device is required. Use a CAN_CONNECT block to connect to a CAN device.
Parameters
----------
CAN_address : str
The CAN device address to connect to.
message : Stateful
A list of messages to send to the CAN device.
Returns
-------
DataContainer
Optional: None
"""
connection: can.interface.Bus = DeviceConnectionManager.get_connection(
CAN_address
).get_handle()
for msg in message.obj:
connection.send(msg)
return None
Example App
Having problems with this example app? Join our Discord community and we will help you out!
This example shows how to send a frame to a CAN bus using the CANable USB-to-CAN adapter. The application sends a first frame intended to indicate the start of a test on a system. Subsequently, the application sends a burst of messages and then sends a frame to indicate the end of the test.
This application uses an CANABLE_CONNECT
block to establish a connection to the CAN bus, but this connection could be replaced by any other connection. For example, the PEAK_CONNECT
block could be used instead.