问题
I'm trying to transfer a file using the XMODEM protocol.
I saw and did not understand the solution provided in: Can I use the xmodem protocol with PySerial?
I saw xmodem package link.
- What is the value of
size
to be provided for thegetc
method? It is not assigned with any value given in the first link. - When I use simple method as explained in the second link, I end up getting the error:
No handlers could be found for logger "xmodem"
.
Here is my code to send the file.
import serial
from xmodem import XMODEM, CRC
from time import sleep
def getc(size, timeout=1):
return port.read(size)
def putc(data, timeout=1):
port.write(data)
sleep(0.001) # give device time to send ACK
port = serial.Serial(port='COM10',parity=serial.PARITY_NONE,bytesize=serial.EIGHTBITS,stopbits=serial.STOPBITS_ONE,timeout=0,xonxoff=0,rtscts=0,dsrdtr=0,baudrate=9600)
sleep(2) # give device time to handle command
stream = open('..\\stream\\myfile.bin','rb')
modem = XMODEM(getc, putc)
modem.send(stream, quiet = 0)
I get the error: No handlers could be found for logger "xmodem"
.
回答1:
Here is the solution for 1st question, getc and putc are used by XMODEM to read size number of bytes from port and write data to port respectively. They need to be defined by user and supplied to XMODEM object. XMODEM internally calls getc with size.
来源:https://stackoverflow.com/questions/12781023/what-is-the-value-of-size-to-be-provided-for-the-getc-method-in-xmodem-protocol