Skip to content

Commit 4dd4298

Browse files
committed
Merge branch 'main' into 14_11-add-extruder
2 parents 7efcafb + 56f9214 commit 4dd4298

File tree

6 files changed

+79
-17
lines changed

6 files changed

+79
-17
lines changed

src/blueapi/BlueapiComponents.tsx

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import {
55
Button,
66
Snackbar,
77
SnackbarCloseReason,
8-
styled,
98
Tooltip,
109
Typography,
1110
} from "@mui/material";
11+
import { forceString, ReadPvRawValue } from "../pv/util";
12+
import { RawValue } from "../pv/types";
1213

1314
type SeverityLevel = "success" | "info" | "warning" | "error";
1415
type VariantChoice = "outlined" | "contained";
@@ -36,27 +37,77 @@ type RunPlanButtonProps = {
3637
// This will be another PR
3738
// See https://github.com/DiamondLightSource/mx-daq-ui/issues/71
3839

40+
/**
41+
* Read the full visit path from the visit PV set by the beamline staff.
42+
* @returns {string} the full visit pV /dls/i24/data/{year}/{visit}
43+
*/
44+
export function readVisitFromPv(): string {
45+
const fullVisitPath: RawValue = ReadPvRawValue({
46+
label: "visit",
47+
pv: "ca://BL24I-MO-IOC-13:GP100",
48+
});
49+
const visitString: string = forceString(fullVisitPath);
50+
return visitString;
51+
}
52+
53+
/**
54+
* Parse the full visit path and return only the instrument session.
55+
* An error will be raised if the instrument session value is undefined or
56+
* if the PV is not connected.
57+
* @param {string} visit The full visit path
58+
* @returns {string} Only the instrument session part of the visit path
59+
*/
60+
export function parseInstrumentSession(visit: string): string {
61+
let instrumentSession: string | undefined;
62+
if (visit === "not connected" || visit === "undefined") {
63+
const msg =
64+
"Unable to run plan as instrument session not set. Please check visit PV.";
65+
throw new Error(msg);
66+
} else {
67+
instrumentSession = visit.split("/").filter(Boolean).at(-1);
68+
if (!instrumentSession) {
69+
throw new Error(
70+
"Unable to run plan as something appears to be wrong with visit path"
71+
);
72+
}
73+
}
74+
return instrumentSession;
75+
}
76+
3977
export function RunPlanButton(props: RunPlanButtonProps) {
4078
const [openSnackbar, setOpenSnackbar] = React.useState<boolean>(false);
4179
const [msg, setMsg] = React.useState<string>("Running plan...");
4280
const [severity, setSeverity] = React.useState<SeverityLevel>("info");
4381

82+
const fullVisit = readVisitFromPv();
83+
let instrumentSession: string;
84+
4485
const params = props.planParams ? props.planParams : {};
4586
const variant = props.btnVariant ? props.btnVariant : "outlined";
4687
const size = props.btnSize ? props.btnSize : "medium";
4788

4889
const handleClick = () => {
4990
setOpenSnackbar(true);
50-
submitAndRunPlanImmediately({
51-
planName: props.planName,
52-
planParams: params,
53-
}).catch((error) => {
91+
try {
92+
instrumentSession = parseInstrumentSession(fullVisit);
93+
submitAndRunPlanImmediately({
94+
planName: props.planName,
95+
planParams: params,
96+
instrumentSession: instrumentSession,
97+
}).catch((error) => {
98+
setSeverity("error");
99+
setMsg(
100+
`Failed to run plan ${props.planName}, see console and logs for full error`
101+
);
102+
console.log(`${msg}. Reason: ${error}`);
103+
});
104+
} catch (error) {
54105
setSeverity("error");
55106
setMsg(
56-
`Failed to run plan ${props.planName}, see console and logs for full error`
107+
`Failed to run plan ${props.planName}, please check visit PV is set.`
57108
);
58-
console.log(`${msg}. Reason: ${error}`);
59-
});
109+
console.log(`An error occurred ${error}`);
110+
}
60111
};
61112

62113
const handleSnackbarClose = (

src/blueapi/blueapi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const BLUEAPI_SOCKET: string = import.meta.env.VITE_BLUEAPI_SOCKET;
55
type BlueApiRequestBody = {
66
planName: string;
77
planParams: object;
8-
// instrumentSession: string;
8+
instrumentSession: string;
99
};
1010
// Update to latest blueapi (> 1.0.0), See https://github.com/DiamondLightSource/mx-daq-ui/issues/72
1111
// @todo check if blueapi request still works if planParams optional (since some times there's none)

src/pv/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function pvIntArrayToString(value: RawValue): string {
5959
}
6060
}
6161

62-
function ReadPvRawValue(props: PvDescription): RawValue {
62+
export function ReadPvRawValue(props: PvDescription): RawValue {
6363
const [_effectivePvName, connected, _readonly, latestValue] = useConnection(
6464
props.label,
6565
props.pv

src/screens/BeamlineStats.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ function ScanStatus(props: Omit<StateBoxProps, "children">) {
8585
>
8686
<PvComponent
8787
label="Scan Status"
88-
pv="ca://BL24I-MO-STEP-14:signal:P2401"
88+
pv="ca://BL24I-MO-STEP-14:pmac:read:P2401"
8989
transformValue={forceString}
9090
/>
9191
<PvComponent
9292
label="Frames Counter"
93-
pv="ca://BL24I-MO-STEP-14:signal:P2402"
93+
pv="ca://BL24I-MO-STEP-14:pmac:read:P2402"
9494
transformValue={forceString}
9595
/>
9696
</StateCard>

src/screens/DetectorMotion.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function DetectorMotionTabPanel() {
1818
return (
1919
<Box>
2020
<Stack spacing={2} alignItems={"center"}>
21-
<RoPvBox label="Selected detector" pv="ca://ME14E-MO-IOC-01:GP101" />
21+
<RoPvBox label="Selected detector" pv="ca://BL24I-MO-IOC-13:GP101" />
2222
<RoPvBox
2323
label="Detector stage y position"
2424
pv="ca://BL24I-EA-DET-01:Y"

src/screens/OavMover.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ import { PvDescription } from "../pv/types";
3030
import { SelectionWithPlanRunner } from "../components/SelectionControl";
3131
import { BacklightPositions, ZoomLevels } from "../pv/enumPvValues";
3232
import oxfordChipDiagram from "../assets/Oxford Chip Diagram.excalidraw.svg";
33-
import { RunPlanButton } from "../blueapi/BlueapiComponents";
33+
import {
34+
parseInstrumentSession,
35+
readVisitFromPv,
36+
RunPlanButton,
37+
} from "../blueapi/BlueapiComponents";
3438

3539
const buttonStyle = {
3640
color: "white",
@@ -391,6 +395,9 @@ export function OavMover() {
391395
const [pixelsPerMicron, setPixelsPerMicron] = useState<number>(1.25);
392396
const theme = useTheme();
393397
const bgColor = theme.palette.background.paper;
398+
399+
const fullVisit = readVisitFromPv();
400+
394401
return (
395402
<div>
396403
<Grid2 container spacing={2} columns={12}>
@@ -412,11 +419,15 @@ export function OavMover() {
412419
"Not submitting plan while disconnected from PVs!"
413420
);
414421
} else {
422+
// This is an example but not useful for actual production use.
415423
submitAndRunPlanImmediately({
416424
planName: "gui_gonio_move_on_click",
417-
planParams: {
418-
position_px: [x_int, y_int],
419-
},
425+
planParams: { position_px: [x_int, y_int] },
426+
instrumentSession: parseInstrumentSession(fullVisit),
427+
}).catch((error) => {
428+
console.log(
429+
`Failed to run plan gui_gonio_move_on_click, see console and logs for full error. Reason: ${error}`
430+
);
420431
});
421432
}
422433
}}

0 commit comments

Comments
 (0)