Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions .github/workflows/desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ jobs:
# bundle.resources picks it up.
run: pyinstaller resistamet-api.spec --noconfirm --clean --distpath desktop/sidecar

- name: Smoke-test the frozen backend (handshake + /health)
- name: Smoke-test the frozen backend (handshake, /health, WebSocket upgrade)
shell: python
run: |
import json, subprocess, sys, time, urllib.request, os
import http.client, json, subprocess, sys, time, urllib.request, os
from urllib.parse import urlsplit
exe = os.path.join("desktop", "sidecar", "resistamet-api",
"resistamet-api.exe" if os.name == "nt" else "resistamet-api")
proc = subprocess.Popen([exe, "--port", "0", "--simulate", "--config", "ci-config.json"],
Expand All @@ -87,6 +88,18 @@ jobs:
info = json.loads(line)
with urllib.request.urlopen(info["url"] + "/health", timeout=10) as r:
assert r.status == 200, r.status
# The desktop UI lives on this socket. uvicorn answers 404 here when
# its WebSocket implementation did not make it into the bundle.
parts = urlsplit(info["url"])
conn = http.client.HTTPConnection(parts.hostname, parts.port, timeout=10)
conn.request("GET", "/session/events/ws?token=" + info["token"], headers={
"Connection": "Upgrade", "Upgrade": "websocket",
"Sec-WebSocket-Version": "13", "Sec-WebSocket-Key": "dGhlIHNhbXBsZSBub25jZQ==",
})
status = conn.getresponse().status
conn.close()
print("websocket upgrade:", status)
assert status == 101, f"WebSocket upgrade answered {status}, not 101"
proc.stdin.close()
proc.wait(timeout=60)
print("backend exited", proc.returncode)
Expand Down
54 changes: 54 additions & 0 deletions desktop/src/components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// A render error must never leave an operator looking at a blank window with
// an instrument running. The measurement lives in the backend process and is
// unaffected; what the operator needs is to know that, to see what broke, and
// a way back to the Stop button. Two boundaries use this: one around the whole
// app, one around the settings dialog body so a broken section closes with the
// dialog instead of taking the measurement view with it.

import { Component, type ErrorInfo, type ReactNode } from "react";
import { Button, Notice } from "./ui";

interface Props {
children: ReactNode;
/** Where this boundary sits, for the message: "the settings dialog". */
scope: string;
/** Offered instead of a reload when the parent can recover (close the dialog). */
onDismiss?: (() => void) | undefined;
}

interface State {
error: Error | null;
}

export class ErrorBoundary extends Component<Props, State> {
state: State = { error: null };

static getDerivedStateFromError(error: Error): State {
return { error };
}

componentDidCatch(error: Error, info: ErrorInfo): void {
console.error(`render error in ${this.props.scope}`, error, info.componentStack);
}

render(): ReactNode {
const { error } = this.state;
if (error === null) return this.props.children;
return (
<div role="alert" style={{ padding: "1rem", display: "grid", gap: "0.75rem" }}>
<Notice tone="danger">
Display error in {this.props.scope}: {error.message}. A running measurement is unaffected: it lives in the
backend, not in this window.
</Notice>
<div style={{ display: "flex", gap: "0.5rem" }}>
{this.props.onDismiss ? (
<Button variant="primary" onClick={this.props.onDismiss}>
Close
</Button>
) : null}
<Button onClick={() => window.location.reload()}>Reload the window</Button>
</div>
</div>
);
}
}
149 changes: 76 additions & 73 deletions desktop/src/components/dialogs/SettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { InstrumentInfo, Profile, VisaBackend } from "../../lib/api";
import { ApiError } from "../../lib/api";
import { useSession } from "../../state/session";
import { setTheme, useUi } from "../../state/ui";
import { ErrorBoundary } from "../ErrorBoundary";
import { FieldRow } from "../forms/SettingsForm";
import { Button, Dialog, Field, Input, Notice, Select } from "../ui";
import styles from "./dialogs.module.css";
Expand Down Expand Up @@ -153,85 +154,87 @@ export function SettingsDialog({ onClose }: Props) {
))}
</nav>
<div className={styles.settingsBody}>
{error ? <Notice tone="danger">{error}</Notice> : null}
{profile === null && !error ? <div className={styles.muted}>Loading…</div> : null}
<ErrorBoundary scope="the settings dialog" onDismiss={onClose} key={section}>
{error ? <Notice tone="danger">{error}</Notice> : null}
{profile === null && !error ? <div className={styles.muted}>Loading…</div> : null}

{profile && section === "timing"
? TIMING.map((spec) => (
<FieldRow
key={spec.key}
spec={spec}
meta={meta("InstrumentSettings")[spec.key] ?? {}}
value={measurement[spec.key]}
onChange={(v) => set("measurement", spec.key, v)}
disabled={running}
/>
))
: null}
{profile && section === "timing"
? TIMING.map((spec) => (
<FieldRow
key={spec.key}
spec={spec}
meta={meta("InstrumentSettings")[spec.key] ?? {}}
value={measurement[spec.key]}
onChange={(v) => set("measurement", spec.key, v)}
disabled={running}
/>
))
: null}

