Skip to content

Commit 8b32129

Browse files
authored
Merge pull request #74 from DiamondLightSource/72-update-blueapi
Update UI to use newer blueapi and update PVs
2 parents f615b48 + 2b4181c commit 8b32129

File tree

6 files changed

+66
-15
lines changed

6 files changed

+66
-15
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+
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+
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/CollectionPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ function FixedInputs() {
2424
<Grid2 size={12}>
2525
<PvComponent
2626
label="Visit"
27-
pv="ca://ME14E-MO-IOC-01:GP100"
27+
pv="ca://BL24I-MO-IOC-13:GP100"
2828
transformValue={forceString}
2929
/>
3030
<PvComponent
3131
label="Detector in use"
32-
pv="ca://ME14E-MO-IOC-01:GP101"
32+
pv="ca://BL24I-MO-IOC-13:GP101"
3333
transformValue={forceString}
3434
/>
3535
</Grid2>

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"

0 commit comments

Comments
 (0)