Skip to content

Commit 050b03c

Browse files
Sekenredhoomakethu
authored andcommitted
Add option to repl allowing Modbus RTU framing on a TCP socket (#447)
* repl: Allow Modbus RTU framing on a TCP socket * repl: Update README for framing option
1 parent e6da559 commit 050b03c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pymodbus/repl/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Usage: pymodbus.console tcp [OPTIONS]
4141
Options:
4242
--host TEXT Modbus TCP IP
4343
--port INTEGER Modbus TCP port
44+
--framer TEXT Override the default packet framer tcp|rtu
4445
--help Show this message and exit.
4546
4647

pymodbus/repl/main.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,19 @@ def main(ctx, verbose):
250250
type=int,
251251
help="Modbus TCP port",
252252
)
253-
def tcp(ctx, host, port):
253+
@click.option(
254+
"--framer",
255+
default='tcp',
256+
type=str,
257+
help="Override the default packet framer tcp|rtu",
258+
)
259+
def tcp(ctx, host, port, framer):
254260
from pymodbus.repl.client import ModbusTcpClient
255-
client = ModbusTcpClient(host=host, port=port)
261+
kwargs = dict(host=host, port=port)
262+
if framer == 'rtu':
263+
from pymodbus.framer.rtu_framer import ModbusRtuFramer
264+
kwargs['framer'] = ModbusRtuFramer
265+
client = ModbusTcpClient(**kwargs)
256266
cli(client)
257267

258268

0 commit comments

Comments
 (0)