Пример #1
0
def io_loop_factory(host="127.0.0.1",
                    port=Defaults.Port,
                    framer=None,
                    source_address=None,
                    timeout=None,
                    **kwargs):
    """
    Factory to create Tornado based asynchronous tcp clients
    :param host: Host IP address
    :param port: Port
    :param framer: Modbus Framer
    :param source_address: Bind address
    :param timeout: Timeout in seconds
    :param kwargs:
    :return: event_loop_thread and tornado future
    """
    from tornado.ioloop import IOLoop
    from pymodbus.client.asynchronous.tornado import AsyncModbusTCPClient as \
        Client

    ioloop = IOLoop()
    protocol = EventLoopThread("ioloop", ioloop.start, ioloop.stop)
    protocol.start()

    client = Client(host=host,
                    port=port,
                    framer=framer,
                    source_address=source_address,
                    timeout=timeout,
                    ioloop=ioloop,
                    **kwargs)

    future = client.connect()

    return protocol, future
Пример #2
0
def io_loop_factory(host="127.0.0.1", port=Defaults.Port, framer=None,
                    source_address=None, timeout=None, **kwargs):
    """
    Factory to create Tornado based asynchronous tcp clients
    :param host: Host IP address
    :param port: Port
    :param framer: Modbus Framer
    :param source_address: Bind address
    :param timeout: Timeout in seconds
    :param kwargs:
    :return: event_loop_thread and tornado future
    """
    from tornado.ioloop import IOLoop
    from pymodbus.client.asynchronous.tornado import AsyncModbusTCPClient as \
        Client

    ioloop = IOLoop()
    protocol = EventLoopThread("ioloop", ioloop.start, ioloop.stop)
    protocol.start()

    client = Client(host=host, port=port, framer=framer,
                    source_address=source_address,
                    timeout=timeout, ioloop=ioloop, **kwargs)

    future = client.connect()

    return protocol, future
Пример #3
0
def reactor_factory(host="127.0.0.1", port=Defaults.Port, framer=None,
                    source_address=None, timeout=None, **kwargs):
    """
    Factory to create twisted tcp asynchronous client
    :param host: Host IP address
    :param port: Port
    :param framer: Modbus Framer
    :param source_address: Bind address
    :param timeout: Timeout in seconds
    :param kwargs:
    :return: event_loop_thread and twisted_deferred
    """
    from twisted.internet import reactor, protocol
    from pymodbus.client.asynchronous.twisted import ModbusTcpClientProtocol

    deferred = protocol.ClientCreator(
        reactor, ModbusTcpClientProtocol
    ).connectTCP(host, port, timeout=timeout, bindAddress=source_address)

    callback = kwargs.get("callback")
    errback = kwargs.get("errback")

    if callback:
        deferred.addCallback(callback)

    if errback:
        deferred.addErrback(errback)

    protocol = EventLoopThread("reactor", reactor.run, reactor.stop,
                               installSignalHandlers=0)
    protocol.start()

    return protocol, deferred
Пример #4
0
def reactor_factory(host="127.0.0.1",
                    port=Defaults.Port,
                    framer=None,
                    source_address=None,
                    timeout=None,
                    **kwargs):
    """
    Factory to create twisted tcp asynchronous client
    :param host: Host IP address
    :param port: Port
    :param framer: Modbus Framer
    :param source_address: Bind address
    :param timeout: Timeout in seconds
    :param kwargs:
    :return: event_loop_thread and twisted_deferred
    """
    from twisted.internet import reactor, protocol
    from pymodbus.client.asynchronous.twisted import ModbusTcpClientProtocol

    deferred = protocol.ClientCreator(reactor,
                                      ModbusTcpClientProtocol).connectTCP(
                                          host,
                                          port,
                                          timeout=timeout,
                                          bindAddress=source_address)

    callback = kwargs.get("callback")
    errback = kwargs.get("errback")

    if callback:
        deferred.addCallback(callback)

    if errback:
        deferred.addErrback(errback)

    protocol = EventLoopThread("reactor",
                               reactor.run,
                               reactor.stop,
                               installSignalHandlers=0)
    protocol.start()

    return protocol, deferred