server.sync — Twisted Synchronous Modbus Server

Module author: Galen Collins <bashwork@gmail.com>

Section author: Galen Collins <bashwork@gmail.com>

API Documentation

Implementation of a Threaded Modbus Server

class pymodbus.server.sync.ModbusRequestHandler(request, client_address, server)

Implements the modbus server protocol

This uses the socketserver.BaseRequestHandler to implement the client handler.

decode(message)

Decodes a request packet

Parameters:message – The raw modbus request packet
Returns:The decoded modbus message or None if error
execute(request)

The callback to call with the resulting message

Parameters:request – The decoded request message
finish()

Callback for when a client disconnects

handle()

Callback when we receive any data

send(message)

Send a request (string) to the network

Parameters:message – The unencoded modbus response
setup()

Callback for when a client connects

class pymodbus.server.sync.ModbusTcpServer(context, framer=None, identity=None)

A modbus threaded tcp socket server

We inherit and overload the socket server so that we can control the client threads as well as have a single server context instance.

process_request(request, client)

Callback for connecting a new client thread

Parameters:
  • request – The request to handle
  • client – The address of the client
server_close()

Callback for stopping the running server

class pymodbus.server.sync.ModbusUdpServer(context, framer=None, identity=None)

A modbus threaded udp socket server

We inherit and overload the socket server so that we can control the client threads as well as have a single server context instance.

process_request(request, client)

Callback for connecting a new client thread

Parameters:
  • request – The request to handle
  • client – The address of the client
server_close()

Callback for stopping the running server

class pymodbus.server.sync.ModbusSerialServer(context, framer=None, identity=None, **kwargs)

A modbus threaded udp socket server

We inherit and overload the socket server so that we can control the client threads as well as have a single server context instance.

serve_forever()

Callback for connecting a new client thread

Parameters:
  • request – The request to handle
  • client – The address of the client
server_close()

Callback for stopping the running server

pymodbus.server.sync.StartTcpServer(context=None, identity=None)

A factory to start and run a tcp modbus server

Parameters:
  • context – The ModbusServerContext datastore
  • identity – An optional identify structure
pymodbus.server.sync.StartUdpServer(context=None, identity=None)

A factory to start and run a udp modbus server

Parameters:
  • context – The ModbusServerContext datastore
  • identity – An optional identify structure
pymodbus.server.sync.StartSerialServer(context=None, identity=None, **kwargs)

A factory to start and run a udp modbus server

Parameters:
  • context – The ModbusServerContext datastore
  • identity – An optional identify structure