Replies: 2 comments
-
I got it to work. Probably not the slickest or most elegant way, but here is what I did: `message1 = can.Message(arbitration_id=0x111, data=[0x0, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70], is_extended_id=False) bus = can.interface.Bus(bustype='socketcan', channel='can0', bitrate=500000) def task1(): def task2(): def task3(): thread1 = threading.Thread(target=task1) thread1.start() time.sleep(25) thread1.join() Next thing to do is to figure out how to make it run indefinitely. I can modify the Best Regards, |
Beta Was this translation helpful? Give feedback.
-
Hi Steve, In your first example you obviously opened one BCM socket, added a TX job (with 20ms) and the overwrote the same job with new data. Usually different CAN IDs create different (independent) TX jobs so the 0x123 and 0x321 frames should have been sent with 20ms gap independently from each other. But the gap is CAN ID specific, so having 0x123 - 17ms - 0x321 - 3ms - 0x123 would show that the 20ms gap for 0x123 is correct. In the second example the different tasks likely open a separate socket each. The sequence is sent indefinitely by the Linux kernel unless you explicitly delete the TX job OR the CAN_BCM socket is closed. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Thanks for reading.
I am an absolute novice here so here goes.
I used this code:
`import can
import time
Initialize a CAN bus (replace 'socketcan' and 'vcan0' with your actual interface)
bus = can.interface.Bus(interface='socketcan', channel='can0', bitrate=500000)
Create a CAN message
msg = can.Message(arbitration_id=0x123, data=[0, 1, 2, 3, 4, 5], is_extended_id=False)
msg2 = can.Message(arbitration_id=0x321, data=[5, 4, 3, 2, 1, 0], is_extended_id=False)
Start sending the message every 20ms
print("Starting to send a message every 20ms.")
task = bus.send_periodic(msg, 0.020)
task = bus.send_periodic(msg2, 0.020)
Let it run for a few seconds
time.sleep(20)
Stop the periodic transmission
task.stop()
print("Stopped cyclic send.")
Shut down the bus
bus.shutdown()`
...to send a single message and it works. But if I add another message (line 14) the first message is sent at 17mS and the second is sent at 3mS. It appears that it is cramming in the two messages into the same 20mS time slot.
Do I need separate tasks for each message I want to send at 20mS? How is that done?
Best Regards,
Steve
Beta Was this translation helpful? Give feedback.
All reactions