-
Notifications
You must be signed in to change notification settings - Fork 20
/
read_bms.py
45 lines (38 loc) · 1.08 KB
/
read_bms.py
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
44
45
#!python2-32
from py9b.link.base import LinkOpenException, LinkTimeoutException
from py9b.link.tcp import TCPLink
from py9b.link.ble import BLELink
from py9b.link.serial import SerialLink
from py9b.transport.base import BaseTransport as BT
from py9b.transport.packet import BasePacket as PKT
from py9b.transport.xiaomi import XiaomiTransport
from py9b.transport.ninebot import NinebotTransport
from py9b.command.regio import ReadRegs
READ_CHUNK_SIZE = 0x10
#link = SerialLink(dump=True)
#link = TCPLink()
link = BLELink()
with link:
print "Scanning..."
ports = link.scan()
print ports
#tran = XiaomiTransport(link)
tran = NinebotTransport(link)
#link.open(("192.168.1.45", 6000))
link.open(ports[0][1])
print "Connected"
hfo = open("BmsRegs.bin", "wb")
for i in xrange(0x0, 0x100, READ_CHUNK_SIZE):
print ".",
for retry in xrange(5):
try:
data = tran.execute(ReadRegs(BT.BMS, i>>1, "16s"))[0]
except LinkTimeoutException:
continue
break
else:
print "No response !"
break
hfo.write(data)
hfo.close()
link.close()