Registry / http-networking / minimalmodbus

minimalmodbus

JSON →
library2.1.1pypypi✓ verified 85d ago

Easy-to-use Modbus RTU and Modbus ASCII implementation for Python. Version 2.1.1 supports Python >=3.8. Released semi-regularly, with a focus on simplicity and reliability for talking to Modbus devices over serial ports.

pip install minimalmodbus
INSTALL
IMPORT
SIG · MINIMALMODBUS
M
minimalmodbus
http-networkingpythonv2.1.1
Install
1.6s avg
Import
18ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.020s · 18.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.016s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Instrument
from minimalmodbus import Instrument
import minimalmodbus; inst = minimalmodbus.Instrument(...)
Wrong usage is uncommon but direct import is standard.

Quick example reading a Modbus register.

import minimalmodbus import serial instrument = minimalmodbus.Instrument('/dev/ttyUSB0', 1) # port, slave address instrument.serial.baudrate = 9600 instrument.serial.bytesize = 8 instrument.serial.parity = serial.PARITY_NONE instrument.serial.stopbits = 1 instrument.serial.timeout = 0.5 # Read temperature (register 0, signed 16-bit) temperature = instrument.read_register(0, 0, signed=True) print(temperature)
Debug
Known issues
breakingIn version 2.0.0, the 'minimalmodbus' module was restructured. The 'Instrument' class now requires explicit serial configuration. Old code using positional arguments for baudrate, parity etc. must be updated.
fix
Set serial parameters via the instrument.serial attribute after creation.
affects: >=2.0.0
gotchaModbus addresses are often 1-based in documentation but minimalmodbus uses 0-based register addresses. For example, holding register 40001 in Modbus maps to register address 0 in the library.
fix
Subtract 1 from usual Modbus addresses.
affects: all
gotchaThe library does not support Modbus TCP natively; it is serial-only. Users often try to pass a hostname and port, which fails.
fix
Use pymodbus for Modbus TCP, or use a serial-to-TCP converter.
affects: all
Errors
Common errors & fixes
ValueError: The slaveaddress 0 cannot be used.
Slave address must be between 1 and 247. Address 0 is reserved for broadcast.
fix
Use a slave address in range 1-247.
serial.serialutil.SerialException: [Errno 2] could not open port /dev/ttyUSB0: [Errno 2] No such file or directory: '/dev/ttyUSB0'
Serial port does not exist or is not accessible.
fix
Check the correct port name (e.g., /dev/ttyUSB0, COM3). On Linux, ensure user has dialout group permissions.
Upgrade
Version history
2.1.1latest on PyPI · released Jul 17, 2023
Audit
Dependencies
pyserialrequiredRequired for serial communication
Agent activity
2 hits · last 30 days
node
2
Resources
minimalmodbus — pip install minimalmodbus · libregistry