Quick start
Prerequisites
Run on Windows with SmartLab Studio II x64 v5.3.200.0. Install the Python package with its project dependencies (pip install .); pywinauto and comtypes are required. Open the SmartLab Studio II GUI and select the Z-axis Basic screen before parameter operations.
Windows interactive session via PyCharm or SSH
Python launched through a remote Windows connection can run in a different session or desktop from SmartLab Studio II. run_interactive.py uses PsExec -i to start pythonw.exe from the same Python environment in the selected logon session. Check the Windows session ID with query user; 1 is an example. The default PsExec path is C:\Tools\PsExec64.exe. Use --psexec for another location. GUI automation requires access to the target desktop and a desktop ready for input.
In a PyCharm Remote Development Python run configuration, set Interpreter options as follows and choose the target in the script field.
"C:\work\smartlab_studio_ctrl\run_interactive.py" --session 1
Over SSH, run this from the project root on Windows.
python .\run_interactive.py --session 1 .\example\uia_local\capture_screenshot.py
Starting in v0.2.8, the target script’s directory becomes its working directory. This example saves to example\uia_local\screenshot_local.png. Python stdout, stderr, and tracebacks are relayed to the caller. The launcher prefers the script’s recorded exit code. If the result is absent, it uses PsExec’s nonzero status or returns 1 when PsExec returned 0.
When the launcher handles a stop request, it notifies the child Python process and returns 130. The child also monitors the launcher’s lifetime and forces its own exit if it is still running five seconds after the interrupt. Processes started separately by the target script may remain running.
Launcher output encoding
Starting in v0.2.10, run_interactive.py uses the same rules for any caller:
Output condition |
Encoding behavior |
|---|---|
|
Keep the standard stream settings Python selected at startup. |
No encoding is specified and the stream goes to a pipe or file |
Use UTF-8 and keep the stream’s error-handling setting. |
No encoding is specified and the stream goes directly to a terminal |
Keep Python’s standard stream settings. |
The launcher reads the target Python log as UTF-8 and decodes PsExec diagnostics separately using the Windows ANSI code page. It then writes the text to the caller using the settings above.
An SSH command without an allocated terminal uses the pipe rule when no encoding is specified. In PyCharm Remote Development, the Run tool window must read the same encoding the launcher emits. If text is garbled, check that the run uses the updated launcher and that the active output encoding and the encoding supplied to Python agree.
Desktop capture (v0.2.9)
On Windows x64, SmartLabCtrl.capture_screenshot() delegates to DesktopCapture, which uses WGC through Python’s windows_capture binding. It combines monitor frames using their physical screen positions and returns PNG bytes. Pass output_directory to save screenshot_local.png in an existing directory. get_screenshot_state() returns READY, STARTING, CAPTURING, or SAVING. See capture over gRPC for remote client-side saving.
Diagnose Windows sessions and capture
Place --session-info before the target script. The launcher logs the Windows session IDs, logged-on users, and connection states, followed by the account and session ID of the Python process that runs the script. Python callers can use get_windows_sessions(), get_current_session_id(), and get_current_windows_user() from run_interactive.py to display a state or handle a missing session before launch.
Disconnecting RDP leaves the user’s session and applications running. Reconnecting can resume the same session. Signing out ends that user’s session, so its desktop is no longer a capture target. The session list can also contain service and listener sessions. Microsoft’s RDP disconnect reference · Windows desktop sessions
On the Windows Pro test host, both users’ sessions remained listed, with the connected user ACTIVE and the other DISCONNECTED. Windows Enterprise multi-session supports multiple concurrently active user sessions in a different configuration. Microsoft’s multi-session FAQ
WGC captured the desktop when hpc was active and Python ran as hpc. Launching from an SSH connection as nakada into the same session started Python as nakada in session 2, and WGC failed to create its GraphicsCaptureItem.
After both RDP clients disconnected without signing out, hpc still had session 2 and nakada had session 3. A temporary task for each logged-on user started Python in that user’s session, but neither process could create a GraphicsCaptureItem. Launching from SSH as nakada into the disconnected hpc session failed at the same point. Inspect connection status, session ownership, and the Python process account together.
Read settings and status
from smartlab_studio_ctrl import SmartLabUIA
smartlab = SmartLabUIA()
print(smartlab.get_start())
print(smartlab.get_step())
print(smartlab.is_running())
print(smartlab.get_remaining_time())
Change settings and start a scan
print(smartlab.set_start("-0.90000"))
print(smartlab.set_stop_position("1.20000"))
smartlab.scan()
This changes instrument settings and requests measurement. Values are examples taken from the current sample; verify permitted values before operating. scan() does not wait for completion.
Export
filename = smartlab.export_data(filename=None, save=False)
print(filename)
save=False leaves the Windows Save dialog open. save=True invokes the Save button. A supplied filename replaces the Save dialog’s filename field; None keeps its default. Export dialog data selection remains at its GUI default. This is not a file-content verification operation.
Logging
smartlab = SmartLabUIA(logger=my_logger)
# or SmartLabUIA(log_level="DEBUG")