2020
2121
2222def test_simple_periodic_send ():
23- print ("Trying to send a message... " )
24- msg = can .Message (arbitration_id = 0x0cf02200 , data = [0 , 1 , 3 , 1 , 4 , 1 ])
25- task = can .send_periodic ('vcan0' , msg , 0.020 )
23+ print ("Starting to send a message every 200ms. Initial data is zeros " )
24+ msg = can .Message (arbitration_id = 0x0cf02200 , data = [0 , 0 , 0 , 0 , 0 , 0 ])
25+ task = can .send_periodic ('vcan0' , msg , 0.20 )
2626 time .sleep (2 )
27+ task .stop ()
28+ print ("stopped cyclic send" )
2729
28- print ("Trying to change data" )
29- msg .data [0 ] = 99
30+
31+ def test_periodic_send_with_modifying_data ():
32+ print ("Starting to send a message every 200ms. Initial data is ones" )
33+ msg = can .Message (arbitration_id = 0x0cf02200 , data = [1 , 1 , 1 , 1 ])
34+ task = can .send_periodic ('vcan0' , msg , 0.20 )
35+ time .sleep (2 )
36+ print ("Changing data of running task to begin with 99" )
37+ msg .data [0 ] = 0x99
3038 task .modify_data (msg )
3139 time .sleep (2 )
3240
3341 task .stop ()
3442 print ("stopped cyclic send" )
35-
43+ print ("Changing data of stopped task to single ff byte" )
44+ msg .data = bytearray ([0xff ])
45+ task .modify_data (msg )
3646 time .sleep (1 )
37- task .start ()
3847 print ("starting again" )
48+ task .start ()
3949 time .sleep (1 )
50+ task .stop ()
4051 print ("done" )
4152
4253
4354def test_dual_rate_periodic_send ():
4455 """Send a message 10 times at 1ms intervals, then continue to send every 500ms"""
45- msg = can .Message (arbitration_id = 0x0c112200 , data = [0 , 1 , 2 , 3 , 4 , 5 ])
56+ msg = can .Message (arbitration_id = 0x123 , data = [0 , 1 , 2 , 3 , 4 , 5 ])
4657 print ("Creating cyclic task to send message 10 times at 1ms, then every 500ms" )
4758 task = can .interface .MultiRateCyclicSendTask ('vcan0' , msg , 10 , 0.001 , 0.50 )
4859 time .sleep (2 )
@@ -60,6 +71,7 @@ def test_dual_rate_periodic_send():
6071 task .start ()
6172 print ("starting again" )
6273 time .sleep (2 )
74+ task .stop ()
6375 print ("done" )
6476
6577
@@ -68,12 +80,11 @@ def test_dual_rate_periodic_send():
6880 for interface in {'socketcan_ctypes' , 'socketcan_native' }:
6981 print ("Carrying out cyclic tests with {} interface" .format (interface ))
7082 can .rc ['interface' ] = interface
83+
7184 test_simple_periodic_send ()
7285
86+ test_periodic_send_with_modifying_data ()
7387
74- for interface in {'socketcan_ctypes' , }:
75- print ("Carrying out cyclic tests with {} interface" .format (interface ))
88+ print ("Carrying out multirate cyclic test for {} interface" .format (interface ))
7689 can .rc ['interface' ] = interface
7790 test_dual_rate_periodic_send ()
78-
79- print ("socketcan_native doesn't yet support MultiRate Cyclic Tasks" )
0 commit comments