# `server.async` — Twisted Asynchronous Modbus Server

## API Documentation

### Implementation of a Twisted Modbus Server

class `pymodbus.server.async.``ModbusTcpProtocol`

  Implements a modbus server in twisted

  `connectionMade`()

    Callback for when a client connects

    ..note:: since the protocol factory cannot be accessed from the
      protocol __init__, the client connection made is essentially our __init__ method.
  `connectionLost`(reason)

    Callback for when a client disconnects

    Parameters: | reason – The client’s reason for disconnecting

  `dataReceived`(data)

    Callback when we receive any data

    Parameters: | data – The data sent by the client

  `_execute`(request)

    Executes the request and returns the result

    Parameters: | request – The decoded request message

  `_send`(message)

    Send a request (string) to the network

    Parameters: | message – The unencoded modbus response

class `pymodbus.server.async.``ModbusUdpProtocol`(store, framer=None, identity=None, **kwargs)

  Implements a modbus udp server in twisted

  `__init__`(store, framer=None, identity=None, **kwargs)

    Overloaded initializer for the modbus factory

    If the identify structure is not passed in, the ModbusControlBlock uses its own empty structure.

    Parameters:

    - store – The ModbusServerContext datastore
    - framer – The framer strategy to use
    - identity – An optional identify structure
    - ignore_missing_slaves – True to not send errors on a request to a missing slave

  `datagramReceived`(data, addr)

    Callback when we receive any data

    Parameters: | data – The data sent by the client

  `_execute`(request, addr)

    Executes the request and returns the result

    Parameters: | request – The decoded request message

  `_send`(message, addr)

    Send a request (string) to the network

    Parameters:

    - message – The unencoded modbus response
    - addr – The (host, port) to send the message to

class `pymodbus.server.async.``ModbusServerFactory`(store, framer=None, identity=None, **kwargs)

  Builder class for a modbus server

  This also holds the server datastore so that it is persisted between connections

  `protocol`

    alias of `ModbusTcpProtocol`

  `__init__`(store, framer=None, identity=None, **kwargs)

    Overloaded initializer for the modbus factory

    If the identify structure is not passed in, the ModbusControlBlock uses its own empty structure.

    Parameters:

    - store – The ModbusServerContext datastore
    - framer – The framer strategy to use
    - identity – An optional identify structure
    - ignore_missing_slaves – True to not send errors on a request to a missing slave

`pymodbus.server.async.``StartTcpServer`(context, identity=None, address=None, console=False, **kwargs)

  Helper method to start the Modbus Async TCP server

  Parameters:

  - context – The server data context
  - identify – The server identity to use (default empty)
  - address – An optional (interface, port) to bind to.
  - console – A flag indicating if you want the debug console
  - ignore_missing_slaves – True to not send errors on a request to a missing slave

`pymodbus.server.async.``StartUdpServer`(context, identity=None, address=None, **kwargs)

  Helper method to start the Modbus Async Udp server

  Parameters:

  - context – The server data context
  - identify – The server identity to use (default empty)
  - address – An optional (interface, port) to bind to.
  - ignore_missing_slaves – True to not send errors on a request to a missing slave

`pymodbus.server.async.``StartSerialServer`(context, identity=None, framer=<class 'pymodbus.transaction.ModbusAsciiFramer'>, **kwargs)

  Helper method to start the Modbus Async Serial server

  Parameters:

  - context – The server data context
  - identify – The server identity to use (default empty)
  - framer – The framer to use (default ModbusAsciiFramer)
  - port – The serial port to attach to
  - baudrate – The baud rate to use for the serial device
  - console – A flag indicating if you want the debug console
  - ignore_missing_slaves – True to not send errors on a request to a missing slave