Use python xmodem to transfer files from WindowsPC to device

Hi,

I try to use python xmodem (https://pypi.org/project/xmodem/) to transfer a file from my PC to device, but it seems that it always fails.

code on my device:

def getc(size, timeout=10):
    return mSerial.port.read(size) or None

def putc(data, timeout=10):
    return mSerial.port.write(data)  # note that this ignores the timeout


if __name__ == '__main__':
    stream = open('test1.txt', 'rb')
    modem = XMODEM(getc, putc)
    try:
        send_result=modem.send(stream)
        print(send_result)
    except Exception as e:
        print(e)
        #modem.abort(count=2, timeout=60)

code on the device:


import serial
from xmodem import XMODEM

ser=serial.Serial("/dev/ttyS2",57600)

def getc(size,timeout=1):
    return ser.read(size) or None

def putc(data,timeout=1):
    return ser.write(data) # note that this ignores the timeout


modem=XMODEM(getc,putc)

stream=open("receive_test01.txt","wb")
modem.recv(stream)


I don't know what the problem is here for I cannot transfer the file successfully.