Skip to content

Commit

Permalink
1. #162, creating universal distribution for py2 and py3
Browse files Browse the repository at this point in the history
2. Merge PR #152 , create compatible versions
  • Loading branch information
dhoomakethu committed May 16, 2017
1 parent 7ca9066 commit d677fe5
Show file tree
Hide file tree
Showing 56 changed files with 817 additions and 637 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ build/
dist/
pymodbus.egg-info/
.coverage
<<<<<<< HEAD
.vscode
.idea
.noseids
=======
.idea/

>>>>>>> 7f1153560c70941a73c7c74725e61b380096c0a7
.idea/
6 changes: 3 additions & 3 deletions examples/common/modbus-payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#---------------------------------------------------------------------------#
# We are going to use a simple client to send our requests
#---------------------------------------------------------------------------#
client = ModbusClient('127.0.0.1')
client = ModbusClient('127.0.0.1', port=5020)
client.connect()

#---------------------------------------------------------------------------#
Expand All @@ -43,7 +43,7 @@
builder.add_bits([0,1,0,1,1,0,1,0])
payload = builder.build()
address = 0x01
result = client.write_registers(address, payload, skip_encode=True)
result = client.write_registers(address, payload, skip_encode=True, unit=1)

#---------------------------------------------------------------------------#
# If you need to decode a collection of registers in a weird layout, the
Expand All @@ -60,7 +60,7 @@
#---------------------------------------------------------------------------#
address = 0x01
count = 8
result = client.read_input_registers(address, count)
result = client.read_input_registers(address, count, unit=1)
decoder = BinaryPayloadDecoder.fromRegisters(result.registers, endian=Endian.Little)
decoded = {
'string': decoder.decode_string(8),
Expand Down
17 changes: 11 additions & 6 deletions examples/common/performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
from time import time
from multiprocessing import log_to_stderr
from pymodbus.client.sync import ModbusTcpClient
from pymodbus.client.sync import ModbusSerialClient

#---------------------------------------------------------------------------#
# choose between threads or processes
#---------------------------------------------------------------------------#
#from multiprocessing import Process as Worker
from threading import Thread as Worker

from threading import Lock
_thread_lock = Lock()
#---------------------------------------------------------------------------#
# initialize the test
#---------------------------------------------------------------------------#
Expand All @@ -29,8 +31,8 @@
# * cycles - the total number of requests to send
# * host - the host to send the requests to
#---------------------------------------------------------------------------#
workers = 1
cycles = 10000
workers = 10
cycles = 1000
host = '127.0.0.1'


Expand All @@ -54,10 +56,12 @@ def single_client_test(host, cycles):

try:
count = 0
client = ModbusTcpClient(host)
# client = ModbusTcpClient(host, port=5020)
client = ModbusSerialClient(method="rtu", port="/dev/ttyp0", baudrate=9600)
while count < cycles:
result = client.read_holding_registers(10, 1).getRegister(0)
count += 1
with _thread_lock:
result = client.read_holding_registers(10, 1, unit=1).getRegister(0)
count += 1
except: logger.exception("failed to run test successfully")
logger.debug("finished worker: %d" % os.getpid())

Expand All @@ -76,3 +80,4 @@ def single_client_test(host, cycles):
any(p.join() for p in procs) # wait for the workers to finish
stop = time()
print "%d requests/second" % ((1.0 * cycles) / (stop - start))
print "time taken to complete %s cycle by %s workers is %s seconds" % (cycles, workers, stop-start)
63 changes: 32 additions & 31 deletions examples/common/synchronous-client-ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#---------------------------------------------------------------------------#
# import the various server implementations
#---------------------------------------------------------------------------#
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
# from pymodbus.client.sync import ModbusTcpClient as ModbusClient
#from pymodbus.client.sync import ModbusUdpClient as ModbusClient
#from pymodbus.client.sync import ModbusSerialClient as ModbusClient
from pymodbus.client.sync import ModbusSerialClient as ModbusClient

#---------------------------------------------------------------------------#
# configure the client logging
Expand All @@ -32,7 +32,8 @@
# It should be noted that you can supply an ipv4 or an ipv6 host address for
# both the UDP and TCP clients.
#---------------------------------------------------------------------------#
client = ModbusClient('127.0.0.1')
client = ModbusClient(method='rtu', port="/dev/ttyp0")
# client = ModbusClient('127.0.0.1', port=5020)
client.connect()

#---------------------------------------------------------------------------#
Expand Down Expand Up @@ -65,35 +66,35 @@
#---------------------------------------------------------------------------#
# information requests
#---------------------------------------------------------------------------#
rq = ReadDeviceInformationRequest()
rq = ReadDeviceInformationRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference
assert(rr.function_code < 0x80) # test that we are not an error
assert(rr.information[0] == 'proconX Pty Ltd') # test the vendor name
assert(rr.information[1] == 'FT-MBSV') # test the product code
assert(rr.information[2] == 'EXPERIMENTAL') # test the code revision
assert(rr.information[0] == 'Pymodbus') # test the vendor name
assert(rr.information[1] == 'PM') # test the product code
assert(rr.information[2] == '1.0') # test the code revision

rq = ReportSlaveIdRequest()
rq = ReportSlaveIdRequest(unit=1)
rr = client.execute(rq)
assert(rr == None) # not supported by reference
# assert(rr == None) # not supported by reference
#assert(rr.function_code < 0x80) # test that we are not an error
#assert(rr.identifier == 0x00) # test the slave identifier
#assert(rr.status == 0x00) # test that the status is ok

rq = ReadExceptionStatusRequest()
rq = ReadExceptionStatusRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference
assert(rr.function_code < 0x80) # test that we are not an error
assert(rr.status == 0x55) # test the status code
#assert(rr.function_code < 0x80) # test that we are not an error
#assert(rr.status == 0x55) # test the status code

rq = GetCommEventCounterRequest()
rq = GetCommEventCounterRequest(unit=1)
rr = client.execute(rq)
assert(rr == None) # not supported by reference
#assert(rr == None) # not supported by reference
#assert(rr.function_code < 0x80) # test that we are not an error
#assert(rr.status == True) # test the status code
#assert(rr.count == 0x00) # test the status code

rq = GetCommEventLogRequest()
rq = GetCommEventLogRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference
#assert(rr.function_code < 0x80) # test that we are not an error
Expand All @@ -105,68 +106,68 @@
#---------------------------------------------------------------------------#
# diagnostic requests
#---------------------------------------------------------------------------#
rq = ReturnQueryDataRequest()
rq = ReturnQueryDataRequest(unit=1)
rr = client.execute(rq)
assert(rr == None) # not supported by reference
# assert(rr == None) # not supported by reference
#assert(rr.message[0] == 0x0000) # test the resulting message

rq = RestartCommunicationsOptionRequest()
rq = RestartCommunicationsOptionRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference
#assert(rr.message == 0x0000) # test the resulting message

rq = ReturnDiagnosticRegisterRequest()
rq = ReturnDiagnosticRegisterRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ChangeAsciiInputDelimiterRequest()
rq = ChangeAsciiInputDelimiterRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ForceListenOnlyModeRequest()
rq = ForceListenOnlyModeRequest(unit=1)
client.execute(rq) # does not send a response

rq = ClearCountersRequest()
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ReturnBusCommunicationErrorCountRequest()
rq = ReturnBusCommunicationErrorCountRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ReturnBusExceptionErrorCountRequest()
rq = ReturnBusExceptionErrorCountRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ReturnSlaveMessageCountRequest()
rq = ReturnSlaveMessageCountRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ReturnSlaveNoResponseCountRequest()
rq = ReturnSlaveNoResponseCountRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ReturnSlaveNAKCountRequest()
rq = ReturnSlaveNAKCountRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ReturnSlaveBusyCountRequest()
rq = ReturnSlaveBusyCountRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ReturnSlaveBusCharacterOverrunCountRequest()
rq = ReturnSlaveBusCharacterOverrunCountRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ReturnIopOverrunCountRequest()
rq = ReturnIopOverrunCountRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ClearOverrunCountRequest()
rq = ClearOverrunCountRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = GetClearModbusPlusRequest()
rq = GetClearModbusPlusRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

Expand Down
39 changes: 23 additions & 16 deletions examples/common/synchronous-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#---------------------------------------------------------------------------#
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
#from pymodbus.client.sync import ModbusUdpClient as ModbusClient
#from pymodbus.client.sync import ModbusSerialClient as ModbusClient
# from pymodbus.client.sync import ModbusSerialClient as ModbusClient

#---------------------------------------------------------------------------#
# configure the client logging
Expand Down Expand Up @@ -55,9 +55,9 @@
#
# client = ModbusClient('localhost', retries=3, retry_on_empty=True)
#---------------------------------------------------------------------------#
client = ModbusClient('localhost', port=502)
client = ModbusClient('localhost', port=5020)
#client = ModbusClient(method='ascii', port='/dev/pts/2', timeout=1)
#client = ModbusClient(method='rtu', port='/dev/pts/2', timeout=1)
# client = ModbusClient(method='rtu', port='/dev/ttyp0', timeout=1)
client.connect()

#---------------------------------------------------------------------------#
Expand All @@ -67,7 +67,7 @@
# individual request. This can be done by specifying the `unit` parameter
# which defaults to `0x00`
#---------------------------------------------------------------------------#
rr = client.read_coils(1, 1, unit=0x02)
rr = client.read_coils(1, 1, unit=0x01)

#---------------------------------------------------------------------------#
# example requests
Expand All @@ -81,39 +81,46 @@
# Keep both of these cases in mind when testing as the following will
# _only_ pass with the supplied async modbus server (script supplied).
#---------------------------------------------------------------------------#
rq = client.write_coil(1, True)
rr = client.read_coils(1,1)
rq = client.write_coil(0, True, unit=1)
rr = client.read_coils(0, 1, unit=1)
assert(rq.function_code < 0x80) # test that we are not an error
assert(rr.bits[0] == True) # test the expected value

rq = client.write_coils(1, [True]*8)
rr = client.read_coils(1,8)
rq = client.write_coils(1, [True]*8, unit=1)
rr = client.read_coils(1, 8, unit=1)
assert(rq.function_code < 0x80) # test that we are not an error
assert(rr.bits == [True]*8) # test the expected value

rq = client.write_coils(1, [False]*8)
rr = client.read_discrete_inputs(1,8)
rq = client.write_coils(1, [False]*8, unit=1)
rr = client.read_coils(1, 8, unit=1)
assert(rq.function_code < 0x80) # test that we are not an error
assert(rr.bits == [False]*8) # test the expected value

rq = client.write_register(1, 10)
rr = client.read_holding_registers(1,1)

rr = client.read_discrete_inputs(0, 8, unit=1)
assert(rq.function_code < 0x80) # test that we are not an error

rq = client.write_register(1, 10, unit=1)
rr = client.read_holding_registers(1, 1, unit=1)
assert(rq.function_code < 0x80) # test that we are not an error
assert(rr.registers[0] == 10) # test the expected value

rq = client.write_registers(1, [10]*8)
rr = client.read_input_registers(1,8)
rq = client.write_registers(1, [10]*8, unit=1)
rr = client.read_holding_registers(1, 8, unit=1)
assert(rq.function_code < 0x80) # test that we are not an error
assert(rr.registers == [10]*8) # test the expected value

rr = client.read_input_registers(1, 8, unit=1)
assert(rq.function_code < 0x80) # test that we are not an error

arguments = {
'read_address': 1,
'read_count': 8,
'write_address': 1,
'write_registers': [20]*8,
}
rq = client.readwrite_registers(**arguments)
rr = client.read_input_registers(1,8)
rq = client.readwrite_registers(unit=1, **arguments)
rr = client.read_holding_registers(1, 8, unit=1)
assert(rq.function_code < 0x80) # test that we are not an error
assert(rq.registers == [20]*8) # test the expected value
assert(rr.registers == [20]*8) # test the expected value
Expand Down
8 changes: 4 additions & 4 deletions examples/common/synchronous-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,16 @@
identity = ModbusDeviceIdentification()
identity.VendorName = 'Pymodbus'
identity.ProductCode = 'PM'
identity.VendorUrl = 'http://github.com/bashwork/pymodbus/'
identity.VendorUrl = 'http://github.com/riptideio/pymodbus/'
identity.ProductName = 'Pymodbus Server'
identity.ModelName = 'Pymodbus Server'
identity.MajorMinorRevision = '1.0'

#---------------------------------------------------------------------------#
#---------------------------------------------------------------------------#
# run the server you want
#---------------------------------------------------------------------------#
# Tcp:
StartTcpServer(context, identity=identity, address=("localhost", 5020))
# StartTcpServer(context, identity=identity, address=("localhost", 5020))

# Udp:
#StartUdpServer(context, identity=identity, address=("localhost", 502))
Expand All @@ -114,4 +114,4 @@
#StartSerialServer(context, identity=identity, port='/dev/pts/3', timeout=1)

# RTU:
#StartSerialServer(context, framer=ModbusRtuFramer, identity=identity, port='/dev/pts/3', timeout=.005)
StartSerialServer(context, framer=ModbusRtuFramer, identity=identity, port='/dev/ptyp0', timeout=.005, baudrate=9600)
Loading

0 comments on commit d677fe5

Please sign in to comment.