pymodbus.client.async.twisted package

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.twisted.ModbusClientProtocol(framer=None, **kwargs)

Bases: twisted.internet.protocol.Protocol, pymodbus.client.async.mixins.AsyncModbusClientMixin

This represents the base modbus client protocol. All the application layer code is deferred to a higher level wrapper.

close()

Closes underlying transport layer ,essentially closing the client :return:

connectionLost(reason=None)

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))

framer = None
class pymodbus.client.async.twisted.ModbusUdpClientProtocol(host='127.0.0.1', port=502, framer=None, source_address=None, timeout=None, **kwargs)

Bases: twisted.internet.protocol.DatagramProtocol, pymodbus.client.async.mixins.AsyncModbusClientMixin

This 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.twisted.ModbusClientFactory

Bases: twisted.internet.protocol.ReconnectingClientFactory

Simple client protocol factory

protocol

alias of ModbusClientProtocol