Skip to content

Commit

Permalink
pymodbus-dev#190 fix examples - callback-server, modbus-payload
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoomakethu committed Jul 23, 2017
1 parent fa85283 commit ac7a1d6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
6 changes: 4 additions & 2 deletions examples/common/callback-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext
from pymodbus.transaction import ModbusRtuFramer, ModbusAsciiFramer


#---------------------------------------------------------------------------#
# import the python libraries we need
#---------------------------------------------------------------------------#
Expand All @@ -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
Expand All @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions examples/common/device-mapping
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0x0001,/dev/ptyp0
0x0002,/dev/ptyp1
8 changes: 4 additions & 4 deletions examples/common/modbus-payload-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

#---------------------------------------------------------------------------#
Expand Down
11 changes: 6 additions & 5 deletions examples/common/modbus-payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ac7a1d6

Please sign in to comment.