Skip to content

Commit

Permalink
report error if USBTMC refresh button fails
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Feb 5, 2025
1 parent 4587c03 commit f719719
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/eez-studio-ui/notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function warn(message: string, options?: ToastOptions) {
}

export function error(message: string, options?: ToastOptions) {
return toast.error(message, options);
return toast.error(message, Object.assign({ autoClose: false }, options));
}

export function update(toastId: ToastId, options: UpdateOptions) {
Expand Down
24 changes: 16 additions & 8 deletions packages/instrument/window/connection-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { observable, action, runInAction, autorun, makeObservable } from "mobx";
import { observer } from "mobx-react";
const os = require("os");

import * as notification from "eez-studio-ui/notification";

import { objectClone } from "eez-studio-shared/util";

import {
Expand Down Expand Up @@ -181,7 +183,7 @@ export const ConnectionProperties = observer(

// TODO doesn't work on Raspbian
if (process.arch != "arm") {
await this.refreshUsbDevices();
await this.refreshUsbDevices(false);
}
} else {
this.initUsbDevices();
Expand Down Expand Up @@ -357,22 +359,28 @@ export const ConnectionProperties = observer(
this.selectedUsbDeviceIndex = selectedUsbDeviceIndex;
}

async refreshUsbDevices() {
async refreshUsbDevices(reportError: boolean) {
const { getUsbDevices } =
require("instrument/connection/interfaces/usbtmc") as typeof UsbTmcModule;

const usbDevices = await getUsbDevices();
try {
const usbDevices = await getUsbDevices();

runInAction(() => {
devices.usbDevices = usbDevices;
});
runInAction(() => {
devices.usbDevices = usbDevices;
});

this.initUsbDevices();
this.initUsbDevices();
} catch (err) {
if (reportError) {
notification.error(err.toString());
}
}
}

onRefreshUsbDevices = (event: React.MouseEvent) => {
event.preventDefault();
this.refreshUsbDevices();
this.refreshUsbDevices(true);
};

refreshVisaResources(includeNetworkResources: boolean) {
Expand Down

0 comments on commit f719719

Please sign in to comment.