Skip to content

Commit c27c312

Browse files
committed
message classes.
1 parent 6b795f1 commit c27c312

File tree

18 files changed

+300
-60
lines changed

18 files changed

+300
-60
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
*.db
21
*.pyc
32
*.swp
43
__pycache__/

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Welcome to PyModbus's documentation!
1414
changelog.rst
1515
source/library/client.rst
1616
source/library/server.rst
17+
source/library/nullmodem.rst
1718
source/library/simulator/simulator
1819
source/library/REPL
1920
source/library/datastore.rst

doc/source/library/nullmodem.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
NullModem
2+
=========
3+
4+
Pymodbus offers a special NullModem transport to help end-to-end test without network.
5+
6+
The NullModem is activated by setting host= (port= for serial) to NULLMODEM_HOST (import pymodbus.transport)
7+
8+
The NullModem works with the normal transport types, and simply substitutes the physical connection:
9+
- *Serial* (RS-485) typically using a dongle
10+
- *TCP*
11+
- *TLS*
12+
- *UDP*
13+
14+
The NullModem is currently integrated in
15+
- :mod:`Modbus<x>Client`
16+
- :mod:`AsyncModbus<x>Client`
17+
- :mod:`Modbus<x>Server`
18+
- :mod:`AsyncModbus<x>Server`
19+
20+
Of course the NullModem requires that server and client(s) run in the same python instance.

pymodbus/client/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from pymodbus.logging import Log
1414
from pymodbus.pdu import ModbusRequest, ModbusResponse
1515
from pymodbus.transaction import DictTransactionManager
16-
from pymodbus.transport.transport import CommParams, ModbusProtocol
16+
from pymodbus.transport import CommParams, ModbusProtocol
1717
from pymodbus.utilities import ModbusTransactionState
1818

1919

pymodbus/client/serial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pymodbus.framer import ModbusFramer
1111
from pymodbus.framer.rtu_framer import ModbusRtuFramer
1212
from pymodbus.logging import Log
13-
from pymodbus.transport.transport import CommType
13+
from pymodbus.transport import CommType
1414
from pymodbus.utilities import ModbusTransactionState
1515

1616

pymodbus/client/tcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pymodbus.framer import ModbusFramer
1111
from pymodbus.framer.socket_framer import ModbusSocketFramer
1212
from pymodbus.logging import Log
13-
from pymodbus.transport.transport import CommType
13+
from pymodbus.transport import CommType
1414
from pymodbus.utilities import ModbusTransactionState
1515

1616

pymodbus/client/tls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pymodbus.framer import ModbusFramer
88
from pymodbus.framer.tls_framer import ModbusTlsFramer
99
from pymodbus.logging import Log
10-
from pymodbus.transport.transport import CommParams, CommType
10+
from pymodbus.transport import CommParams, CommType
1111

1212

1313
class AsyncModbusTlsClient(AsyncModbusTcpClient):

pymodbus/client/udp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pymodbus.framer import ModbusFramer
99
from pymodbus.framer.socket_framer import ModbusSocketFramer
1010
from pymodbus.logging import Log
11-
from pymodbus.transport.transport import CommType
11+
from pymodbus.transport import CommType
1212

1313

1414
DGRAM_TYPE = socket.SOCK_DGRAM

pymodbus/server/async_io.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
ModbusSocketFramer,
2020
ModbusTlsFramer,
2121
)
22-
from pymodbus.transport.transport import CommParams, CommType, ModbusProtocol
22+
from pymodbus.transport import CommParams, CommType, ModbusProtocol
2323

2424

2525
with suppress(ImportError):
@@ -296,6 +296,7 @@ def __init__(
296296
reconnect_delay=0.0,
297297
reconnect_delay_max=0.0,
298298
timeout_connect=0.0,
299+
new_connection_class=lambda: ModbusServerRequestHandler(self),
299300
),
300301
)
301302
params.source_address = address
@@ -322,10 +323,6 @@ def __init__(
322323
# defer the initialization of the server
323324
self.handle_local_echo = False
324325

325-
def handle_new_connection(self):
326-
"""Handle incoming connect."""
327-
return ModbusServerRequestHandler(self)
328-
329326
async def serve_forever(self):
330327
"""Start endless loop."""
331328
if self.transport:
@@ -408,6 +405,7 @@ def __init__( # pylint: disable=too-many-arguments
408405
sslctx=CommParams.generate_ssl(
409406
True, certfile, keyfile, password, sslctx=sslctx
410407
),
408+
new_connection_class=lambda: ModbusServerRequestHandler(self),
411409
)
412410
super().__init__(
413411
context,
@@ -468,6 +466,7 @@ def __init__(
468466
reconnect_delay=0.0,
469467
reconnect_delay_max=0.0,
470468
timeout_connect=0.0,
469+
new_connection_class=lambda: ModbusServerRequestHandler(self),
471470
),
472471
True,
473472
)
@@ -490,10 +489,6 @@ def __init__(
490489
self.request_tracer = None
491490
self.handle_local_echo = False
492491

493-
def handle_new_connection(self):
494-
"""Handle incoming connect."""
495-
return ModbusServerRequestHandler(self)
496-
497492
async def serve_forever(self):
498493
"""Start endless loop."""
499494
if self.transport:
@@ -570,6 +565,7 @@ def __init__(
570565
parity=kwargs.get("parity", "N"),
571566
baudrate=kwargs.get("baudrate", 19200),
572567
stopbits=kwargs.get("stopbits", 1),
568+
new_connection_class=lambda: ModbusServerRequestHandler(self),
573569
),
574570
True,
575571
)
@@ -595,10 +591,6 @@ def __init__(
595591
async def start(self):
596592
"""Start connecting."""
597593

598-
def handle_new_connection(self):
599-
"""Handle incoming connect."""
600-
return ModbusServerRequestHandler(self)
601-
602594
async def shutdown(self):
603595
"""Terminate server."""
604596
self.transport_close()

pymodbus/transport/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
11
"""Transport."""
2+
3+
__all__ = [
4+
"CommType",
5+
"CommParams",
6+
"ModbusProtocol",
7+
"NullModem",
8+
"NULLMODEM_HOST",
9+
"ModbusMessage",
10+
"CommFrameType",
11+
]
12+
13+
from pymodbus.transport.message import CommFrameType, ModbusMessage
14+
from pymodbus.transport.transport import (
15+
NULLMODEM_HOST,
16+
CommParams,
17+
CommType,
18+
ModbusProtocol,
19+
NullModem,
20+
)

0 commit comments

Comments
 (0)