# varionix/pycom-modbus architecture

> Architecture diagram of the GitHub repository varionix/pycom-modbus, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/varionix/pycom-modbus
- Repository: https://github.com/varionix/pycom-modbus

## Overview

uModbus is a small MicroPython Modbus client library with TCP and serial RTU transports. A caller selects a transport, invokes read or write operations, and receives decoded values or write-validation status. The example in main.py demonstrates WLAN setup and a TCP multiple-register write. Sampled source shows the transport and encoding paths; no README was provided, so capabilities are based on the exposed methods and source.

Main entry points: [`uModbus/tcp.py`](https://github.com/varionix/pycom-modbus/blob/master/uModbus/tcp.py) (TCP client), [`uModbus/serial.py`](https://github.com/varionix/pycom-modbus/blob/master/uModbus/serial.py) (Serial RTU client), [`main.py`](https://github.com/varionix/pycom-modbus/blob/master/main.py) (Example script), [`uModbus/functions.py`](https://github.com/varionix/pycom-modbus/blob/master/uModbus/functions.py) (PDU encoding)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Example entry"]
  node_example["Example script<br/>[main.py]"]
  node_wlan["WLAN network"]
end

subgraph group_protocol["Modbus protocol"]
  node_pdu["PDU encoding<br/>[functions.py]"]
  node_constants["Protocol constants<br/>[const.py]"]
end

subgraph group_transport["Transports"]
  node_tcp["TCP client<br/>[tcp.py]"]
  node_serial["Serial RTU client<br/>[serial.py]"]
end

node_caller(("Application caller"))
node_slave["Modbus slave"]

node_caller -->|"runs"| node_example
node_example -->|"connects via"| node_wlan
node_example -->|"creates and calls"| node_tcp
node_caller -->|"calls reads/writes"| node_tcp
node_caller -.->|"calls reads/writes"| node_serial
node_tcp -->|"builds and validates"| node_pdu
node_serial -->|"builds and validates"| node_pdu
node_pdu -->|"uses codes"| node_constants
node_tcp -->|"uses framing constants"| node_constants
node_serial -->|"uses RTU constants"| node_constants
node_tcp -->|"exchanges TCP frames"| node_slave
node_serial -.->|"exchanges RTU frames"| node_slave

click node_example "https://github.com/varionix/pycom-modbus/blob/master/main.py"
click node_tcp "https://github.com/varionix/pycom-modbus/blob/master/uModbus/tcp.py"
click node_serial "https://github.com/varionix/pycom-modbus/blob/master/uModbus/serial.py"
click node_pdu "https://github.com/varionix/pycom-modbus/blob/master/uModbus/functions.py"
click node_constants "https://github.com/varionix/pycom-modbus/blob/master/uModbus/const.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_example,node_wlan toneBlue
class node_pdu,node_constants toneAmber
class node_tcp,node_serial toneMint
class node_caller,node_slave toneIndigo
```

## Components

### Example entry

- [Example script](https://github.com/varionix/pycom-modbus/blob/master/main.py): `main.py`
- **WLAN network**

### Modbus protocol

- [PDU encoding](https://github.com/varionix/pycom-modbus/blob/master/uModbus/functions.py): `uModbus/functions.py`
- [Protocol constants](https://github.com/varionix/pycom-modbus/blob/master/uModbus/const.py): `uModbus/const.py`

### Transports

- [TCP client](https://github.com/varionix/pycom-modbus/blob/master/uModbus/tcp.py): `uModbus/tcp.py`
- [Serial RTU client](https://github.com/varionix/pycom-modbus/blob/master/uModbus/serial.py): `uModbus/serial.py`

### Other components

- **Application caller**
- **Modbus slave**

## Connections

- Application caller → Example script: runs
- Example script → WLAN network: connects via
- Example script → TCP client: creates and calls
- Application caller → TCP client: calls reads/writes
- Application caller → Serial RTU client: calls reads/writes
- TCP client → PDU encoding: builds and validates
- Serial RTU client → PDU encoding: builds and validates
- PDU encoding → Protocol constants: uses codes
- TCP client → Protocol constants: uses framing constants
- Serial RTU client → Protocol constants: uses RTU constants
- TCP client → Modbus slave: exchanges TCP frames
- Serial RTU client → Modbus slave: exchanges RTU frames
