tests: Added and adapted CAN tests for extended messages
This commit is contained in:
parent
504636815e
commit
6a15ac80dc
tests/pyb
@ -1,9 +1,42 @@
|
|||||||
from pyb import CAN
|
from pyb import CAN
|
||||||
|
|
||||||
can = CAN(1)
|
can = CAN(1, CAN.LOOPBACK)
|
||||||
print(can)
|
print(can)
|
||||||
can.init(CAN.LOOPBACK)
|
|
||||||
print(can.any(0))
|
print(can.any(0))
|
||||||
can.send('abcd', 123)
|
can.send('abcd', 123)
|
||||||
print(can.any(0))
|
print(can.any(0))
|
||||||
print(can.recv(0))
|
print(can.recv(0))
|
||||||
|
|
||||||
|
can.send('abcd', -1)
|
||||||
|
print(can.recv(0))
|
||||||
|
|
||||||
|
can.send('abcd', 0x7FF + 1)
|
||||||
|
print(can.recv(0))
|
||||||
|
|
||||||
|
#Test too long message
|
||||||
|
try:
|
||||||
|
can.send('abcdefghi', 0x7FF)
|
||||||
|
except ValueError:
|
||||||
|
print('passed')
|
||||||
|
else:
|
||||||
|
print('failed')
|
||||||
|
|
||||||
|
del can
|
||||||
|
|
||||||
|
#Testing extended IDs
|
||||||
|
can = CAN(1, CAN.LOOPBACK, extframe = True)
|
||||||
|
print(can)
|
||||||
|
|
||||||
|
try:
|
||||||
|
can.send('abcde', 0x7FF + 1)
|
||||||
|
except ValueError:
|
||||||
|
print('failed')
|
||||||
|
else:
|
||||||
|
r = can.recv(0)
|
||||||
|
if r[0] == 0x7FF+1 and r[3] == b'abcde':
|
||||||
|
print('passed')
|
||||||
|
else:
|
||||||
|
print('failed, wrong data received')
|
||||||
|
|
||||||
|
|
||||||
|
print('end')
|
@ -1,4 +1,10 @@
|
|||||||
CAN(1)
|
CAN(1, LOOPBACK, False)
|
||||||
False
|
False
|
||||||
True
|
True
|
||||||
(123, 0, 0, b'abcd')
|
(123, 0, 0, b'abcd')
|
||||||
|
(2047, 0, 0, b'abcd')
|
||||||
|
(0, 0, 0, b'abcd')
|
||||||
|
passed
|
||||||
|
CAN(1, LOOPBACK, True)
|
||||||
|
passed
|
||||||
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user