Skip to content

Commit

Permalink
Cleaning up the build tools
Browse files Browse the repository at this point in the history
- moving custom datastores to examples
- bumping required versions
- making the debug server console optional
- updating documentation
  • Loading branch information
bashwork committed Oct 2, 2012
1 parent 044acb0 commit 3856f07
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 56 deletions.
2 changes: 1 addition & 1 deletion doc/api/pydoc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def process( self ):
del self.pending[0]
finally:
for item in self.warnings:
log.info(item)
_log.info(item)

def clean (self, objectList, object):
"""callback from the formatter object asking us to remove
Expand Down
6 changes: 6 additions & 0 deletions doc/sphinx/examples/database-datastore.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
==================================================
Database Datastore Example
==================================================

.. literalinclude:: ../../../examples/datastore/database.py

9 changes: 9 additions & 0 deletions doc/sphinx/examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ Example Library Code
synchronous-server
performance

Custom Datastore Code
--------------------------------------------------

.. toctree::
:maxdepth: 2

redis-datastore
database-datastore

Example Frontend Code
--------------------------------------------------

Expand Down
6 changes: 6 additions & 0 deletions doc/sphinx/examples/redis-datastore.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
==================================================
Redis Datastore Example
==================================================

.. literalinclude:: ../../../examples/datastore/modredis.py

16 changes: 0 additions & 16 deletions doc/sphinx/library/datastore/database.rst

This file was deleted.

2 changes: 0 additions & 2 deletions doc/sphinx/library/datastore/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ from the sourcecode*
store.rst
context.rst
remote.rst
database.rst
modredis.rst
16 changes: 0 additions & 16 deletions doc/sphinx/library/datastore/modredis.rst

This file was deleted.

6 changes: 3 additions & 3 deletions examples/common/synchronous-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#---------------------------------------------------------------------------#
# import the various server implementations
#---------------------------------------------------------------------------#
#from pymodbus.client.sync import ModbusTcpClient as ModbusClient
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
#from pymodbus.client.sync import ModbusUdpClient as ModbusClient
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
#from pymodbus.client.sync import ModbusSerialClient as ModbusClient

#---------------------------------------------------------------------------#
# configure the client logging
Expand All @@ -38,7 +38,7 @@
# It should be noted that you can supply an ipv4 or an ipv6 host address for
# both the UDP and TCP clients.
#---------------------------------------------------------------------------#
client = ModbusClient('localhost')
client = ModbusClient('localhost', port=5020)
#client = ModbusClient(method='ascii', port='/dev/pts/2', timeout=1)
#client = ModbusClient(method='rtu', port='/dev/pts/2', timeout=1)
client.connect()
Expand Down
25 changes: 25 additions & 0 deletions examples/datastore/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
============================================================
Custom Datastore Implementations
============================================================

There are a few example implementations of custom datastores
just to show what is possible.

------------------------------------------------------------
SqlAlchemy Backend
------------------------------------------------------------

This module allows one to use any database available through
the sqlalchemy package as a datastore for the modbus server.
This could be useful to have many servers who have data they
agree upon and is transactional.

------------------------------------------------------------
Redis Backend
------------------------------------------------------------

This module allows one to use redis as a modbus server
datastore backend. This achieves the same thing as the
sqlalchemy backend, however, it is much more lightweight and
easier to set up.

File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions examples/datastore/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -------------------------------------------------------------------
# if you want to use the custom data stores, uncomment these
# -------------------------------------------------------------------
#SQLAlchemy==0.7.9
#redis==2.6.2
9 changes: 7 additions & 2 deletions pymodbus/server/async.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,20 @@ def _send(self, message, addr):
#---------------------------------------------------------------------------#
# Starting Factories
#---------------------------------------------------------------------------#
def StartTcpServer(context, identity=None, address=None):
def StartTcpServer(context, identity=None, address=None, console=False):
''' Helper method to start the Modbus Async TCP server
:param context: The server data context
:param identify: The server identity to use (default empty)
:param address: An optional (interface, port) to bind to.
:param console: A flag indicating if you want the debug console
'''
from twisted.internet import reactor

address = address or ("", Defaults.Port)
framer = ModbusSocketFramer
factory = ModbusServerFactory(context, framer, identity)
InstallManagementConsole({'factory': factory})
if console: InstallManagementConsole({'factory': factory})

_logger.info("Starting Modbus TCP Server on %s:%s" % address)
reactor.listenTCP(address[1], factory, interface=address[0])
Expand Down Expand Up @@ -233,15 +234,19 @@ def StartSerialServer(context, identity=None,
:param framer: The framer to use (default ModbusAsciiFramer)
:param port: The serial port to attach to
:param baudrate: The baud rate to use for the serial device
:param console: A flag indicating if you want the debug console
'''
from twisted.internet import reactor
from twisted.internet.serialport import SerialPort

port = kwargs.get('port', '/dev/ttyS0')
baudrate = kwargs.get('baudrate', Defaults.Baudrate)
console = kwargs.get('console', False)

_logger.info("Starting Modbus Serial Server on %s" % port)
factory = ModbusServerFactory(context, framer, identity)
if console: InstallManagementConsole({'factory': factory})

protocol = factory.buildProtocol(None)
SerialPort.getHost = lambda self: port # hack for logging
handle = SerialPort(protocol, port, reactor, baudrate)
Expand Down
30 changes: 21 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
distribute==0.6.24
pyserial==2.5
# -------------------------------------------------------------------
# if want to use the pymodbus serial stack, uncomment these
# -------------------------------------------------------------------
#pyserial==2.6
# -------------------------------------------------------------------
# if you want to run the tests and code coverage, uncomment these
# these out
# -------------------------------------------------------------------
#coverage==3.4
#nose==1.0.0
#coverage==3.5.3
#mock==1.0b1
#nose==1.2.1
#pep8==1.3.3
# -------------------------------------------------------------------
# if you want to use the asynchronous version, uncomment these
# -------------------------------------------------------------------
#Twisted==12.2.0
#zope.interface==4.0.1
#pyasn1==0.1.4
#pycrypto==2.6
#wsgiref==0.1.2
# -------------------------------------------------------------------
# if you are just using the synchronous version, you can comment
# these out
# if you want to build the documentation, uncomment these
# -------------------------------------------------------------------
Twisted==11.0.0
zope.interface==3.8.0
#Jinja2==2.6
#Pygments==1.5
#Sphinx==1.1.3
#docutils==0.9.1
11 changes: 5 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@
include_package_data = True,
zip_safe = True,
install_requires = [
'twisted >= 2.5.0',
'nose >= 1.0.0',
'mock >= 0.8.0',
'pyserial >= 2.4'
'twisted >= 12.2.0',
'pyserial >= 2.6'
],
extras_require = {
'quality' : [ 'epydoc >= 3.4.1', 'coverage >= 3.3.1', 'pyflakes >= 0.4.0' ],
'twisted' : [ 'pyasn1 >= 0.0.13', 'pycrypto >= 2.3' ],
'quality' : [ 'coverage >= 3.5.3', 'nose >= 1.2.1', 'mock >= 1.0.0', 'pep8 >= 1.3.3' ],
'documents' : [ 'sphinx >= 1.1.3' ],
'twisted' : [ 'pyasn1 >= 0.1.4', 'pycrypto >= 2.6' ],
},
test_suite = 'nose.collector',
cmdclass = command_classes,
Expand Down
2 changes: 1 addition & 1 deletion test/test_server_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def testUdpServerInitialize(self):
def testTcpServerStartup(self):
''' Test that the modbus tcp async server starts correctly '''
with patch('twisted.internet.reactor') as mock_reactor:
StartTcpServer(context=None)
StartTcpServer(context=None, console=True)
self.assertEqual(mock_reactor.listenTCP.call_count, 2)
self.assertEqual(mock_reactor.run.call_count, 1)

Expand Down

0 comments on commit 3856f07

Please sign in to comment.