{profile && section === "instrument" ? <InstrumentSection running={running} /> : null}
{profile && section === "instrument" ? <InstrumentSection running={running} /> : null}

{profile && section === "aux"
? AUX.map((spec) => (
<FieldRow
key={spec.key}
spec={spec}
meta={meta("AuxSensorSettings")[spec.key] ?? {}}
value={measurement[spec.key]}
onChange={(v) => set("measurement", spec.key, v)}
disabled={running}
/>
))
: null}
{profile && section === "aux"
? AUX.map((spec) => (
<FieldRow
key={spec.key}
spec={spec}
meta={meta("AuxSensorSettings")[spec.key] ?? {}}
value={measurement[spec.key]}
onChange={(v) => set("measurement", spec.key, v)}
disabled={running}
/>
))
: null}

{profile && section === "safety"
? SAFETY.map((spec) => (
<FieldRow
key={spec.key}
spec={spec}
meta={meta("SafetySettings")[spec.key] ?? {}}
value={measurement[spec.key]}
onChange={(v) => set("measurement", spec.key, v)}
disabled={running}
/>
))
: null}
{profile && section === "safety"
? SAFETY.map((spec) => (
<FieldRow
key={spec.key}
spec={spec}
meta={meta("SafetySettings")[spec.key] ?? {}}
value={measurement[spec.key]}
onChange={(v) => set("measurement", spec.key, v)}
disabled={running}
/>
))
: null}

{profile && section === "files" ? (
<>
{FILES.map((spec) => (
<FieldRow
key={spec.key}
spec={spec}
meta={meta("FileSettings")[spec.key] ?? {}}
value={(draft.file ?? {})[spec.key]}
onChange={(v) => set("file", spec.key, v)}
disabled={running}
/>
))}
<div className={styles.subhead}>Output</div>
{OUTPUT.map((spec) => (
<FieldRow
key={spec.key}
spec={spec}
meta={meta("OutputSettings")[spec.key] ?? {}}
value={(draft.output ?? {})[spec.key]}
onChange={(v) => set("output", spec.key, v)}
disabled={running}
/>
))}
</>
) : null}
{profile && section === "files" ? (
<>
{FILES.map((spec) => (
<FieldRow
key={spec.key}
spec={spec}
meta={meta("FileSettings")[spec.key] ?? {}}
value={(draft.file ?? {})[spec.key]}
onChange={(v) => set("file", spec.key, v)}
disabled={running}
/>
))}
<div className={styles.subhead}>Output</div>
{OUTPUT.map((spec) => (
<FieldRow
key={spec.key}
spec={spec}
meta={meta("OutputSettings")[spec.key] ?? {}}
value={(draft.output ?? {})[spec.key]}
onChange={(v) => set("output", spec.key, v)}
disabled={running}
/>
))}
</>
) : null}

{section === "display" ? (
<Field label="Theme" hint="Stored on this computer, not in the profile.">
<Select value={ui.theme} onChange={(e) => setTheme(e.target.value as typeof ui.theme)}>
<option value="dark">Dark</option>
<option value="light">Light</option>
<option value="system">Follow system</option>
</Select>
</Field>
) : null}
{section === "display" ? (
<Field label="Theme" hint="Stored on this computer, not in the profile.">
<Select value={ui.theme} onChange={(e) => setTheme(e.target.value as typeof ui.theme)}>
<option value="dark">Dark</option>
<option value="light">Light</option>
<option value="system">Follow system</option>
</Select>
</Field>
) : null}
</ErrorBoundary>
</div>
</div>
</Dialog>
Expand Down
41 changes: 30 additions & 11 deletions desktop/src/components/forms/SettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ export function SettingsForm({ mode, groups, values, onChange, issues = [], disa
{groups.map((group) => (
<div key={group.title}>
<SectionTitle>{group.title}</SectionTitle>
{group.fields.map((spec) => (
<FieldRow
key={spec.key}
spec={spec}
meta={meta[spec.key] ?? {}}
value={values[spec.key]}
onChange={(v) => onChange(spec.key, v)}
issue={issueFor(spec.key)}
disabled={disabled}
/>
))}
{group.fields.map((spec) => {
const overridden = spec.overriddenBy !== undefined && values[spec.overriddenBy.key] === spec.overriddenBy.when;
return (
<FieldRow
key={spec.key}
spec={overridden ? { ...spec, hint: spec.overriddenBy!.hint } : spec}
meta={meta[spec.key] ?? {}}
value={values[spec.key]}
onChange={(v) => onChange(spec.key, v)}
issue={issueFor(spec.key)}
disabled={disabled || overridden}
/>
);
})}
</div>
))}
</>
Expand Down Expand Up @@ -81,6 +84,22 @@ export function FieldRow({ spec, meta, value, onChange, issue, disabled }: RowPr
);
}

if (meta.type === "string") {
// Free text: an address, a driver name, a directory. Never the numeric
// input, whose formatter would throw on a string mid-render.
return (
<Field label={spec.label} hint={spec.hint} error={error} stacked>
<Input
className="mono"
value={typeof value === "string" ? value : String(meta.default ?? "")}
disabled={disabled}
invalid={issue !== undefined}
onChange={(e) => onChange(e.target.value)}
/>
</Field>
);
}

if (meta.type === "integer") {
// Counts are counts: no prefixes, no decimals.
const current = typeof value === "number" ? value : ((meta.default as number | undefined) ?? 0);
Expand Down
11 changes: 2 additions & 9 deletions desktop/src/components/plot/LivePlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useEffect, useRef } from "react";
import uPlot, { type AlignedData, type Options, type Series } from "uplot";
import "uplot/dist/uPlot.min.css";
import { getSeries, getSamplesVersion } from "../../state/samples";
import { engineering } from "../../lib/format";
import { axisLabels, engineering } from "../../lib/format";
import styles from "./LivePlot.module.css";

export interface TraceSpec {
Expand Down Expand Up @@ -70,14 +70,7 @@ export function LivePlot({ traces, mode, windowS = 0, fps = 30 }: Props) {
})),
];

