Interfaces

From SweepMe! Wiki
Jump to navigation Jump to search

Interfaces allow other programs to drive SweepMe! remotely. They are a Pro feature.

The available interfaces are managed via menu "Tools" → "Interfaces". Each interface can be started/stopped on demand or set to launch automatically with SweepMe!. All interfaces share the same command vocabulary documented below; they only differ in the transport (HTTP, raw TCP, WebSocket, serial COM).

Commands

Every interface forwards incoming requests to the SweepMe! ActionManager, which exposes a fixed set of named functions. Command names are lower-case and use underscores; arguments are separated by space (text protocol) or passed as a JSON array (JSON protocol). Each command returns either a plain string or a JSON-serialisable object.

Status & info

  • hello — returns "hello". Useful as a heartbeat / smoke test.
  • get_version — returns the SweepMe! version string (e.g. "1.5.8.5").
  • is_running — returns true / false.
  • is_paused — returns true / false.
  • get_status — returns a JSON object with running, paused, version, current branch, time_elapsed, time_progress, time_index, time_stamp, time_left, and a data_saved flag.
  • get_measurement_progress — leaner status payload optimised for polling: running, paused, branch, max_branch, time_elapsed_s, time_progress, time_index, time_left_s.
  • get_functions — returns the list of all registered command names. Pass a single argument false to also include commands that require arguments or return data.


Parameter & data access

  • get_parameters — returns the list of available parameter keys (compare with the Parameters widget).
  • get_value — accepts one or more parameter keys, returns the values joined into a single space-separated string. Use when you only need a short text rendering, e.g. for the plain-text /api/ endpoint.
  • get_values — accepts one or more parameter keys, returns a JSON object mapping each requested key to its value. Unknown keys come back as "Error: key is unknown".
  • get_all_values — takes no arguments, returns every registered parameter as a JSON object.

Measurement control

  • run — start a measurement.
  • stop — stop the running measurement.
  • pause — pause the running measurement.
  • resume — resume after a pause.
  • toggle_pause — pause if running, resume if paused.
  • skip_current_branch — abort the current sequencer branch and continue with the next one.

File & save

  • set_filename — sets the file-name field in the Save Bar.
  • set_folder — sets the folder field in the Save Bar.
  • save_data — triggers the "Save data" action on the temp data of the last run (using the current Save Bar values).

Setting management

  • get_current_setting — returns the path of the currently loaded .set file, or an empty string if no setting is loaded.
  • load_setting — accepts an absolute path to a .set file and loads it. Only works when no measurement is running.

Driver versions

  • get_driver_version — accepts a driver name, returns the active version string.
  • get_available_driver_versions — accepts a driver name, returns a list of version dicts (id, version, origin, path, active).
  • set_driver_version — accepts driver name and version id, switches the driver to that version. Only works when no measurement is running.

Module versions

  • get_module_version — same as above, for modules.
  • get_available_module_versions — same as above, for modules.
  • set_module_version — same as above, for modules.

Debug & utility

  • get_debug_log — returns the last N lines of the debug log. Optional arguments: lines (int, default 100) and since_last_run (bool, default false).
  • print — prints arguments to the Debug widget, returns "Ok".
  • debug — emits a timestamped debug message, returns "Ok".

Application control

  • close_sweepme — closes SweepMe! gracefully without prompting for unsaved changes. Only works when no measurement is running.

Interfaces

HTTP server

Exposes the commands as an HTTP service plus a built-in web dashboard.

The HTTP server has two command endpoints:

POST /api/

Plain-text protocol. The request body is a single line of command arg1 arg2 … separated by spaces. The response body is the raw return value as text. Convenient for shell tools and quick tests.

POST /json/

JSON protocol. The request body is {"command": "...", "args": [...], "kwargs": {...}}. The response is {"request": "...", "status": "SUCCESS"|"ERROR", "response": ...} where response is the original return value (string, list, dict, ...).

GET /

Serves the dashboard — a single web page that exposes Run / Stop / Pause / Resume controls, live measurement progress, a parameter monitor, Save Bar controls, driver and module version management, a debug-log viewer and an arbitrary command runner. The page works in any modern browser without authentication, so the server should only be exposed on trusted networks.

The default port is 8080 (8443 with SSL). Host and port persist across sessions. To accept connections from other machines, set Host to the machine's LAN IP (or 0.0.0.0) in the Interfaces dialog and open the chosen port in the Windows firewall.

A Python automation client for the HTTP server is available as the SweepMe! MCP server.

TCPIP

Raw socket service — send each command on its own line over a TCP connection (default port 8765). Responses come back on the same socket as plain text, the same payload as the HTTP /api/ endpoint. Use localhost when the controlling script runs on the same machine as SweepMe!, or the LAN IP for remote control.

Web socket

WebSocket service (default port 8765, ws:// or wss:// when SSL is configured). Each WebSocket message is one command, the reply arrives as the next message. Best suited for browser-based dashboards or long-lived clients that want push-style updates without polling.

COM port

Connect to another computer over an RS-232 serial link and exchange commands as text lines. Default settings: baudrate 9600, line terminator \n (LF), 8 data bits, 1 stop bit, no parity. Use the "Find ports" button in the Interfaces dialog to refresh the COM port list.

Authentication & security

The interfaces have an access-code mechanism in the protocol but no GUI to set one yet, so in practice all running interfaces are unauthenticated. Restrict the listening host to localhost or a trusted LAN when possible, and prefer running SweepMe! behind a VPN when remote access from outside the lab is needed.

SSL/TLS for HTTPS / WSS is supported but currently requires registering the certificate manually under HKLM\SOFTWARE\SweepMe\Server\SSL (see InterfaceManager.SSLProvider). Without a certificate the server falls back to plain HTTP / WS.