Skip to content

Commit

Permalink
1. Fix sync client and examples.
Browse files Browse the repository at this point in the history
2. Fix repl server errors
  • Loading branch information
dhoomakethu committed Aug 8, 2022
1 parent 6701233 commit d73ea4b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions examples/client_async_basic_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ async def handle_coils(client):
_logger.debug(txt)

_logger.info("### Reading Coils to get bit 5")
rr = await client.read_coils(1, 5)
rr = await client.read_coils(1, 5, unit=UNIT)
assert not rr.isError() # test that call was OK
txt = f"### coils response: {str(rr.bits)}"
_logger.debug(txt)

_logger.info("### Write true to coil bit 0 and read to verify")
rq = await client.write_coil(0, True)
rr = await client.read_coils(0, 1)
rq = await client.write_coil(0, True, unit=UNIT)
rr = await client.read_coils(0, 1, unit=UNIT)
assert not rq.isError() and not rr.isError() # test that calls was OK
assert rr.bits[0] # test the expected value
txt = f"### coils response: {str(rr.bits)}"
_logger.debug(txt)

_logger.info("### Write true to multiple coils 1-8")
rq = await client.write_coils(1, [True] * 8, unit=UNIT)
rq = await client.write_coils(1, [True] * 21, unit=UNIT)
rr = await client.read_coils(1, 21, unit=UNIT)
assert not rq.isError() and not rr.isError() # test that calls was OK
resp = [True] * 21
Expand Down
1 change: 0 additions & 1 deletion examples/client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
def setup_sync_client():
"""Run client setup."""
args = get_commandline()
args.comm = "serial"
_logger.info("### Create client object")
if args.comm == "tcp":
client = ModbusTcpClient(
Expand Down
8 changes: 4 additions & 4 deletions examples/client_sync_basic_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ def handle_coils(client):
_logger.debug(txt)

_logger.info("### Reading Coils to get bit 5")
rr = client.read_coils(1, 5)
rr = client.read_coils(1, 5, unit=UNIT)
assert not rr.isError() # test that call was OK
txt = f"### coils response: {str(rr.bits)}"
_logger.debug(txt)

_logger.info("### Write true to coil bit 0 and read to verify")
rq = client.write_coil(0, True)
rr = client.read_coils(0, 1)
rq = client.write_coil(0, True, unit=UNIT)
rr = client.read_coils(0, 1, unit=UNIT)
assert not rq.isError() and not rr.isError() # test that calls was OK
assert rr.bits[0] # test the expected value
txt = f"### coils response: {str(rr.bits)}"
_logger.debug(txt)

_logger.info("### Write true to multiple coils 1-8")
rq = client.write_coils(1, [True] * 8, unit=UNIT)
rq = client.write_coils(1, [True] * 21, unit=UNIT)
rr = client.read_coils(1, 21, unit=UNIT)
assert not rq.isError() and not rr.isError() # test that calls was OK
resp = [True] * 21
Expand Down
11 changes: 6 additions & 5 deletions pymodbus/repl/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import asyncio
import json
import logging
import typer
from typing import List
from pathlib import Path
from enum import Enum
import typer
from pymodbus.framer.socket_framer import ModbusSocketFramer
from pymodbus.repl.server.cli import run_repl
from pymodbus.server.reactive.default_config import DEFUALT_CONFIG
Expand Down Expand Up @@ -45,7 +46,7 @@ class ModbusFramerTypes(str, Enum):
binary = "binary" # pylint: disable=invalid-name


def _completer(incomplete: str, valid_values: list[str]) -> list[str]:
def _completer(incomplete: str, valid_values: List[str]) -> List[str]:
"""Complete value."""
completion = []
for name in valid_values:
Expand All @@ -54,13 +55,13 @@ def _completer(incomplete: str, valid_values: list[str]) -> list[str]:
return completion


def framers(incomplete: str) -> list[str]:
def framers(incomplete: str) -> List[str]:
"""Return an autocompleted list of supported clouds."""
_framers = ["socket", "rtu", "tls", "ascii", "binary"]
return _completer(incomplete, _framers)


def servers(incomplete: str) -> list[str]:
def servers(incomplete: str) -> List[str]:
"""Return an autocompleted list of supported clouds."""
_servers = ["tcp", "serial", "tls", "udp"]
return _completer(incomplete, _servers)
Expand Down Expand Up @@ -128,7 +129,7 @@ def run(
"--modbus-port",
"-p",
help='Modbus port'),
modbus_unit_id: list[int] = typer.Option(
modbus_unit_id: List[int] = typer.Option(
None,
"--unit-id",
"-u",
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _transact(
"""
last_exception = None
try:
self.client.connect()
self.client.start()
packet = self.client.framer.buildPacket(packet)
if _logger.isEnabledFor(logging.DEBUG):
txt = f"SEND: {hexlify_packets(packet)}"
Expand Down

0 comments on commit d73ea4b

Please sign in to comment.