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

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
_buildResponse(tid)

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
_handleResponse(reply)

Handle the processed response and link to correct deferred

Parameters:reply – The reply to process
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.ModbusClientFactory

Simple client protocol factory

protocol

alias of ModbusClientProtocol