Skip to content

Commit 713fe5f

Browse files
committed
Modbus sync client timing enhancements #221
Fix TCP server #256, #260
1 parent 15bb3b3 commit 713fe5f

File tree

13 files changed

+563
-370
lines changed

13 files changed

+563
-370
lines changed

CHANGELOG.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Version 1.5.0
2+
------------------------------------------------------------
3+
* Improve transaction speeds for sync clients (RTU/ASCII), now retry on empty happens only when retry_on_empty kwarg is passed to client during intialization
4+
5+
`client = Client(..., retry_on_empty=True)`
6+
7+
* Fix tcp servers (sync/async) not processing requests with transaction id > 255
8+
* Introduce new api to check if the received response is an error or not (response.isError())
9+
* Fix Misc examples
10+
111
Version 1.4.0
212
------------------------------------------------------------
313
* Bug fix Modbus TCP client reading incomplete data

examples/common/synchronous_server.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@
1919
from pymodbus.datastore import ModbusSequentialDataBlock
2020
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext
2121

22-
from pymodbus.transaction import ModbusRtuFramer
22+
from pymodbus.transaction import ModbusRtuFramer, ModbusBinaryFramer
2323
# --------------------------------------------------------------------------- #
2424
# configure the service logging
2525
# --------------------------------------------------------------------------- #
2626
import logging
27-
logging.basicConfig()
27+
FORMAT = '%(asctime)-15s %(levelname)-8s %(module)-8s:%(lineno)-8s %(message)s'
28+
logging.basicConfig(format=FORMAT)
2829
log = logging.getLogger()
2930
log.setLevel(logging.DEBUG)
3031

32+
SERIAL_PORT = "/tmp/ptyp0"
33+
TCP_PORT = 5020
34+
3135

3236
def run_server():
3337
# ----------------------------------------------------------------------- #
@@ -85,11 +89,11 @@ def run_server():
8589
# store = ModbusSlaveContext(..., zero_mode=True)
8690
# ----------------------------------------------------------------------- #
8791
store = ModbusSlaveContext(
88-
di = ModbusSequentialDataBlock(0, [17]*100),
89-
co = ModbusSequentialDataBlock(0, [17]*100),
90-
hr = ModbusSequentialDataBlock(0, [17]*100),
91-
ir = ModbusSequentialDataBlock(0, [17]*100))
92-
context = ModbusServerContext(slaves=store, single=True)
92+
di=ModbusSequentialDataBlock(0, [17]*100),
93+
co=ModbusSequentialDataBlock(0, [17]*100),
94+
hr=ModbusSequentialDataBlock(0, [17]*100),
95+
ir=ModbusSequentialDataBlock(0, [17]*100))
96+
context = ModbusServerContext(slaves={1: store, 2: store}, single=False)
9397

9498
# ----------------------------------------------------------------------- #
9599
# initialize the server information
@@ -108,18 +112,23 @@ def run_server():
108112
# run the server you want
109113
# ----------------------------------------------------------------------- #
110114
# Tcp:
111-
StartTcpServer(context, identity=identity, address=("localhost", 5020))
115+
StartTcpServer(context, identity=identity, address=("localhost", TCP_PORT))
112116

113117
# Udp:
114-
# StartUdpServer(context, identity=identity, address=("localhost", 502))
118+
# StartUdpServer(context, identity=identity,
119+
# address=("localhost", TCP_PORT))
115120

116121
# Ascii:
117-
# StartSerialServer(context, identity=identity,
118-
# port='/dev/pts/3', timeout=1)
119-
122+
# StartSerialServer(context, identity=identity,
123+
# port=SERIAL_PORT, timeout=1)
124+
125+
# Binary:
126+
# StartSerialServer(context, identity=identity, framer=ModbusBinaryFramer,
127+
# port=SERIAL_PORT, timeout=1)
128+
120129
# RTU:
121130
# StartSerialServer(context, framer=ModbusRtuFramer, identity=identity,
122-
# port='/dev/ptyp0', timeout=.005, baudrate=9600)
131+
# port=SERIAL_PORT, timeout=.005, baudrate=9600)
123132

124133

125134
if __name__ == "__main__":

pymodbus/client/common.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@
1515
from pymodbus.other_message import *
1616

1717

18+
class ModbusTransactionState(object):
19+
"""
20+
Modbus Client States
21+
"""
22+
IDLE = 0
23+
SENDING = 1
24+
WAITING_FOR_REPLY = 2
25+
WAITING_TURNAROUND_DELAY = 3
26+
PROCESSING_REPLY = 4
27+
PROCESSING_ERROR = 5
28+
TRANSCATION_COMPLETE = 6
29+
30+
1831
class ModbusClientMixin(object):
1932
'''
2033
This is a modbus client mixin that provides additional factory

0 commit comments

Comments
 (0)