Skip to content

Commit e4abb1a

Browse files
committed
Minor updates to examples
1 parent 8b601b1 commit e4abb1a

File tree

9 files changed

+23
-27
lines changed

9 files changed

+23
-27
lines changed

examples/common/changing_framers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
# Import the modbus framer that you want
2424
# --------------------------------------------------------------------------- #
2525
# --------------------------------------------------------------------------- #
26-
#from pymodbus.transaction import ModbusSocketFramer as ModbusFramer
27-
from pymodbus.transaction import ModbusRtuFramer as ModbusFramer
26+
from pymodbus.transaction import ModbusSocketFramer as ModbusFramer
27+
# from pymodbus.transaction import ModbusRtuFramer as ModbusFramer
2828
#from pymodbus.transaction import ModbusBinaryFramer as ModbusFramer
2929
#from pymodbus.transaction import ModbusAsciiFramer as ModbusFramer
3030

@@ -48,7 +48,7 @@
4848
# ----------------------------------------------------------------------- #
4949
rq = client.write_coil(1, True)
5050
rr = client.read_coils(1,1)
51-
assert(rq.isError() is False) # test that we are not an error
51+
assert(not rq.isError()) # test that we are not an error
5252
assert(rr.bits[0] == True) # test the expected value
5353

5454
# ----------------------------------------------------------------------- #

examples/common/modbus_payload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
' %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s')
2222
logging.basicConfig(format=FORMAT)
2323
log = logging.getLogger()
24-
log.setLevel(logging.DEBUG)
24+
log.setLevel(logging.INFO)
2525

2626

2727
def run_binary_payload_ex():

examples/common/synchronous_client.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ def run_sync_client():
7878
# which defaults to `0x00`
7979
# ----------------------------------------------------------------------- #
8080
log.debug("Reading Coils")
81-
8281
rr = client.read_coils(1, 1, unit=UNIT)
8382
log.debug(rr)
8483

@@ -98,14 +97,14 @@ def run_sync_client():
9897
log.debug("Write to a Coil and read back")
9998
rq = client.write_coil(0, True, unit=UNIT)
10099
rr = client.read_coils(0, 1, unit=UNIT)
101-
assert(rq.isError() is False) # test that we are not an error
100+
assert(not rq.isError()) # test that we are not an error
102101
assert(rr.bits[0] == True) # test the expected value
103102

104103
log.debug("Write to multiple coils and read back- test 1")
105104
rq = client.write_coils(1, [True]*8, unit=UNIT)
106-
assert(rq.isError() is False) # test that we are not an error
105+
assert(not rq.isError()) # test that we are not an error
107106
rr = client.read_coils(1, 21, unit=UNIT)
108-
assert(rr.isError() is False) # test that we are not an error
107+
assert(not rr.isError()) # test that we are not an error
109108
resp = [True]*21
110109

111110
# If the returned output quantity is not a multiple of eight,
@@ -118,28 +117,28 @@ def run_sync_client():
118117
log.debug("Write to multiple coils and read back - test 2")
119118
rq = client.write_coils(1, [False]*8, unit=UNIT)
120119
rr = client.read_coils(1, 8, unit=UNIT)
121-
assert(rq.isError() is False) # test that we are not an error
120+
assert(not rq.isError()) # test that we are not an error
122121
assert(rr.bits == [False]*8) # test the expected value
123122

124123
log.debug("Read discrete inputs")
125124
rr = client.read_discrete_inputs(0, 8, unit=UNIT)
126-
assert(rq.isError() is False) # test that we are not an error
125+
assert(not rq.isError()) # test that we are not an error
127126

128127
log.debug("Write to a holding register and read back")
129128
rq = client.write_register(1, 10, unit=UNIT)
130129
rr = client.read_holding_registers(1, 1, unit=UNIT)
131-
assert(rq.isError() is False) # test that we are not an error
130+
assert(not rq.isError()) # test that we are not an error
132131
assert(rr.registers[0] == 10) # test the expected value
133132

134133
log.debug("Write to multiple holding registers and read back")
135134
rq = client.write_registers(1, [10]*8, unit=UNIT)
136135
rr = client.read_holding_registers(1, 8, unit=UNIT)
137-
assert(rq.isError() is False) # test that we are not an error
136+
assert(not rq.isError()) # test that we are not an error
138137
assert(rr.registers == [10]*8) # test the expected value
139138

140139
log.debug("Read input registers")
141140
rr = client.read_input_registers(1, 8, unit=UNIT)
142-
assert(rq.isError() is False) # test that we are not an error
141+
assert(not rq.isError()) # test that we are not an error
143142

