pymodbus.client package¶
Submodules¶
pymodbus.client.async module¶
Implementation of a Modbus Client Using Twisted¶
Example run:
from twisted.internet import reactor, protocol
from pymodbus.client.async import ModbusClientProtocol
def printResult(result):
print "Result: %d" % result.bits[0]
def process(client):
result = client.write_coil(1, True)
result.addCallback(printResult)
reactor.callLater(1, reactor.stop)
defer = protocol.ClientCreator(reactor, ModbusClientProtocol
).connectTCP("localhost", 502)
defer.addCallback(process)
Another example:
from twisted.internet import reactor
from pymodbus.client.async import ModbusClientFactory
def process():
factory = reactor.connectTCP("localhost", 502, ModbusClientFactory())
reactor.stop()
if __name__ == "__main__":
reactor.callLater(1, process)
reactor.run()
-
class
pymodbus.client.async.ModbusClientProtocol(framer=None, **kwargs)¶ Bases:
twisted.internet.protocol.Protocol,pymodbus.client.common.ModbusClientMixinThis represents the base modbus client protocol. All the application layer code is deferred to a higher level wrapper.
-
connectionLost(reason)¶ Called upon a client disconnect
Parameters: reason – The reason for the disconnect
-
connectionMade()¶ Called upon a successful client connection.
-
dataReceived(data)¶ Get response, check for valid message, decode result
Parameters: data – The data returned from the server
-
execute(request)¶ Starts the producer to send the next request to consumer.write(Frame(request))
-
-
class
pymodbus.client.async.ModbusUdpClientProtocol(framer=None, **kwargs)¶ Bases:
twisted.internet.protocol.DatagramProtocol,pymodbus.client.common.ModbusClientMixinThis represents the base modbus client protocol. All the application layer code is deferred to a higher level wrapper.
-
datagramReceived(data, params)¶ Get response, check for valid message, decode result
Parameters: - data – The data returned from the server
- params – The host parameters sending the datagram
-
execute(request)¶ Starts the producer to send the next request to consumer.write(Frame(request))
-
-
class
pymodbus.client.async.ModbusClientFactory¶ Bases:
twisted.internet.protocol.ReconnectingClientFactorySimple client protocol factory
-
protocol¶ alias of
ModbusClientProtocol
-
pymodbus.client.common module¶
Modbus Client Common¶
This is a common client mixin that can be used by both the synchronous and asynchronous clients to simplify the interface.
-
class
pymodbus.client.common.ModbusClientMixin¶ Bases:
objectThis is a modbus client mixin that provides additional factory methods for all the current modbus methods. This can be used instead of the normal pattern of:
# instead of this client = ModbusClient(...) request = ReadCoilsRequest(1,10) response = client.execute(request) # now like this client = ModbusClient(...) response = client.read_coils(1, 10)
-
last_frame_end= 0¶
-
mask_write_register(*args, **kwargs)¶ Parameters: - address – The address of the register to write
- and_mask – The and bitmask to apply to the register address
- or_mask – The or bitmask to apply to the register address
- unit – The slave unit this request is targeting
Returns: A deferred response handle
-
read_coils(address, count=1, **kwargs)¶ Parameters: - address – The starting address to read from
- count – The number of coils to read
- unit – The slave unit this request is targeting
Returns: A deferred response handle
-
read_discrete_inputs(address, count=1, **kwargs)¶ Parameters: - address – The starting address to read from
- count – The number of discretes to read
- unit – The slave unit this request is targeting
Returns: A deferred response handle
-
read_holding_registers(address, count=1, **kwargs)¶ Parameters: - address – The starting address to read from
- count – The number of registers to read
- unit – The slave unit this request is targeting
Returns: A deferred response handle
-
read_input_registers(address, count=1, **kwargs)¶ Parameters: - address – The starting address to read from
- count – The number of registers to read
- unit – The slave unit this request is targeting
Returns: A deferred response handle
-
readwrite_registers(*args, **kwargs)¶ Parameters: - read_address – The address to start reading from
- read_count – The number of registers to read from address
- write_address – The address to start writing to
- write_registers – The registers to write to the specified address
- unit – The slave unit this request is targeting
Returns: A deferred response handle
-
silent_interval= 0¶
-
state= 0¶
-
write_coil(address, value, **kwargs)¶ Parameters: - address – The starting address to write to
- value – The value to write to the specified address
- unit – The slave unit this request is targeting
Returns: A deferred response handle
-
write_coils(address, values, **kwargs)¶ Parameters: - address – The starting address to write to
- values – The values to write to the specified address
- unit – The slave unit this request is targeting
Returns: A deferred response handle
-
write_register(address, value, **kwargs)¶ Parameters: - address – The starting address to write to
- value – The value to write to the specified address
- unit – The slave unit this request is targeting
Returns: A deferred response handle
-
write_registers(address, values, **kwargs)¶ Parameters: - address – The starting address to write to
- values – The values to write to the specified address
- unit – The slave unit this request is targeting
Returns: A deferred response handle
-
pymodbus.client.sync module¶
-
class
pymodbus.client.sync.ModbusTcpClient(host='127.0.0.1', port=502, framer=<class 'pymodbus.framer.socket_framer.ModbusSocketFramer'>, **kwargs)¶ Bases:
pymodbus.client.sync.BaseModbusClientImplementation of a modbus tcp client
-
close()¶ Closes the underlying socket connection
-
connect()¶ Connect to the modbus tcp server
Returns: True if connection succeeded, False otherwise
-
is_socket_open()¶
-
-
class
pymodbus.client.sync.ModbusUdpClient(host='127.0.0.1', port=502, framer=<class 'pymodbus.framer.socket_framer.ModbusSocketFramer'>, **kwargs)¶ Bases:
pymodbus.client.sync.BaseModbusClientImplementation of a modbus udp client
-
close()¶ Closes the underlying socket connection
-
connect()¶ Connect to the modbus tcp server
Returns: True if connection succeeded, False otherwise
-
is_socket_open()¶
-
-
class
pymodbus.client.sync.ModbusSerialClient(method='ascii', **kwargs)¶ Bases:
pymodbus.client.sync.BaseModbusClientImplementation of a modbus serial client
-
close()¶ Closes the underlying socket connection
-
connect()¶ Connect to the modbus serial server
Returns: True if connection succeeded, False otherwise
-
is_socket_open()¶
-
state= 0¶
-