forked from hardbyte/python-can
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtual_can_demo.py
More file actions
30 lines (23 loc) · 822 Bytes
/
virtual_can_demo.py
File metadata and controls
30 lines (23 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
This demo creates multiple processes of Producers to spam a socketcan bus.
"""
import time
import logging
import concurrent.futures
import can
can.rc['interface'] = 'socketcan_native'
from can.interfaces.interface import Bus
can_interface = 'vcan0'
def producer(id):
""":param id: Spam the bus with messages including the data id."""
bus = Bus(can_interface)
for i in range(16):
msg = can.Message(arbitration_id=0x0cf02200, data=[id, i, 0, 1, 3, 1, 4, 1])
bus.send(msg)
# TODO Issue #3: Need to keep running to ensure the writing threads stay alive. ?
time.sleep(2)
if __name__ == "__main__":
#logging.getLogger('').setLevel(logging.DEBUG)
with concurrent.futures.ProcessPoolExecutor(max_workers=4) as executor:
executor.map(producer, range(5))
time.sleep(2)