Skip to content

Commit

Permalink
Merge pull request #329 from riptideio/pymodbus-repl
Browse files Browse the repository at this point in the history
Pymodbus repl
  • Loading branch information
dhoomakethu authored Sep 21, 2018
2 parents 7a0ad56 + c201144 commit c9e8d75
Show file tree
Hide file tree
Showing 19 changed files with 1,581 additions and 78 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
omit =
pymodbus/repl/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ test/__pycache__/
/doc/html/
/doc/_build/
.pytest_cache/
/.pymodhis
1 change: 1 addition & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ requirements_file: requirements-docs.txt
python:
extra_requirements:
- twisted
- torndo
- documents
version: 3.5
14 changes: 14 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
Version 2.0.0rc2
-----------------------------------------------------------
**Note This is a Major release and might affect your existing Async client implementation. Refer examples on how to use the latest async clients.**

* Async client implementation based on Tornado, Twisted and asyncio with backward compatibility support for twisted client.
* Allow reusing existing[running] asyncio loop when creating async client based on asyncio.
* Allow reusing address for Modbus TCP sync server.
* Add support to install tornado as extra requirement while installing pymodbus.
* Support Pymodbus REPL
* Add support to python 3.7.
* Bug fix and enhancements in examples.


Version 2.0.0rc1
-----------------------------------------------------------
**Note This is a Major release and might affect your existing Async client implementation. Refer examples on how to use the latest async clients.**

* Async client implementation based on Tornado, Twisted and asyncio


Version 1.5.2
------------------------------------------------------------
* Fix serial client `is_socket_open` method
Expand Down
42 changes: 29 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ Client Features
* Full read/write protocol on discrete and register
* Most of the extended protocol (diagnostic/file/pipe/setting/information)
* TCP, UDP, Serial ASCII, Serial RTU, and Serial Binary
* asynchronous(powered by twisted) and synchronous versions
* asynchronous(powered by twisted/tornado/asyncio) and synchronous versions
* Payload builder/decoder utilities
* Pymodbus REPL for quick tests

------------------------------------------------------------
Server Features
Expand Down Expand Up @@ -93,9 +94,21 @@ trace them. I get a lot of email and sometimes these requests
get lost in the noise: http://groups.google.com/group/pymodbus or
at gitter: https://gitter.im/pymodbus_dev/Lobby

------------------------------------------------------------
============================================================
Pymodbus REPL (Read Evaluate Procee Loop)
============================================================
Starting with Pymodbus 2.x, pymodbus library comes with handy
Pymodbus REPL to quickly run the modbus clients in tcp/rtu modes.

Pymodbus REPL comes with many handy features such as payload decoder
to directly retrieve the values in desired format and supports all
the diagnostic function codes directly .

For more info on REPL refer `Pymodbus REPL <pymodbus/repl/README.md>`_

============================================================
Installing
------------------------------------------------------------
============================================================

You can install using pip or easy install by issuing the following
commands in a terminal window (make sure you have correct
Expand All @@ -104,15 +117,18 @@ permissions or a virtualenv currently running)::
easy_install -U pymodbus
pip install -U pymodbus

To Install pymodbus with twisted support run
.. code-block:: python
To Install pymodbus with twisted support run::

pip install -U pymodbus[twisted]

To Install pymodbus with tornado support run
To Install pymodbus with tornado support run::

.. code-block:: python
pip install -U pymodbus[tornado]

To Install pymodbus REPL::

pip install -U pymodbus[repl]

Otherwise you can pull the trunk source and install from there::

git clone git://github.com/bashwork/pymodbus.git
Expand All @@ -128,9 +144,9 @@ out all mentions of twisted. It should be noted that without twisted,
one will only be able to run the synchronized version as the
asynchronous versions uses twisted for its event loop.

------------------------------------------------------------
============================================================
Current Work In Progress
------------------------------------------------------------
============================================================

Since I don't have access to any live modbus devices anymore
it is a bit hard to test on live hardware. However, if you would
Expand Down Expand Up @@ -166,14 +182,14 @@ Use make to perform a range of activities
make tox run the tests on all Python versions
make clean cleanup all temporary files

------------------------------------------------------------
============================================================
Contributing
------------------------------------------------------------
============================================================
Just fork the repo and raise your PR against `dev` branch.

------------------------------------------------------------
============================================================
License Information
------------------------------------------------------------
============================================================

Pymodbus is built on top of code developed from/by:
* Copyright (c) 2001-2005 S.W.A.C. GmbH, Germany.
Expand Down
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Welcome to PyModbus's documentation!

readme.rst
changelog.rst
repl.rst
source/example/modules.rst
source/library/modules.rst

Expand Down
4 changes: 4 additions & 0 deletions doc/repl.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Pymodbus REPL
=============

.. mdinclude:: ../pymodbus/repl/README.md
44 changes: 44 additions & 0 deletions doc/source/library/pymodbus.repl.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
pymodbus\.repl package
==========================

.. automodule:: pymodbus.repl
:members:
:undoc-members:
:show-inheritance:


Submodules
----------

pymodbus\.repl\.client module
-----------------------------------

.. automodule:: pymodbus.repl.client
:members:
:undoc-members:
:show-inheritance:

pymodbus\.repl\.completer module
-----------------------------------

.. automodule:: pymodbus.repl.completer
:members:
:undoc-members:
:show-inheritance:

