diff options
author | Damien George <damien.p.george@gmail.com> | 2015-04-16 23:52:43 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-04-16 23:52:43 +0100 |
commit | 7d5e34287c678b015a0f94620fc8626897a5cbda (patch) | |
tree | dd1198fd2670ac5b63e38a654588c25d69315efa /tests/pyb | |
parent | 4c459213499b289a1710aa0e6d3fb80c4889cc1f (diff) | |
download | micropython-7d5e34287c678b015a0f94620fc8626897a5cbda.tar.gz micropython-7d5e34287c678b015a0f94620fc8626897a5cbda.zip |
stmhal: Allow sending CAN messages with timeout=0.
Thanks to Henrik Sölver for this patch.
Diffstat (limited to 'tests/pyb')
-rw-r--r-- | tests/pyb/can.py | 61 | ||||
-rw-r--r-- | tests/pyb/can.py.exp | 6 |
2 files changed, 52 insertions, 15 deletions
diff --git a/tests/pyb/can.py b/tests/pyb/can.py index 132da23069..5fd4d39d05 100644 --- a/tests/pyb/can.py +++ b/tests/pyb/can.py @@ -1,4 +1,5 @@ from pyb import CAN +import pyb CAN.initfilterbanks(14) can = CAN(1) @@ -11,19 +12,19 @@ print(can.any(0)) # Catch all filter can.setfilter(0, CAN.MASK16, 0, (0, 0, 0, 0)) -can.send('abcd', 123) +can.send('abcd', 123, timeout=5000) print(can.any(0)) print(can.recv(0)) -can.send('abcd', -1) +can.send('abcd', -1, timeout=5000) print(can.recv(0)) -can.send('abcd', 0x7FF + 1) +can.send('abcd', 0x7FF + 1, timeout=5000) print(can.recv(0)) # Test too long message try: - can.send('abcdefghi', 0x7FF) + can.send('abcdefghi', 0x7FF, timeout=5000) except ValueError: print('passed') else: @@ -39,7 +40,7 @@ can.setfilter(0, CAN.MASK32, 0, (0, 0)) print(can) try: - can.send('abcde', 0x7FF + 1) + can.send('abcde', 0x7FF + 1, timeout=5000) except ValueError: print('failed') else: @@ -95,17 +96,17 @@ def cb1a(bus, reason): can.rxcallback(0, cb0) can.rxcallback(1, cb1) -can.send('11111111',1) -can.send('22222222',2) -can.send('33333333',3) +can.send('11111111',1, timeout=5000) +can.send('22222222',2, timeout=5000) +can.send('33333333',3, timeout=5000) can.rxcallback(0, cb0a) -can.send('44444444',4) +can.send('44444444',4, timeout=5000) -can.send('55555555',5) -can.send('66666666',6) -can.send('77777777',7) +can.send('55555555',5, timeout=5000) +can.send('66666666',6, timeout=5000) +can.send('77777777',7, timeout=5000) can.rxcallback(1, cb1a) -can.send('88888888',8) +can.send('88888888',8, timeout=5000) print(can.recv(0)) print(can.recv(0)) @@ -114,9 +115,39 @@ print(can.recv(1)) print(can.recv(1)) print(can.recv(1)) -can.send('11111111',1) -can.send('55555555',5) +can.send('11111111',1, timeout=5000) +can.send('55555555',5, timeout=5000) print(can.recv(0)) print(can.recv(1)) +del can + +# Testing asyncronous send +can = CAN(1, CAN.LOOPBACK) +can.setfilter(0, CAN.MASK16, 0, (0, 0, 0, 0)) + +while can.any(0): + can.recv(0) + +can.send('abcde', 1, timeout=0) +print(can.any(0)) +while not can.any(0): + pass + +print(can.recv(0)) + +try: + can.send('abcde', 2, timeout=0) + can.send('abcde', 3, timeout=0) + can.send('abcde', 4, timeout=0) + can.send('abcde', 5, timeout=0) +except OSError as e: + if str(e) == '16': + print('passed') + else: + print('failed') + +pyb.delay(500) +while can.any(0): + print(can.recv(0)) diff --git a/tests/pyb/can.py.exp b/tests/pyb/can.py.exp index b0ede7b9f4..845f6d5ba1 100644 --- a/tests/pyb/can.py.exp +++ b/tests/pyb/can.py.exp @@ -32,3 +32,9 @@ cb1a pending (1, 0, 0, b'11111111') (5, 0, 0, b'55555555') +False +(1, 0, 0, b'abcde') +passed +(2, 0, 0, b'abcde') +(3, 0, 0, b'abcde') +(4, 0, 0, b'abcde') |