What is the value of size to be provided for the getc method in xmodem protocol?

狂风中的少年 提交于 2020-01-01 19:45:24

问题


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.

  1. What is the value of size to be provided for the getc method? It is not assigned with any value given in the first link.
  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!