isa56k / ymodem

YMODEM (For cluster communication port) written by Python - 用Python实现的YMODEM串口通讯协议

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ymodem-logo

The project is based on XMODEM implementation written by tehmaze.

Build Status license

README: ENGLISH | 简体中文

YMODEM Protocol: ENGLISH | 简体中文

Can YMODEM for Python work

If you want to run the test sample, please do the following:

  1. use virtual serial port tool to generate COM1 and COM2 that can communicate
  2. 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) cmd_test hash_result

How to use YMODEM for Python

  1. Import YModem in your target file
from YModem import YModem
  1. 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)
  1. Send file
tester.send_file(file_path)
  1. Receive file
tester.recv_file(root_path)

YMODEM for Python API

Create YMODEM object

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

Send data

def send_file(self, file_path, retry=20, callback=None)
  • file_path: target file path
  • retry: max resend tries
  • callback: implemented by the developer

Recv data

def recv_file(self, root_path, callback=None)
  • root_path: root path for storing the file
  • callback: implemented by the developer

Attention

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

Change logs

v1.0.0 (2020/5/14 14:00 +00:00)

  • Simplified the implementation of the original version of YModem

License

MIT License

About

YMODEM (For cluster communication port) written by Python - 用Python实现的YMODEM串口通讯协议

License:MIT License


Languages

Language:Python 100.0%