client.async — Twisted Async Modbus Client

API Documentation

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)
    reactor.callLater(1, reactor.stop)

defer = protocol.ClientCreator(reactor, ModbusClientProtocol
        ).connectTCP("localhost", 502)

Another example:

from twisted.internet import reactor
from pymodbus.client.async import ModbusClientFactory

def process():
    factory = reactor.connectTCP("localhost", 502, ModbusClientFactory())

if __name__ == "__main__":
   reactor.callLater(1, process)
class pymodbus.client.async.ModbusClientProtocol(framer=None, **kwargs)

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

__init__(framer=None, **kwargs)

Initializes the framer module

Parameters:framer – The framer to use for the protocol

Helper method to return a deferred response for the current request.

Parameters:tid – The transaction identifier for this response
Returns:A defer linked to the latest request

Handle the processed response and link to correct deferred

Parameters:reply – The reply to process

Called upon a client disconnect

Parameters:reason – The reason for the disconnect

Called upon a successful client connection.


Get response, check for valid message, decode result

Parameters:data – The data returned from the server

Starts the producer to send the next request to consumer.write(Frame(request))

class pymodbus.client.async.ModbusClientFactory

Simple client protocol factory


alias of ModbusClientProtocol