|
9 | 9 | from pymodbus.payload import BinaryPayloadDecoder |
10 | 10 | from pymodbus.payload import BinaryPayloadBuilder |
11 | 11 | from pymodbus.client.sync import ModbusTcpClient as ModbusClient |
| 12 | +from pymodbus.compat import iteritems |
12 | 13 |
|
13 | 14 | #---------------------------------------------------------------------------# |
14 | 15 | # configure the client logging |
|
34 | 35 | # - a 8 byte string 'abcdefgh' |
35 | 36 | # - a 32 bit float 22.34 |
36 | 37 | # - a 16 bit unsigned int 0x1234 |
| 38 | +# - another 16 bit unsigned int 0x5678 |
37 | 39 | # - an 8 bit int 0x12 |
38 | 40 | # - an 8 bit bitstring [0,1,0,1,1,0,1,0] |
39 | 41 | #---------------------------------------------------------------------------# |
40 | 42 | builder = BinaryPayloadBuilder(endian=Endian.Big) |
41 | 43 | builder.add_string('abcdefgh') |
42 | 44 | builder.add_32bit_float(22.34) |
43 | 45 | builder.add_16bit_uint(0x1234) |
| 46 | +builder.add_16bit_uint(0x5678) |
44 | 47 | builder.add_8bit_int(0x12) |
45 | 48 | builder.add_bits([0,1,0,1,1,0,1,0]) |
46 | 49 | payload = builder.build() |
|
57 | 60 | # - a 8 byte string 'abcdefgh' |
58 | 61 | # - a 32 bit float 22.34 |
59 | 62 | # - a 16 bit unsigned int 0x1234 |
| 63 | +# - another 16 bit unsigned int which we will ignore |
60 | 64 | # - an 8 bit int 0x12 |
61 | 65 | # - an 8 bit bitstring [0,1,0,1,1,0,1,0] |
62 | 66 | #---------------------------------------------------------------------------# |
|
68 | 72 | 'string': decoder.decode_string(8), |
69 | 73 | 'float': decoder.decode_32bit_float(), |
70 | 74 | '16uint': decoder.decode_16bit_uint(), |
| 75 | + 'ignored': decoder.skip_bytes(2), |
71 | 76 | '8int': decoder.decode_8bit_int(), |
72 | 77 | 'bits': decoder.decode_bits(), |
73 | 78 | } |
74 | 79 |
|
75 | | -print "-" * 60 |
76 | | -print "Decoded Data" |
77 | | -print "-" * 60 |
78 | | -for name, value in decoded.iteritems(): |
79 | | - print ("%s\t" % name), value |
| 80 | +print("-" * 60) |
| 81 | +print("Decoded Data") |
| 82 | +print("-" * 60) |
| 83 | +for name, value in iteritems(decoded): |
| 84 | + print ("%s\t" % name, value) |
80 | 85 |
|
81 | 86 | #---------------------------------------------------------------------------# |
82 | 87 | # close the client |
|
0 commit comments