herosdevices.hardware.menlo.qwebchannel¶
Client for Qt’s WebChannel protocol over a plain websocket, without any Qt dependency.
Some instruments (for example Menlo Systems frequency combs) expose their control/status tree via Qt’s
QWebChannel protocol. The protocol implementation itself
is provided by the pywebchannel package, which has no Qt dependency. This module only supplies the
websocket transport and the endpoint’s authentication handshake on top of it.
Module Contents¶
- herosdevices.hardware.menlo.qwebchannel.QWEBCHANNEL_DEFAULT_PORT = 8002¶
- class herosdevices.hardware.menlo.qwebchannel.QWebChannelConnection(host: str, port: int = QWEBCHANNEL_DEFAULT_PORT, path: str = '/core/', user: str = 'guest', password: str = '', timeout: float = 5.0, reconnect_cooldown: float = 30.0)[source]¶
Manage a QWebChannel connection to a device over a plain websocket.
- Parameters:
host – Hostname or IP address of the websocket endpoint.
port – Port the websocket endpoint listens on.
path – Path component of the websocket URL.
user – Username used for authentication.
password – Password used for authentication.
timeout – Seconds to wait for the connection to open and the channel to initialize. Also bounds how long the underlying socket connect may block, so an unresponsive (as opposed to actively refusing) endpoint fails within timeout too, instead of hanging on the OS’s own connect timeout.
reconnect_cooldown – Minimum seconds between two connection attempts. A
connect()call made before this has elapsed since the last attempt fails immediately without touching the network, so a caller that retries on every use (likeOFC) does not hammer a device that stays unreachable for an extended period.
Note
There is no active reconnect-on-disconnect: a lost connection is only noticed and re-established the next time
connect()is called (which every read/write onOFCdoes implicitly via its _ensure_connected helper). This keeps reconnection logic in one place, serialized by a lock, instead of racing an active retry from the websocket’s own background thread against callers.- host¶
- port = 8002¶
- path = '/core/'¶
- user = 'guest'¶
- password = ''¶
- timeout = 5.0¶
- reconnect_cooldown = 30.0¶
- channel¶
- property root¶
The root object exposed by the QWebChannel endpoint, or None if not connected yet.
- send(data: str) None[source]¶
Send raw data over the websocket.
Called by
pywebchannel.qwebchannel.QWebChannel, not meant to be called directly.
- connect() None[source]¶
Open the websocket connection and wait until the channel is initialized.
Does nothing if a connection is already open and ready. Safe to call concurrently from multiple threads: only the first caller actually (re)connects, the others wait for it and then observe the result.
- Raises:
ConnectionError – The last attempt was less than reconnect_cooldown seconds ago; no new attempt was made.
TimeoutError – The connection could not be established within timeout seconds.