How to stop Xmodem after bin file transfer was finished - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to stop Xmodem after bin file transfer was finished (/thread-22799.html) |
How to stop Xmodem after bin file transfer was finished - shaya2103 - Nov-27-2019 hello freinds, I am sending a BIN file successfully to my energy meter through serial port using the code in the bottom. My problem is that Xmodem doesn't stop after all 128 blocks where sent and i have no idea how to break from it and communicate again with my meter. Please your kind help. def sendFile(): fileSize = os.path.getsize('104_new.BIN') total = math.ceil(fileSize /128) ser= serialPort.serialport ser.flushInput() print (ser) def getc(size, timeout=0): gbytes = ser.read(1) #sleep(0.008) print(f'Read Byte: {gbytes}') return gbytes or None def putc(data, timeout=0): pbytes = ser.write(data) sleep(0.2) print(f'Put Byte: {pbytes}') return pbytes or None modem =XMODEM(getc,putc) f = open('104_new.BIN', "rb") modem.send(f,retry=50,callback=total) f.close() ser.close() ser.flushOutput() senddata_edit.insert(0,'scan\r')this is the error code i get:
|