def Flash(self, fwfilep): if self.device == 'extbms' and self.protocol != 'ninebot': exit('Only Ninebot supports External BMS !') self.setfwfilep(fwfilep) file = open(fwfilep, 'rb') dev = self.devices.get(self.device) if self.interface == 'ble': if platform != 'android': try: from py9b.link.ble import BLELink except: exit('BLE is not yet working with your configuration !') elif platform == 'android': try: from py9b.link.able import BLELink except: exit('BLE is not yet supported on Android !') else: exit('BLE is not supported on your system !') link = BLELink() elif self.interface == 'tcp': from py9b.link.tcp import TCPLink link = TCPLink() elif self.interface == 'serial': if platform == 'android': exit('Serial is not yet supported on Android !') from py9b.link.serial import SerialLink link = SerialLink() else: exit('!!! BUG !!! Unknown interface selected: ' + interface) with link: tran = self.protocols.get(self.protocol)(link) if self.address != '': addr = self.address elif self.interface != 'ble': print('Scanning...') ports = link.scan() if not ports: exit("No interfaces found !") print('Connecting to', ports[0][0]) addr = ports[0][1] else: raise LinkOpenException link.open(addr) print('Connected') try: UpdateFirmware(link, tran, dev, file) except Exception as e: print('Error:', e) raise
link = BLELink() elif args.interface == 'tcp': from py9b.link.tcp import TCPLink link = TCPLink() elif args.interface == 'serial': from py9b.link.serial import SerialLink link = SerialLink() else: exit('!!! BUG !!! Unknown interface selected: ' + args.interface) with link: tran = protocols.get(args.protocol)(link) if args.address: addr = args.address else: print('Scanning...') ports = link.scan() if not ports: exit("No interfaces found !") print('Connecting to', ports[0][0]) addr = ports[0][1] link.open(addr) print('Connected') try: UpdateFirmware(link, tran, dev, args.file) except Exception as e: print('Error:', e) raise
#link = SerialLink(dump=True) #link = TCPLink() link = BLELink(dump=True) 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") print("Pinging...") for retry in xrange(20): print(".", end="") try: old_sn = tran.execute(ReadRegs(BT.ESC, 0x10, "14s"))[0] except LinkTimeoutException: continue break else: exit("Timed out !") print("") #lock