|
66 | 66 | # The slave to query is specified in an optional parameter for each |
67 | 67 | # individual request. This can be done by specifying the `unit` parameter |
68 | 68 | # which defaults to `0x00` |
69 | | -#---------------------------------------------------------------------------# |
| 69 | +#---------------------------------------------------------------------------# |
| 70 | +log.debug("Reading Coils") |
70 | 71 | rr = client.read_coils(1, 1, unit=0x01) |
71 | 72 |
|
72 | 73 | #---------------------------------------------------------------------------# |
|
80 | 81 | # blocks for the two sets, so a change to one is a change to the other. |
81 | 82 | # Keep both of these cases in mind when testing as the following will |
82 | 83 | # _only_ pass with the supplied async modbus server (script supplied). |
83 | | -#---------------------------------------------------------------------------# |
| 84 | +#---------------------------------------------------------------------------# |
| 85 | +log.debug("Write to a Coil and read back") |
84 | 86 | rq = client.write_coil(0, True, unit=1) |
85 | 87 | rr = client.read_coils(0, 1, unit=1) |
86 | 88 | assert(rq.function_code < 0x80) # test that we are not an error |
87 | 89 | assert(rr.bits[0] == True) # test the expected value |
88 | 90 |
|
| 91 | +log.debug("Write to multiple coils and read back- test 1") |
89 | 92 | rq = client.write_coils(1, [True]*8, unit=1) |
90 | | -rr = client.read_coils(1, 8, unit=1) |
91 | 93 | assert(rq.function_code < 0x80) # test that we are not an error |
92 | | -assert(rr.bits == [True]*8) # test the expected value |
| 94 | +rr = client.read_coils(1, 21, unit=1) |
| 95 | +assert(rr.function_code < 0x80) # test that we are not an error |
| 96 | +resp = [True]*21 |
| 97 | + |
| 98 | +# If the returned output quantity is not a multiple of eight, |
| 99 | +# the remaining bits in the final data byte will be padded with zeros |
| 100 | +# (toward the high order end of the byte). |
| 101 | + |
| 102 | +resp.extend([False]*3) |
| 103 | +assert(rr.bits == resp) # test the expected value |
93 | 104 |
|
| 105 | +log.debug("Write to multiple coils and read back - test 2") |
94 | 106 | rq = client.write_coils(1, [False]*8, unit=1) |
95 | 107 | rr = client.read_coils(1, 8, unit=1) |
96 | 108 | assert(rq.function_code < 0x80) # test that we are not an error |
97 | 109 | assert(rr.bits == [False]*8) # test the expected value |
98 | 110 |
|
99 | 111 |
|
| 112 | +log.debug("Read discrete inputs") |
100 | 113 | rr = client.read_discrete_inputs(0, 8, unit=1) |
101 | 114 | assert(rq.function_code < 0x80) # test that we are not an error |
102 | 115 |
|
| 116 | +log.debug("Write to a holding register and read back") |
103 | 117 | rq = client.write_register(1, 10, unit=1) |
104 | 118 | rr = client.read_holding_registers(1, 1, unit=1) |
105 | 119 | assert(rq.function_code < 0x80) # test that we are not an error |
106 | 120 | assert(rr.registers[0] == 10) # test the expected value |
107 | 121 |
|
| 122 | +log.debug("Write to multiple holding registers and read back") |
108 | 123 | rq = client.write_registers(1, [10]*8, unit=1) |
109 | 124 | rr = client.read_holding_registers(1, 8, unit=1) |
110 | 125 | assert(rq.function_code < 0x80) # test that we are not an error |
111 | 126 | assert(rr.registers == [10]*8) # test the expected value |
112 | 127 |
|
| 128 | +log.debug("Read input registers") |
113 | 129 | rr = client.read_input_registers(1, 8, unit=1) |
114 | 130 | assert(rq.function_code < 0x80) # test that we are not an error |
115 | 131 |
|
|
119 | 135 | 'write_address': 1, |
120 | 136 | 'write_registers': [20]*8, |
121 | 137 | } |
| 138 | +log.debug("Read write registeres simulataneously") |
122 | 139 | rq = client.readwrite_registers(unit=1, **arguments) |
123 | 140 | rr = client.read_holding_registers(1, 8, unit=1) |
124 | 141 | assert(rq.function_code < 0x80) # test that we are not an error |
|
0 commit comments