Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eydam-prototyping/mp_modbus
Modbus Lib for Micropython
https://github.com/eydam-prototyping/mp_modbus
Last synced: 3 months ago
JSON representation
Modbus Lib for Micropython
- Host: GitHub
- URL: https://github.com/eydam-prototyping/mp_modbus
- Owner: eydam-prototyping
- License: mit
- Created: 2021-07-22T11:34:03.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-09-16T14:02:07.000Z (about 3 years ago)
- Last Synced: 2024-04-22T12:33:28.566Z (7 months ago)
- Language: Python
- Size: 53.7 KB
- Stars: 11
- Watchers: 2
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-micropython - mp_modbus - Modbus library for MicroPython. (Libraries / Communications)
README
# mp_modbus
Modbus Lib for Micropython## mp_modbus_frame
Create a modbus frame (you shouldn't have to do it by yourself):
```python
from mp_modbus_frame import modbus_rtu_frame, modbus_tcp_frame# RTU
rtu_frame = modbus_rtu_frame(
device_addr=1, # slave address
func_code=3, # function code
register=100, # requested register
length=2, # number of requested registers
fr_type="request" # type of frame
)# or parsing:
rtu_frame = modbus_rtu_frame.parse_frame(
bytearray([0x01, 0x03, 0x00, 0x12, 0x00, 0x08, 0xe4, 0x09])
)# TCP
tcp_frame = modbus_tcp_frame(
transaction_id=1, # transaction id
unit_id=1, # unit id
device_addr=1, # slave address
func_code=3, # function code
register=100, # requested register
length=2, # number of requested registers
fr_type="request" # type of frame
)# or parsing:
tcp_frame = modbus_tcp_frame.parse_frame(
bytearray([0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x01, 0x03,
0x00, 0x12, 0x00, 0x08])
)
```
## mp_modbus_masterRTU-Master or TCP-Client:
```python
from mp_modbus_master import modbus_rtu_master, modbus_tcp_client# RTU
rtu_master = modbus_rtu_master(
uart_no=2, parity=0, tx_pin=12, rx_pin=13, en_pin=32
)frame = rtu_master.read_holding_registers(305, 1)
print(frame.data)# TCP
```