Skip to content

Commit ae140fe

Browse files
authored
Merge pull request #504 from erlend-aasland/fix-examples
Fix comment and assertions in synchronous_client.py
2 parents 0eefa9b + 783260b commit ae140fe

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

examples/common/synchronous_client.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
print result
1515
"""
1616
# --------------------------------------------------------------------------- #
17-
# import the various server implementations
17+
# import the various client implementations
1818
# --------------------------------------------------------------------------- #
1919
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
2020
# from pymodbus.client.sync import ModbusUdpClient as ModbusClient
@@ -104,12 +104,13 @@ def run_sync_client():
104104
rq = client.write_coil(0, True, unit=UNIT)
105105
rr = client.read_coils(0, 1, unit=UNIT)
106106
assert(not rq.isError()) # test that we are not an error
107+
assert(not rr.isError()) # test that we are not an error
107108
assert(rr.bits[0] == True) # test the expected value
108109

109110
log.debug("Write to multiple coils and read back- test 1")
110111
rq = client.write_coils(1, [True]*8, unit=UNIT)
111-
assert(not rq.isError()) # test that we are not an error
112112
rr = client.read_coils(1, 21, unit=UNIT)
113+
assert(not rq.isError()) # test that we are not an error
113114
assert(not rr.isError()) # test that we are not an error
114115
resp = [True]*21
115116

@@ -124,27 +125,30 @@ def run_sync_client():
124125
rq = client.write_coils(1, [False]*8, unit=UNIT)
125126
rr = client.read_coils(1, 8, unit=UNIT)
126127
assert(not rq.isError()) # test that we are not an error
128+
assert(not rr.isError()) # test that we are not an error
127129
assert(rr.bits == [False]*8) # test the expected value
128130

129131
log.debug("Read discrete inputs")
130132
rr = client.read_discrete_inputs(0, 8, unit=UNIT)
131-
assert(not rq.isError()) # test that we are not an error
133+
assert(not rr.isError()) # test that we are not an error
132134

133135
log.debug("Write to a holding register and read back")
134136
rq = client.write_register(1, 10, unit=UNIT)
135137
rr = client.read_holding_registers(1, 1, unit=UNIT)
136138
assert(not rq.isError()) # test that we are not an error
139+
assert(not rr.isError()) # test that we are not an error
137140
assert(rr.registers[0] == 10) # test the expected value
138141

139142
log.debug("Write to multiple holding registers and read back")
140143
rq = client.write_registers(1, [10]*8, unit=UNIT)
141144
rr = client.read_holding_registers(1, 8, unit=UNIT)
142145
assert(not rq.isError()) # test that we are not an error
146+
assert(not rr.isError()) # test that we are not an error
143147
assert(rr.registers == [10]*8) # test the expected value
144148

145149
log.debug("Read input registers")
146150
rr = client.read_input_registers(1, 8, unit=UNIT)
147-
assert(not rq.isError()) # test that we are not an error
151+
assert(not rr.isError()) # test that we are not an error
148152

149153
arguments = {
150154
'read_address': 1,
@@ -156,6 +160,7 @@ def run_sync_client():
156160
rq = client.readwrite_registers(unit=UNIT, **arguments)
157161
rr = client.read_holding_registers(1, 8, unit=UNIT)
158162
assert(not rq.isError()) # test that we are not an error
163+
assert(not rr.isError()) # test that we are not an error
159164
assert(rq.registers == [20]*8) # test the expected value
160165
assert(rr.registers == [20]*8) # test the expected value
161166

0 commit comments

Comments
 (0)