summaryrefslogtreecommitdiffstatshomepage
path: root/tests/pyb/can.py
blob: 923a83860f35407e0152b679b7ba1523c0bee0dd (plain) (blame)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
from pyb import CAN

can = CAN(1)
print(can)

can.init(CAN.LOOPBACK)
print(can)
print(can.any(0))

can.send('abcd', 123)
print(can.any(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')