The project is based on XMODEM implementation written by tehmaze.
YMODEM Protocol: ENGLISH | 简体中文
If you want to run the test sample, please do the following:
- use virtual serial port tool to generate COM1 and COM2 that can communicate
- run the test_receiver.py and test_sender.py on the command line
The specific transmission process is shown in the following figure (sender on the left and receiver on the right)
- Import YModem in your target file
from YModem import YModem
- Define your own get() and put() and create YMODEM object
def getc(size):
return serial_io.read(size) or None
def putc(data):
return serial_io.write(data)
tester = YModem(getc, putc)
- Send file
tester.send_file(file_path)
- Receive file
tester.recv_file(root_path)
def __init__(self, getc, putc, header_pad=b'\x00', data_pad=b'\x1a')
- get: Custom function. Get size bytes of data from data source(size)
- put: Custom function. Send size bytes to destination
def send_file(self, file_path, retry=20, callback=None)
- file_path: target file path
- retry: max resend tries
- callback: implemented by the developer
def recv_file(self, root_path, callback=None)
- root_path: root path for storing the file
- callback: implemented by the developer
This project does not include the following code related to business logic:
- the callback that processing the internal data of YModem
- Timeout mechanism and CAN instruction sending
- Simplified the implementation of the original version of YModem