Coder Social home page Coder Social logo

okayming / ymodem4python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alexwoo1900/ymodem

1.0 0.0 0.0 42.04 MB

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

License: MIT License

Python 100.00%

ymodem4python's Introduction

ymodem-logo

The YMODEM project is based on XMODEM implementation written by tehmaze. It is also compatible with XMODEM mode.

Build Status license

README: ENGLISH | 简体中文

Demo

Test the sending and receiving functions

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 FileReceiver.py and FileSender.py on the command line

The specific transmission process is shown in the following figure: SenderAndReceiver

Interact with SecureCRT

Interact with SecureCRT as sender SecureCRT1

Interact with SecureCRT as Finder SecureCRT2

Quick start

from Modem import Modem

'''
Sender
'''
# define read function for sender
def sender_read(size, timeout=3):
    pass

# define write function for sender
def sender_write(data, timeout=3):
    pass

# create sender
sender = Modem(sender_read, sender_write)

# send multi files
sender.send([file_path1, file_path2, file_path3 ...])

'''
Receiver
'''

# define read function for receiver
def receiver_read(size, timeout=3):
    pass

# define write function for receiver
def receiver_write(data, timeout=3):
    pass

# create receiver
receiver = Modem(receiver_read, receiver_write)

# receive multi files
receiver.recv(folder_path)

API

Create MODEM Object

def __init__(self, reader, writer, mode='ymodem1k', program="rzsz")
  • reader, reader(object) or read(function)
  • writer, writer(object) or write(function)
  • mode, support xmodem, xmodem1k, ymodem, ymodem1k(by default)
  • program, YMODEM of different program have different features

Send files

def send(self, file_paths, retry=10, timeout=10, callback=None)
  • file_paths: file path list.

  • retry: max retry count.

  • timeout: timeout of reader or writer in second.

  • callback: callback function. see below.

    Parameter Description
    task index index of current task
    task (file) name name of the file
    total packets number of packets plan to send
    success packets number of packets successfully sent
    failed packets number of packets failed to send

Receive files

def recv(self, folder_path, crc_mode=1, retry=10, timeout=10, delay=1, callback=None)
  • folder_path: folder path for saving.

  • crc_mode: checksum or crc mode.

  • retry: max retry count.

  • timeout: timeout of reader or writer in second.

  • delay: delay in second.

  • callback: callback function. see below.

    Parameter Description
    task index index of current task
    task (file) name name of the file
    total packets number of packets plan to send
    success packets number of packets successfully sent
    failed packets number of packets failed to send

Debug

If you want to output debugging information, set the log level to DEBUG.

logging.basicConfig(level=logging.DEBUG, format='%(message)s')

Changelog

v1.3 (2022/11/21 14:00 +00:00)

  • Support batch transmission
  • Simplify the API

License

MIT License

ymodem4python's People

Contributors

alexwoo1900 avatar crvux avatar otscher avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.