From ac7a1d626671b3d71871fe34a8f07d0ff9b3d0ef Mon Sep 17 00:00:00 2001 From: dhoomakethu Date: Sun, 23 Jul 2017 07:06:09 +0530 Subject: [PATCH] #190 fix examples - callback-server, modbus-payload --- examples/common/callback-server.py | 6 ++++-- examples/common/device-mapping | 2 ++ examples/common/modbus-payload-server.py | 8 ++++---- examples/common/modbus-payload.py | 11 ++++++----- 4 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 examples/common/device-mapping diff --git a/examples/common/callback-server.py b/examples/common/callback-server.py index 374787b6c..572b13841 100755 --- a/examples/common/callback-server.py +++ b/examples/common/callback-server.py @@ -16,6 +16,7 @@ from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext from pymodbus.transaction import ModbusRtuFramer, ModbusAsciiFramer + #---------------------------------------------------------------------------# # import the python libraries we need #---------------------------------------------------------------------------# @@ -31,7 +32,8 @@ #---------------------------------------------------------------------------# # create your custom data block with callbacks -#---------------------------------------------------------------------------# +#---------------------------------------------------------------------------# + class CallbackDataBlock(ModbusSparseDataBlock): ''' A datablock that stores the new value in memory and passes the operation to a message queue for further @@ -44,7 +46,7 @@ def __init__(self, devices, queue): self.devices = devices self.queue = queue - values = {k:0 for k in devices.iterkeys()} + values = {k:0 for k in devices.keys()} values[0xbeef] = len(values) # the number of devices super(CallbackDataBlock, self).__init__(values) diff --git a/examples/common/device-mapping b/examples/common/device-mapping new file mode 100644 index 000000000..dc7c8b85c --- /dev/null +++ b/examples/common/device-mapping @@ -0,0 +1,2 @@ +0x0001,/dev/ptyp0 +0x0002,/dev/ptyp1 \ No newline at end of file diff --git a/examples/common/modbus-payload-server.py b/examples/common/modbus-payload-server.py index 3c6d1953a..b2b55ebeb 100755 --- a/examples/common/modbus-payload-server.py +++ b/examples/common/modbus-payload-server.py @@ -35,10 +35,10 @@ # build your payload #---------------------------------------------------------------------------# builder = BinaryPayloadBuilder(endian=Endian.Little) -builder.add_string('abcdefgh') -builder.add_32bit_float(22.34) -builder.add_16bit_uint(0x1234) -builder.add_8bit_int(0x12) +# builder.add_string('abcdefgh') +# builder.add_32bit_float(22.34) +# builder.add_16bit_uint(4660) +# builder.add_8bit_int(18) builder.add_bits([0,1,0,1,1,0,1,0]) #---------------------------------------------------------------------------# diff --git a/examples/common/modbus-payload.py b/examples/common/modbus-payload.py index 03dbad354..143b1adfa 100755 --- a/examples/common/modbus-payload.py +++ b/examples/common/modbus-payload.py @@ -9,6 +9,7 @@ from pymodbus.payload import BinaryPayloadDecoder from pymodbus.payload import BinaryPayloadBuilder from pymodbus.client.sync import ModbusTcpClient as ModbusClient +from pymodbus.compat import iteritems #---------------------------------------------------------------------------# # configure the client logging @@ -72,11 +73,11 @@ 'bits': decoder.decode_bits(), } -print "-" * 60 -print "Decoded Data" -print "-" * 60 -for name, value in decoded.iteritems(): - print ("%s\t" % name), value +print("-" * 60) +print("Decoded Data") +print("-" * 60) +for name, value in iteritems(decoded): + print ("%s\t" % name, value) #---------------------------------------------------------------------------# # close the client