pymodbus\.repl\.helper module
-----------------------------------

.. automodule:: pymodbus.repl.helper
:members:
:undoc-members:
:show-inheritance:


pymodbus\.repl\.main module
-----------------------------------

.. automodule:: pymodbus.repl.main
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions doc/source/library/pymodbus.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Subpackages
pymodbus.framer
pymodbus.internal
pymodbus.server
pymodbus.repl


Submodules
Expand Down
107 changes: 44 additions & 63 deletions pymodbus/compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Python 2.x/3.x Compatibility Layer
-------------------------------------------------
Expand All @@ -10,87 +10,68 @@
:copyright: Copyright 2013 by the Jinja team, see AUTHORS.
:license: BSD, see LICENSE for details.
'''
"""
import sys
import struct
import six

#---------------------------------------------------------------------------#
# --------------------------------------------------------------------------- #
# python version checks
#---------------------------------------------------------------------------#
# --------------------------------------------------------------------------- #
PYTHON_VERSION = sys.version_info
IS_PYTHON2 = PYTHON_VERSION[0] == 2
IS_PYTHON3 = PYTHON_VERSION[0] == 3
IS_PYPY = hasattr(sys, 'pypy_translation_info')
IS_JYTHON = sys.platform.startswith('java')
IS_PYTHON2 = six.PY2
IS_PYTHON3 = six.PY3
IS_PYPY = hasattr(sys, 'pypy_translation_info')
IS_JYTHON = sys.platform.startswith('java')

#---------------------------------------------------------------------------#
# python > 3.3 compatability layer
#---------------------------------------------------------------------------#
if not IS_PYTHON2:
#-----------------------------------------------------------------------#
# portable builtins
#-----------------------------------------------------------------------#
int2byte = lambda b: struct.pack('B', b)
byte2int = lambda b: b
unichr = chr
range_type = range
text_type = str
string_types = (str,)
iterkeys = lambda d: iter(d.keys())
itervalues = lambda d: iter(d.values())
iteritems = lambda d: iter(d.items())
get_next = lambda x: x.__next__()

#-----------------------------------------------------------------------#
# module renames
#-----------------------------------------------------------------------#
from io import BytesIO, StringIO
NativeStringIO = StringIO
# --------------------------------------------------------------------------- #
# python > 3.3 compatibility layer
# --------------------------------------------------------------------------- #
# ----------------------------------------------------------------------- #
# portable builtins
# ----------------------------------------------------------------------- #
int2byte = six.int2byte
unichr = six.unichr
range_type = six.moves.range
text_type = six.string_types
string_types = six.string_types
iterkeys = six.iterkeys
itervalues = six.itervalues
iteritems = six.iteritems
get_next = six.next
unicode_string = six.u

ifilter = filter
imap = map
izip = zip
intern = sys.intern
NativeStringIO = six.StringIO
ifilter = six.moves.filter
imap = six.moves.map
izip = six.moves.zip
intern = six.moves.intern

if not IS_PYTHON2:
# ----------------------------------------------------------------------- #
# module renames
# ----------------------------------------------------------------------- #
import socketserver

#-----------------------------------------------------------------------#
# ----------------------------------------------------------------------- #
# decorators
#-----------------------------------------------------------------------#
# ----------------------------------------------------------------------- #
implements_to_string = lambda x: x

#---------------------------------------------------------------------------#
byte2int = lambda b: b
# --------------------------------------------------------------------------- #
# python > 2.5 compatability layer
#---------------------------------------------------------------------------#
# --------------------------------------------------------------------------- #
else:
#-----------------------------------------------------------------------#
# portable builtins
#-----------------------------------------------------------------------#
int2byte = chr
byte2int = ord
unichr = unichr
text_type = unicode
range_type = xrange
string_types = (str, unicode)
iterkeys = lambda d: d.iterkeys()
itervalues = lambda d: d.itervalues()
iteritems = lambda d: d.iteritems()
get_next = lambda x: x.next()

#-----------------------------------------------------------------------#
byte2int = six.byte2int
# ----------------------------------------------------------------------- #
# module renames
#-----------------------------------------------------------------------#
from cStringIO import StringIO as BytesIO, StringIO
NativeStringIO = BytesIO

from itertools import imap, izip, ifilter
intern = intern

# ----------------------------------------------------------------------- #
import SocketServer as socketserver

#-----------------------------------------------------------------------#
# ----------------------------------------------------------------------- #
# decorators
#-----------------------------------------------------------------------#
# ----------------------------------------------------------------------- #
def implements_to_string(klass):
klass.__unicode__ = klass.__str__
klass.__str__ = lambda x: x.__unicode__().encode('utf-8')
Expand Down
4 changes: 2 additions & 2 deletions pymodbus/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pymodbus.utilities import unpack_bitstring
from pymodbus.utilities import make_byte_string
from pymodbus.exceptions import ParameterException

from pymodbus.compat import unicode_string
# --------------------------------------------------------------------------- #
# Logging
# --------------------------------------------------------------------------- #
Expand Down Expand Up @@ -341,7 +341,7 @@ def _unpack_words(self, fstring, handle):
pk = self._byteorder + 'H'
handle = [pack(pk, p) for p in handle]
handle = b''.join(handle)
_logger.debug(handle)
_logger.debug(unicode_string(handle))
return handle

def reset(self):
Expand Down
Loading

0 comments on commit c9e8d75

Please sign in to comment.