# Web frontend v3.x

TO BE DOCUMENTED.

## pymodbus.simulator (v3.x)

The easiest way to run the simulator with web is to use “pymodbus.simulator” from the commandline.

TO BE DOCUMENTED.

HTTP server for modbus simulator.

class pymodbus.server.simulator.http_server.CallTracer(call: bool = False, fc: int = -1, address: int = -1, count: int = -1, data: bytes = b'')

  Bases: `object`

  Define call/response traces.

class pymodbus.server.simulator.http_server.CallTypeMonitor(active: bool = False, trace_response: bool = False, range_start: int = -1, range_stop: int = -1, function: int = -1, hex: bool = False, decode: bool = False)

  Bases: `object`

  Define Request/Response monitor.

class pymodbus.server.simulator.http_server.CallTypeResponse(active: int = -1, split: int = 0, delay: int = 0, junk_len: int = 10, error_response: int = 0, change_rate: int = 0, clear_after: int = 1)

  Bases: `object`

  Define Response manipulation.

class pymodbus.server.simulator.http_server.ModbusSimulatorServer(modbus_server: str = 'server', modbus_device: str = 'device', http_host: str = '0.0.0.0', http_port: int = 8080, log_file: str = 'server.log', json_file: str = 'setup.json', custom_actions_module: str | None = None)

  Bases: `object`

  ModbusSimulatorServer.

  Parameters:

    - modbus_server – Server name in json file (default: “server”)

    - modbus_device – Device name in json file (default: “client”)

    - http_host – TCP host for HTTP (default: “localhost”)

    - http_port – TCP port for HTTP (default: 8080)

    - json_file – setup file (default: “setup.json”)

    - custom_actions_module – python module with custom actions (default: none)

  if either http_port or http_host is none, HTTP will not be started. This class starts a http server, that serves a couple of endpoints:

  - “<addr>/” static files

  - “<addr>/api/log” log handling, HTML with GET, REST-API with post

  - “<addr>/api/registers” register handling, HTML with GET, REST-API with post

  - “<addr>/api/calls” call (function code / message) handling, HTML with GET, REST-API with post

  - “<addr>/api/server” server handling, HTML with GET, REST-API with post

  Example:

      from pymodbus import ModbusSimulatorServer

      async def run():
          simulator = ModbusSimulatorServer(
              modbus_server="my server",
              modbus_device="my device",
              http_host="localhost",
              http_port=8080)
          await simulator.run_forever(only_start=True)
          ...
          await simulator.stop()

  async start_modbus_server(app)

    Start Modbus server as asyncio task.

  async stop_modbus_server(app)

    Stop modbus server.

  async run_forever(only_start=False)

    Start modbus and http servers.

  async stop()

    Stop modbus and http servers.

  async handle_html_static(request: Request)

    Handle static html.

  async handle_html(request: Request)

    Handle html.

  async handle_json(request: Request)

    Handle api registers.

  build_html_registers(params, html)

    Build html registers page.

  build_html_calls(params: dict, html: str) → str

    Build html calls page.

  build_html_log(_params, html)

    Build html log page.

  build_html_server(_params, html)

    Build html server page.

  build_json_registers(params)

    Build json registers response.

  build_json_calls(params: dict) → dict

    Build json calls response.

  build_json_log(params)

    Build json log page.

  build_json_server(params)

    Build html server page.

  helper_handle_submit(params, submit_actions)

    Build html register submit.

  action_clear(_params, _range_start, _range_stop)

    Clear register filter.

  action_stop(_params, _range_start, _range_stop)

    Stop call monitoring.

  action_reset(_params, _range_start, _range_stop)

    Reset call simulation.

  action_add(params, range_start, range_stop)

    Build list of registers matching filter.

  action_monitor(params, range_start, range_stop)

    Start monitoring calls.

  action_set(params, _range_start, _range_stop)

    Set register value.

  action_simulate(params, _range_start, _range_stop)

    Simulate responses.