144143
arguments = {
145144
'read_address': 1,
@@ -150,7 +149,7 @@ def run_sync_client():
150149
log.debug("Read write registeres simulataneously")
151150
rq = client.readwrite_registers(unit=UNIT, **arguments)
152151
rr = client.read_holding_registers(1, 8, unit=UNIT)
153-
assert(rq.isError() is False) # test that we are not an error
152+
assert(not rq.isError()) # test that we are not an error
154153
assert(rq.registers == [20]*8) # test the expected value
155154
assert(rr.registers == [20]*8) # test the expected value
156155

examples/common/synchronous_client_ext.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717

1818
# --------------------------------------------------------------------------- #
19-
2019
# import the extended messages to perform
2120
# --------------------------------------------------------------------------- #
2221
from pymodbus.diag_message import *
@@ -47,7 +46,6 @@ def execute_extended_requests():
4746
#
4847
# It should be noted that you can supply an ipv4 or an ipv6 host address
4948
# for both the UDP and TCP clients.
50-
5149
# ------------------------------------------------------------------------#
5250
client = ModbusClient(method='rtu', port="/dev/ptyp0")
5351
# client = ModbusClient(method='ascii', port="/dev/ptyp0")
@@ -84,7 +82,7 @@ def execute_extended_requests():
8482
rr = client.execute(rq)
8583
log.debug(rr)
8684
# assert(rr == None) # not supported by reference
87-
# assert (rr.isError() is False) # test that we are not an error
85+
# assert (not rr.isError()) # test that we are not an error
8886
# assert (rr.information[0] == b'Pymodbus') # test the vendor name
8987
# assert (rr.information[1] == b'PM') # test the product code
9088
# assert (rr.information[2] == b'1.0') # test the code revision
@@ -94,7 +92,7 @@ def execute_extended_requests():
9492
rr = client.execute(rq)
9593
log.debug(rr)
9694
# assert(rr == None) # not supported by reference
97-
# assert(rr.isError() is False) # test that we are not an error
95+
# assert(not rr.isError()) # test that we are not an error
9896
# assert(rr.identifier == 0x00) # test the slave identifier
9997
# assert(rr.status == 0x00) # test that the status is ok
10098

@@ -103,15 +101,15 @@ def execute_extended_requests():
103101
rr = client.execute(rq)
104102
log.debug(rr)
105103
# assert(rr == None) # not supported by reference
106-
# assert(rr.isError() is False) # test that we are not an error
104+
# assert(not rr.isError()) # test that we are not an error
107105
# assert(rr.status == 0x55) # test the status code
108106

109107
log.debug("Running GetCommEventCounterRequest")
110108
rq = GetCommEventCounterRequest(unit=UNIT)
111109
rr = client.execute(rq)
112110
log.debug(rr)
113111
# assert(rr == None) # not supported by reference
114-
# assert(rr.isError() is False) # test that we are not an error
112+
# assert(not rr.isError()) # test that we are not an error
115113
# assert(rr.status == True) # test the status code
116114
# assert(rr.count == 0x00) # test the status code
117115

@@ -120,7 +118,7 @@ def execute_extended_requests():
120118
rr = client.execute(rq)
121119
log.debug(rr)
122120
# assert(rr == None) # not supported by reference
123-
# assert(rr.isError() is False) # test that we are not an error
121+
# assert(not rr.isError()) # test that we are not an error
124122
# assert(rr.status == True) # test the status code
125123
# assert(rr.event_count == 0x00) # test the number of events
126124
# assert(rr.message_count == 0x00) # test the number of messages

examples/contrib/remote_server_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def __extract_result(self, fx, result):
113113
:param fx: The function to call
114114
:param result: The resulting data
115115
"""
116-
if result.isError() is False:
116+
if not result.isError():
117117
if fx in ['d', 'c']:
118118
return result.bits
119119
if fx in ['h', 'i']:

examples/contrib/serial_forwarder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ def run_serial_forwarder():
2929
# ----------------------------------------------------------------------- #
3030
# initialize the datastore(serial client)
3131
# ----------------------------------------------------------------------- #
32-
client = ModbusClient(method='ascii', port='/dev/pts/14')
32+
client = ModbusClient(method='rtu', port='/dev/ptyp0')
3333
store = RemoteSlaveContext(client)
3434
context = ModbusServerContext(slaves=store, single=True)
3535

3636
# ----------------------------------------------------------------------- #
3737
# run the server you want
3838
# ----------------------------------------------------------------------- #
39-
StartServer(context)
39+
StartServer(context, address=("localhost", 5020))
4040

4141

4242
if __name__ == "__main__":

pymodbus/datastore/remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def __extract_result(self, fx, result):
9999
''' A helper method to extract the values out of
100100
a response. TODO make this consistent (values?)
101101
'''
102-
if result.isError() is False:
102+
if not result.isError():
103103
if fx in ['d', 'c']: return result.bits
104104
if fx in ['h', 'i']: return result.registers
105105
else: return result

pymodbus/transaction.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ def delTransaction(self, tid):
430430

431431

432432
# --------------------------------------------------------------------------- #
433-
434433
# Exported symbols
435434
# --------------------------------------------------------------------------- #
436435
__all__ = [

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ envlist = py27, py34, py35, py36, pypy
88

99
[testenv]
1010
deps = -requirements-tests.txt
11-
commands = nostests {posargs}
11+
commands = py.test {posargs}
1212

1313
[flake8]
1414
exclude = .tox

0 commit comments

Comments
 (0)