pyModbusTCP-cli 0.4.0a1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ build/
2
+ dist/
3
+ *.pyc
4
+ *.egg-info/
5
+
6
+ /.idea/
7
+ /.vscode/
8
+
9
+ /venv/
10
+ /lab/
11
+
12
+ # Sphinx documentation (built pages and generated help of the tools)
13
+ /docs/_build/
14
+ /docs/_generated/
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 l.lefebvre
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,110 @@
1
+ Metadata-Version: 2.5
2
+ Name: pyModbusTCP-cli
3
+ Version: 0.4.0a1
4
+ Summary: Command line tools for pyModbusTCP: Modbus/TCP server, client and Modbus TCP/RTU gateways
5
+ Project-URL: Source, https://github.com/sourceperl/pyModbusTCP
6
+ Project-URL: Issues, https://github.com/sourceperl/pyModbusTCP/issues
7
+ Author: Loïc Lefebvre
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Topic :: System :: Networking
16
+ Requires-Python: >=3.10
17
+ Requires-Dist: pymodbustcp[serial]==0.4.0a1
18
+ Description-Content-Type: text/markdown
19
+
20
+ # pyModbusTCP-cli
21
+
22
+ Command line tools built on [pyModbusTCP](https://github.com/sourceperl/pyModbusTCP):
23
+
24
+ | Command | Role |
25
+ |------------------|----------------------------------------------------------------------------|
26
+ | `mbtcp-server` | Modbus/TCP server (test a client, a SCADA, a gateway...) |
27
+ | `mbtcp-client` | Modbus/TCP client: read and write requests from the command line |
28
+ | `mbtcp-tcp2rtu` | gateway: Modbus/TCP clients -> Modbus/RTU slaves on a serial line |
29
+ | `mbtcp-rtu2tcp` | gateway: a Modbus/RTU master on a serial line -> a Modbus/TCP server |
30
+
31
+ The code of the tools is in the pyModbusTCP library (module `pyModbusTCP.tools`). This package contains no code:
32
+ it only adds the commands to the PATH, with pyserial for the gateways. So a plain `pip install pyModbusTCP` puts no
33
+ command in the PATH and installs no dependency.
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ # as isolated command line tools (recommended)
39
+ pipx install pyModbusTCP-cli
40
+
41
+ # or in a virtual environment, with the library
42
+ pip install "pyModbusTCP[tools]==0.4.0a1"
43
+ ```
44
+
45
+ **Alpha**: pyModbusTCP-cli is new with pyModbusTCP 0.4.0, only pre-releases exist for now. The commands, their
46
+ options and their output may still change before the final release. Without a version or `--pre`,
47
+ `pip install "pyModbusTCP[tools]"` installs the stable pyModbusTCP 0.3.1, without the tools.
48
+
49
+ Without this package, the tools can still be run from the library alone:
50
+
51
+ ```bash
52
+ python -m pyModbusTCP.tools server --help
53
+ python -m pyModbusTCP.tools client --help
54
+ pip install "pyModbusTCP[serial]==0.4.0a1" # pyserial, only needed by the gateways
55
+ python -m pyModbusTCP.tools tcp2rtu --help
56
+ python -m pyModbusTCP.tools rtu2tcp --help
57
+ ```
58
+
59
+ ## Examples
60
+
61
+ ```bash
62
+ # server on localhost:5020, log the writes of the clients
63
+ mbtcp-server --log-changes
64
+
65
+ # read 4 holding registers from address 0, write some values
66
+ mbtcp-client -p 5020 read-holding 0 -n 4
67
+ mbtcp-client -p 5020 write-registers 0 100 200 0x1234
68
+ mbtcp-client -p 5020 write-coil 10 on
69
+
70
+ # TCP clients of the 192.168.1.0/24 network can read (only) the RTU slaves of /dev/ttyUSB0
71
+ mbtcp-tcp2rtu -H 0.0.0.0 -A 192.168.1.0/24 --read-only -b 19200 --parity E /dev/ttyUSB0
72
+
73
+ # a RTU master on /dev/ttyUSB0 reads the Modbus/TCP server 192.168.1.10 (gateway is RTU slave 30)
74
+ mbtcp-rtu2tcp -a 30 -H 192.168.1.10 /dev/ttyUSB0
75
+ ```
76
+
77
+ Run any command with `--help` for all its options.
78
+
79
+ ## Security
80
+
81
+ Modbus/TCP has no authentication and no encryption: any host that can reach a server can read and write its data.
82
+ The server and the TCP to RTU gateway are designed to be safe by default:
83
+
84
+ - they listen on `localhost` and on port 5020 by default: use `-H` with the address of the network interface that
85
+ needs it (`0.0.0.0` only if every network of the host is trusted);
86
+ - `-A/--allow` restricts the clients to some IP addresses or networks, `--read-only` refuses every write;
87
+ - the TCP to RTU gateway refuses broadcast requests (unit id 0) unless `--allow-broadcast` is set.
88
+
89
+ Port 502 (the standard Modbus/TCP port) is a privileged port on Unix systems. **Never run these commands as root (or
90
+ with sudo) to listen on it.** Give the `CAP_NET_BIND_SERVICE` capability to the Python interpreter of a virtual
91
+ environment dedicated to the tools instead:
92
+
93
+ ```bash
94
+ python3 -m venv --copies ~/mbtcp-venv # --copies: real interpreter files, not links to the system one
95
+ ~/mbtcp-venv/bin/pip install pyModbusTCP-cli
96
+ sudo setcap 'cap_net_bind_service=+ep' ~/mbtcp-venv/bin/python3
97
+ ~/mbtcp-venv/bin/mbtcp-server -H 192.168.1.10 -p 502
98
+ ```
99
+
100
+ The commands of this virtual environment run its `bin/python3`, the file with the capability. This does not work
101
+ with pipx, whose environments use links to the system interpreter (`setcap` refuses them). See "Listen on the standard
102
+ Modbus port 502 without root" in the [examples README](https://github.com/sourceperl/pyModbusTCP/tree/master/examples)
103
+ for the details and the precautions.
104
+
105
+ See also the [security policy](https://github.com/sourceperl/pyModbusTCP/blob/master/SECURITY.md) of pyModbusTCP.
106
+
107
+ ## Versions
108
+
109
+ pyModbusTCP-cli has the version of pyModbusTCP and requires exactly this release of the library (where its code
110
+ is).
@@ -0,0 +1,91 @@
1
+ # pyModbusTCP-cli
2
+
3
+ Command line tools built on [pyModbusTCP](https://github.com/sourceperl/pyModbusTCP):
4
+
5
+ | Command | Role |
6
+ |------------------|----------------------------------------------------------------------------|
7
+ | `mbtcp-server` | Modbus/TCP server (test a client, a SCADA, a gateway...) |
8
+ | `mbtcp-client` | Modbus/TCP client: read and write requests from the command line |
9
+ | `mbtcp-tcp2rtu` | gateway: Modbus/TCP clients -> Modbus/RTU slaves on a serial line |
10
+ | `mbtcp-rtu2tcp` | gateway: a Modbus/RTU master on a serial line -> a Modbus/TCP server |
11
+
12
+ The code of the tools is in the pyModbusTCP library (module `pyModbusTCP.tools`). This package contains no code:
13
+ it only adds the commands to the PATH, with pyserial for the gateways. So a plain `pip install pyModbusTCP` puts no
14
+ command in the PATH and installs no dependency.
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ # as isolated command line tools (recommended)
20
+ pipx install pyModbusTCP-cli
21
+
22
+ # or in a virtual environment, with the library
23
+ pip install "pyModbusTCP[tools]==0.4.0a1"
24
+ ```
25
+
26
+ **Alpha**: pyModbusTCP-cli is new with pyModbusTCP 0.4.0, only pre-releases exist for now. The commands, their
27
+ options and their output may still change before the final release. Without a version or `--pre`,
28
+ `pip install "pyModbusTCP[tools]"` installs the stable pyModbusTCP 0.3.1, without the tools.
29
+
30
+ Without this package, the tools can still be run from the library alone:
31
+
32
+ ```bash
33
+ python -m pyModbusTCP.tools server --help
34
+ python -m pyModbusTCP.tools client --help
35
+ pip install "pyModbusTCP[serial]==0.4.0a1" # pyserial, only needed by the gateways
36
+ python -m pyModbusTCP.tools tcp2rtu --help
37
+ python -m pyModbusTCP.tools rtu2tcp --help
38
+ ```
39
+
40
+ ## Examples
41
+
42
+ ```bash
43
+ # server on localhost:5020, log the writes of the clients
44
+ mbtcp-server --log-changes
45
+
46
+ # read 4 holding registers from address 0, write some values
47
+ mbtcp-client -p 5020 read-holding 0 -n 4
48
+ mbtcp-client -p 5020 write-registers 0 100 200 0x1234
49
+ mbtcp-client -p 5020 write-coil 10 on
50
+
51
+ # TCP clients of the 192.168.1.0/24 network can read (only) the RTU slaves of /dev/ttyUSB0
52
+ mbtcp-tcp2rtu -H 0.0.0.0 -A 192.168.1.0/24 --read-only -b 19200 --parity E /dev/ttyUSB0
53
+
54
+ # a RTU master on /dev/ttyUSB0 reads the Modbus/TCP server 192.168.1.10 (gateway is RTU slave 30)
55
+ mbtcp-rtu2tcp -a 30 -H 192.168.1.10 /dev/ttyUSB0
56
+ ```
57
+
58
+ Run any command with `--help` for all its options.
59
+
60
+ ## Security
61
+
62
+ Modbus/TCP has no authentication and no encryption: any host that can reach a server can read and write its data.
63
+ The server and the TCP to RTU gateway are designed to be safe by default:
64
+
65
+ - they listen on `localhost` and on port 5020 by default: use `-H` with the address of the network interface that
66
+ needs it (`0.0.0.0` only if every network of the host is trusted);
67
+ - `-A/--allow` restricts the clients to some IP addresses or networks, `--read-only` refuses every write;
68
+ - the TCP to RTU gateway refuses broadcast requests (unit id 0) unless `--allow-broadcast` is set.
69
+
70
+ Port 502 (the standard Modbus/TCP port) is a privileged port on Unix systems. **Never run these commands as root (or
71
+ with sudo) to listen on it.** Give the `CAP_NET_BIND_SERVICE` capability to the Python interpreter of a virtual
72
+ environment dedicated to the tools instead:
73
+
74
+ ```bash
75
+ python3 -m venv --copies ~/mbtcp-venv # --copies: real interpreter files, not links to the system one
76
+ ~/mbtcp-venv/bin/pip install pyModbusTCP-cli
77
+ sudo setcap 'cap_net_bind_service=+ep' ~/mbtcp-venv/bin/python3
78
+ ~/mbtcp-venv/bin/mbtcp-server -H 192.168.1.10 -p 502
79
+ ```
80
+
81
+ The commands of this virtual environment run its `bin/python3`, the file with the capability. This does not work
82
+ with pipx, whose environments use links to the system interpreter (`setcap` refuses them). See "Listen on the standard
83
+ Modbus port 502 without root" in the [examples README](https://github.com/sourceperl/pyModbusTCP/tree/master/examples)
84
+ for the details and the precautions.
85
+
86
+ See also the [security policy](https://github.com/sourceperl/pyModbusTCP/blob/master/SECURITY.md) of pyModbusTCP.
87
+
88
+ ## Versions
89
+
90
+ pyModbusTCP-cli has the version of pyModbusTCP and requires exactly this release of the library (where its code
91
+ is).
@@ -0,0 +1,16 @@
1
+ """Build of pyModbusTCP-cli: require exactly the release of pyModbusTCP of the same version.
2
+
3
+ The version itself is read from ../pyModbusTCP/constants.py by hatchling ([tool.hatch.version] of pyproject.toml), so
4
+ the two packages of the repository can't get out of sync. A build from the sdist of pyModbusTCP-cli (where the
5
+ library sources are not available) takes the version and the dependencies from PKG-INFO, without this hook.
6
+ """
7
+
8
+ from typing import Any
9
+
10
+ from hatchling.metadata.plugin.interface import MetadataHookInterface
11
+
12
+
13
+ class CustomMetadataHook(MetadataHookInterface):
14
+ def update(self, metadata: dict[str, Any]) -> None:
15
+ # the code of the commands is in the library: exactly the same release
16
+ metadata['dependencies'] = ['pyModbusTCP[serial]==%s' % metadata['version']]
@@ -0,0 +1,47 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ # This package contains no code: it only installs the commands of the tools of pyModbusTCP (module pyModbusTCP.tools)
6
+ # and their optional dependency (pyserial). A plain "pip install pyModbusTCP" puts no command in the PATH.
7
+
8
+ [project]
9
+ name = "pyModbusTCP-cli"
10
+ # version: the one of pyModbusTCP (../pyModbusTCP/constants.py, see [tool.hatch.version]), the two packages are always
11
+ # released together with the same version; dependencies: exactly this release of pyModbusTCP (set by hatch_build.py)
12
+ dynamic = ["version", "dependencies"]
13
+ description = "Command line tools for pyModbusTCP: Modbus/TCP server, client and Modbus TCP/RTU gateways"
14
+ readme = "README.md"
15
+ requires-python = ">=3.10"
16
+ authors = [{ name = "Loïc Lefebvre" }]
17
+ license = "MIT"
18
+ license-files = ["LICENSE*"]
19
+ classifiers = [
20
+ "Development Status :: 3 - Alpha",
21
+ "Environment :: Console",
22
+ "Intended Audience :: Developers",
23
+ "Operating System :: OS Independent",
24
+ "Programming Language :: Python :: 3 :: Only",
25
+ "Topic :: System :: Networking",
26
+ ]
27
+
28
+ [project.scripts]
29
+ mbtcp-server = "pyModbusTCP.tools._entry:run_server"
30
+ mbtcp-client = "pyModbusTCP.tools._entry:run_client"
31
+ mbtcp-tcp2rtu = "pyModbusTCP.tools._entry:run_tcp2rtu"
32
+ mbtcp-rtu2tcp = "pyModbusTCP.tools._entry:run_rtu2tcp"
33
+
34
+ [project.urls]
35
+ Source = "https://github.com/sourceperl/pyModbusTCP"
36
+ Issues = "https://github.com/sourceperl/pyModbusTCP/issues"
37
+
38
+ [tool.hatch.version]
39
+ # from the repository; a build from the sdist (no ../pyModbusTCP) reads the version and the dependencies in PKG-INFO
40
+ path = "../pyModbusTCP/constants.py"
41
+
42
+ [tool.hatch.metadata.hooks.custom]
43
+ # hatch_build.py: requirement on exactly this release of pyModbusTCP
44
+
45
+ [tool.hatch.build.targets.wheel]
46
+ # no code in this package (see above): only the metadata and the commands
47
+ bypass-selection = true