const axisValues = (unit: string) => (_u: uPlot, ticks: number[]) => {
// Pick one prefix for the whole axis from the largest tick so labels
// read as a scale, not a jumble of prefixes.
const largest = ticks.reduce((m, v) => Math.max(m, Math.abs(v)), 0);
const ref = engineering(largest || 1, unit);
const factor = largest ? Number(ref.mantissa) / largest : 1;
return ticks.map((v) => (v * factor).toPrecision(4).replace(/\.?0+$/, "") + (ref.unit ? ` ${ref.unit}` : ""));
};
const axisValues = (unit: string) => (_u: uPlot, ticks: number[]) => axisLabels(ticks, unit);

const leftUnit = traces.find((t) => !t.rightAxis)?.unit ?? "";
const rightUnit = traces.find((t) => t.rightAxis)?.unit ?? "";
Expand Down
9 changes: 2 additions & 7 deletions desktop/src/components/plot/XYPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { useEffect, useRef } from "react";
import uPlot, { type AlignedData, type Options } from "uplot";
import "uplot/dist/uPlot.min.css";
import { engineering } from "../../lib/format";
import { axisLabels } from "../../lib/format";
import styles from "./LivePlot.module.css";

export interface XYSeries {
Expand Down Expand Up @@ -40,12 +40,7 @@ export function XYPlot({ series, xUnit, yUnit }: Props) {
const gridLine = computed.getPropertyValue("--grid-line").trim() || "rgba(255,255,255,.08)";
const font = "11px " + computed.getPropertyValue("--font-mono");

const axisValues = (unit: string) => (_u: uPlot, ticks: number[]) => {
const largest = ticks.reduce((m, v) => Math.max(m, Math.abs(v)), 0);
const ref = engineering(largest || 1, unit);
const factor = largest ? Number(ref.mantissa) / largest : 1;
return ticks.map((v) => (v * factor).toPrecision(4).replace(/\.?0+$/, "") + (ref.unit ? ` ${ref.unit}` : ""));
};
const axisValues = (unit: string) => (_u: uPlot, ticks: number[]) => axisLabels(ticks, unit);

// uPlot wants one shared x array. Series with different x sets are
// merged onto the union of x values, with nulls where a series has none.
Expand Down
22 changes: 20 additions & 2 deletions desktop/src/lib/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export interface FieldSpec<K extends string = string> {
hint?: string;
/** Enum labels, when the raw values are not self-explanatory. */
options?: Record<string, string>;
/** The instrument ignores this field while another field has a given
* value; the row is shown disabled with `hint` so the number on screen is
* not mistaken for the number in use. */
overriddenBy?: { key: string; when: unknown; hint: string };
}

export interface FieldGroup<K extends string = string> {
Expand All @@ -35,8 +39,22 @@ export const RESISTANCE_FIELDS: FieldGroup<Keys<ResistanceSettings>>[] = [
{
title: "Source",
fields: [
{ key: "res_test_current", label: "Test current", unit: "A" },
{ key: "res_voltage_compliance", label: "Voltage compliance", unit: "V" },
// With Auto range on, the 2400's auto-ohms picks the test current per
// range and sets its own voltage limit (2.1 V seen for a 0.5 V request);
// the CSV's Current column and effective.voltage_compliance_V record
// what it chose. Bench, 2026-09-18.
{
key: "res_test_current",
label: "Test current",
unit: "A",
overriddenBy: { key: "res_auto_range", when: true, hint: "Chosen by the instrument per range while Auto range is on." },
},
{
key: "res_voltage_compliance",
label: "Voltage compliance",
unit: "V",
overriddenBy: { key: "res_auto_range", when: true, hint: "Set by the instrument while Auto range is on; the file records the value in force." },
},
],
},
{
Expand Down
Loading
Loading