Is there an equivalent in Python Socketcan / python-can that allows CAN messages to be sent to a specific destination device ID like how it's done on Arduino devices? The Arduino CAN bus boards use a MCP_CAN Library which allows for defining ID filter mode of the protocol controller in the command sendMsgBuf(ID, EXT, DLC, DATA). I have multiple devices connected which I can send specific CAN messages with ID field set to... CAN.sendMsgBuf(0x01...), CAN.sendMsgBuf(0x02...), CAN.sendMsgBuf(0x03...). However, when on a Linux board running socketcan, there's no equivalent Python-can with the cansend command.
Python-Can / Linux
import can
def send_one()
bus = can.interface.Bus(bustype='socketcan', channel='can0', bitrate=500000)
msg = can.Message(arbitration_id=0xc0ffee,
data=[0, 25, 0, 1, 3, 1, 4, 1],
is_extended_id=False)
try:
bus.send(msg)
print("Message sent on {}".format(bus.channel_info))
except can.CanError:
print("Message NOT sent")
if __name__ == '__main__':
send_one()
MCP_CAN Library for Arduino
//sendMsgBuf(ID, DLC, DATA)
...sendMsgBuf(0x01, DLC, DATA) //Send to Device ID 0x01
...sendMsgBuf(0x02, DLC, DATA) //Send to Device ID 0x02
...sendMsgBuf(0x02, DLC, DATA) //Send to Device ID 0x03
In a standard socketcan example, the can.Message() command sets the arbitration_id for the transmitting device, but it doesn't define the can_id of the device that I'm trying to send it to when I have multiple devices connected to the canbus which are waiting for messages. How would I send CAN messages to let's say can device 0x01, device 0x02, and device 0x03?