Ymodem Python3 implementation
Project description
The YMODEM project is based on XMODEM implementation written by tehmaze. It is also compatible with XMODEM mode.
Demo
Test the sending and receiving functions
Interact with SecureCRT
Interact with SecureCRT as sender
Interact with SecureCRT as Finder
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
Source Code
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 main.py.
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:
- path: folder path for storing the target file
- callback: callback function. Same as the callback of send().
ATTENTION
Depending on different communication environments, developers may need to manually adjust timeout parameters in _read_and_wait or _write_and_wait.
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 (2024/02/03)
- Added cli tool to iteract with YMODEM via Serial bus
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
Project details
Release history Release notifications | RSS feed
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.1.tar.gz
(22.1 kB
view details)
Built Distribution
ymodem-1.5.1-py3-none-any.whl
(21.4 kB
view details)
File details
Details for the file ymodem-1.5.1.tar.gz
.
File metadata
- Download URL: ymodem-1.5.1.tar.gz
- Upload date:
- Size: 22.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4373cd6c8d29629495dbffdd9ed187b07f27381231d55d3a137025320d5ce67 |
|
MD5 | 643e809558a4393936564ac6594ee9d6 |
|
BLAKE2b-256 | dfdbd96a2c259933916bc5062b8f8a297493fcbe44bd9a0f42579cc5f532f9b2 |
File details
Details for the file ymodem-1.5.1-py3-none-any.whl
.
File metadata
- Download URL: ymodem-1.5.1-py3-none-any.whl
- Upload date:
- Size: 21.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55fccfe7243e35bc96d70d6c8778f4ddd1a23f61ea5404cf30470cc5ffe900b3 |
|
MD5 | b758206a73f8fa92ba5bcba1d7cd0964 |
|
BLAKE2b-256 | 90449f09d0efaddcc253b4b35fbe26bf419aa40c15f0554df3fbffdf5f5404a3 |