我正在编写一个程序,需要使用XMODEM从传感器设备传输数据.我想避免编写我自己的XMODEM代码,所以我想知道是否有人知道是否有可用的python XMODEM模块?
def xmodem_send(serial, file): t, anim = 0, '|/-\\' serial.setTimeout(1) while 1: if serial.read(1) != NAK: t = t + 1 print anim[t%len(anim)],'\r', if t == 60 : return False else: break p = 1 s = file.read(128) while s: s = s + '\xFF'*(128 - len(s)) chk = 0 for c in s: chk+=ord(c) while 1: serial.write(SOH) serial.write(chr(p)) serial.write(chr(255 - p)) serial.write(s) serial.write(chr(chk%256)) serial.flush() answer = serial.read(1) if answer == NAK: continue if answer == ACK: break return False s = file.read(128) p = (p + 1)%256 print '.', serial.write(EOT) return True