Skip to main content

Ymodem Python3 implementation

Reason this release was yanked:

have issues

Project description

ymodem-logo

Fork of the YMODEM project by alexwoo1900 Now available on PyPi, also now it can be used as cli tool for Serial ports The YMODEM project is based on XMODEM implementation written by tehmaze. It is also compatible with XMODEM mode.

license PyPI Version

README: ENGLISH | 简体中文

Installation

pip install ymodem

Usage

CLI TOOL

# To get help
ymodem -h
# or
python -m ymodem -h

Sending a batch of files

ymodem send ./file.bin ./file2.bin -p COM4 -b 115200
# or
python -m ymodem send ./file.bin ./file2.bin -p COM4 -b 115200

Receive a file

ymodem recv ./ -p COM4 -b 115200
# or
python -m ymodem recv ./ -p COM4 -b 115200

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 ymodem.Socket import ModemSocket

# define read
def read(size, timeout = 3):
    # implementation

# define write
def write(data, timeout = 3):
    # implementation

# create socket
cli = ModemSocket(read, write)

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

# receive multi files
cli.recv(folder_path)

For more detailed usage, please refer to the demo/FileReceiver.py and demo/FileSender.py files.

API

Create MODEM Object

def __init__(self, 
             read: Callable[[int, Optional[float]], Any], 
             write: Callable[[Union[bytes, bytearray], Optional[float]], Any], 
             protocol_type: int = ProtocolType.YMODEM, 
             protocol_type_options: List[str] = [],
             packet_size: int = 1024,
             style_id: int = _psm.get_available_styles()[0]):
  • protocol_type: Protocol type, see Protocol.py
  • protocol_type_options: such as g representing the YMODEM-G in the YMODEM protocol.
  • packet_size: The size of a single packet, 128/1024 bytes, may be adjusted depending on the protocol style
  • style_id: Protocol style, different styles have different support for functional features

Send files

def send(self, 
         paths: List[str], 
         callback: Optional[Callable[[int, str, int, int], None]] = None
        ) -> bool:
  • 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

Receive files

def recv(self, 
         path: str, 
         callback: Optional[Callable[[int, str, int, int], None]] = None
        ) -> bool:
  • callback: callback function. Same as the callback of 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.5.1b1 (2024/02/03)

  • Added additional options to cli tool

v1.5.1b0 (2024/02/03)

  • Added cli tool to iteract with YMODEM via Serial bus
  • Fix of transaction end logic in send()

v1.5 (2023/05/20 11:00 +00:00)

  • Rewritten send() and recv()
  • Support YMODEM-G. The success rate of YMODEM-G based on pyserial depends on the user's OS, and after testing, the success rate is very low without any delay.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ymodem-1.5.1b1.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

ymodem-1.5.1b1-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file ymodem-1.5.1b1.tar.gz.

File metadata

  • Download URL: ymodem-1.5.1b1.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for ymodem-1.5.1b1.tar.gz
Algorithm Hash digest
SHA256 2b0d71e15906e92968c4b5a1d93283eb0058a2fedf59217afe19f316fa1cb65f
MD5 a4c904ed2f06f698645d97b924f435c4
BLAKE2b-256 c3aaeaa7ff213a7c9d0c8e637d2b064fc4f9a50d1d6d537ff0d90ff716634010

See more details on using hashes here.

File details

Details for the file ymodem-1.5.1b1-py3-none-any.whl.

File metadata

  • Download URL: ymodem-1.5.1b1-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for ymodem-1.5.1b1-py3-none-any.whl
Algorithm Hash digest
SHA256 1154a06aac43e009bd07a85e74180eed187fd064ee7aa98f4b84df7c0bcb27ae
MD5 46d4bc5ee5ff3bee42e502f0172194ef
BLAKE2b-256 d3af074786e132b0e085f7c729b34da16934d5093477a4ec98f33f4bf5397974

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page