Skip to content

Commit

Permalink
Modbus sync client timing enhancements #221
Browse files Browse the repository at this point in the history
 Fix TCP server #256, #260
  • Loading branch information
dhoomakethu committed Jan 13, 2018
1 parent 15bb3b3 commit 713fe5f
Show file tree
Hide file tree
Showing 13 changed files with 563 additions and 370 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
Version 1.5.0
------------------------------------------------------------
* 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

`client = Client(..., retry_on_empty=True)`

* Fix tcp servers (sync/async) not processing requests with transaction id > 255
* Introduce new api to check if the received response is an error or not (response.isError())
* Fix Misc examples

Version 1.4.0
------------------------------------------------------------
* Bug fix Modbus TCP client reading incomplete data
Expand Down
35 changes: 22 additions & 13 deletions examples/common/synchronous_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@
from pymodbus.datastore import ModbusSequentialDataBlock
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext

from pymodbus.transaction import ModbusRtuFramer
from pymodbus.transaction import ModbusRtuFramer, ModbusBinaryFramer
# --------------------------------------------------------------------------- #
# configure the service logging
# --------------------------------------------------------------------------- #
import logging
logging.basicConfig()
FORMAT = '%(asctime)-15s %(levelname)-8s %(module)-8s:%(lineno)-8s %(message)s'
logging.basicConfig(format=FORMAT)
log = logging.getLogger()
log.setLevel(logging.DEBUG)

SERIAL_PORT = "/tmp/ptyp0"
TCP_PORT = 5020


def run_server():
# ----------------------------------------------------------------------- #
Expand Down Expand Up @@ -85,11 +89,11 @@ def run_server():
# store = ModbusSlaveContext(..., zero_mode=True)
# ----------------------------------------------------------------------- #
store = ModbusSlaveContext(
di = ModbusSequentialDataBlock(0, [17]*100),
co = ModbusSequentialDataBlock(0, [17]*100),
hr = ModbusSequentialDataBlock(0, [17]*100),
ir = ModbusSequentialDataBlock(0, [17]*100))
context = ModbusServerContext(slaves=store, single=True)
di=ModbusSequentialDataBlock(0, [17]*100),
co=ModbusSequentialDataBlock(0, [17]*100),
hr=ModbusSequentialDataBlock(0, [17]*100),
ir=ModbusSequentialDataBlock(0, [17]*100))
context = ModbusServerContext(slaves={1: store, 2: store}, single=False)

# ----------------------------------------------------------------------- #
# initialize the server information
Expand All @@ -108,18 +112,23 @@ def run_server():
# run the server you want
# ----------------------------------------------------------------------- #
# Tcp:
StartTcpServer(context, identity=identity, address=("localhost", 5020))
StartTcpServer(context, identity=identity, address=("localhost", TCP_PORT))

# Udp:
# StartUdpServer(context, identity=identity, address=("localhost", 502))
# StartUdpServer(context, identity=identity,
# address=("localhost", TCP_PORT))

# Ascii:
# StartSerialServer(context, identity=identity,
# port='/dev/pts/3', timeout=1)

# StartSerialServer(context, identity=identity,
# port=SERIAL_PORT, timeout=1)

# Binary:
# StartSerialServer(context, identity=identity, framer=ModbusBinaryFramer,
# port=SERIAL_PORT, timeout=1)

# RTU:
# StartSerialServer(context, framer=ModbusRtuFramer, identity=identity,
# port='/dev/ptyp0', timeout=.005, baudrate=9600)
# port=SERIAL_PORT, timeout=.005, baudrate=9600)


if __name__ == "__main__":
Expand Down
13 changes: 13 additions & 0 deletions pymodbus/client/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@
from pymodbus.other_message import *


class ModbusTransactionState(object):
"""
Modbus Client States
"""
IDLE = 0
SENDING = 1
WAITING_FOR_REPLY = 2
WAITING_TURNAROUND_DELAY = 3
PROCESSING_REPLY = 4
PROCESSING_ERROR = 5
TRANSCATION_COMPLETE = 6


class ModbusClientMixin(object):
'''
This is a modbus client mixin that provides additional factory
Expand Down
Loading

0 comments on commit 713fe5f

Please sign in to comment.