import React from "react"; import { observer } from "mobx-react"; import { Loader } from "eez-studio-ui/loader"; import { PropertyList, StaticProperty, TextInputProperty, BooleanProperty } from "eez-studio-ui/properties"; import { AlertDanger } from "eez-studio-ui/alert"; import { Toolbar } from "eez-studio-ui/toolbar"; import { ButtonAction } from "eez-studio-ui/action"; import * as notification from "eez-studio-ui/notification"; import { ConnectionProperties } from "instrument/window/connection-dialog"; import { InstrumentObject } from "instrument/instrument-object"; import { ConnectionParameters } from "instrument/connection/interface"; import type * as CatalogModule from "home/extensions-manager/catalog"; import type * as ExtensionManagerModule from "home/extensions-manager/extensions-manager"; import type { InstrumentsStore } from "home/instruments"; //////////////////////////////////////////////////////////////////////////////// export const InstrumentToolbar = observer( class InstrumentToolbar extends React.Component<{ instrument: InstrumentObject; instrumentsStore: InstrumentsStore; }> { onOpenInTab = () => { this.props.instrument.openEditor("tab"); }; onOpenInWindow = () => { this.props.instrument.openEditor("window"); }; onDelete = () => { window.postMessage( { type: "delete-instrument", instrumentId: this.props.instrument.id }, "*" ); }; render() { return ( {this.props.instrument.isUnknownExtension && ( installExtension(this.props.instrument) } /> )} {!this.props.instrumentsStore.selectInstrument && ( )} {!this.props.instrumentsStore.selectInstrument && ( )} ); } } ); //////////////////////////////////////////////////////////////////////////////// export const InstrumentProperties = observer( class InstrumentProperties extends React.Component<{ instrument: InstrumentObject; }> { render() { return ; } } ); //////////////////////////////////////////////////////////////////////////////// export const InstrumentConnection = observer( class InstrumentConnection extends React.Component<{ instrument: InstrumentObject; }> { render() { return ; } } ); //////////////////////////////////////////////////////////////////////////////// export const ConnectionParametersDetails = observer( class ConnectionParametersDetails extends React.Component<{ instrument: InstrumentObject; }> { render() { const { instrument } = this.props; if (instrument.lastConnection) { if (instrument.lastConnection.type === "ethernet") { return ( ); } else if (instrument.lastConnection.type === "serial") { return ( ); } else if (instrument.lastConnection.type === "usbtmc") { return ( ); } else if (instrument.lastConnection.type === "web-simulator") { return ( ); } else if (instrument.lastConnection.type === "visa") { return ( ); } } return null; } } ); //////////////////////////////////////////////////////////////////////////////// export async function installExtension(instrument: InstrumentObject) { const { extensionsCatalog } = require("home/extensions-manager/catalog") as typeof CatalogModule; const extension = extensionsCatalog.catalog.find( extension => extension.id === instrument.extension!.id ); if (extension) { const progressToastId = notification.info("Installing...", { autoClose: false }); const { downloadAndInstallExtension } = require("home/extensions-manager/extensions-manager") as typeof ExtensionManagerModule; await downloadAndInstallExtension(extension, progressToastId); notification.update(progressToastId, { render: "Extensions successfully installed!", type: notification.SUCCESS, autoClose: 500 }); } else { notification.error("Instrument extension not found!"); } } //////////////////////////////////////////////////////////////////////////////// const Properties = observer( class Properties extends React.Component< { instrument: InstrumentObject; }, {} > { render() { const extension = this.props.instrument.extension; if (!extension) { return null; } return ( this.props.instrument.setLabel(value) } /> this.props.instrument.setAutoConnect(value) } /> ); } } ); //////////////////////////////////////////////////////////////////////////////// const Connection = observer( class Connection extends React.Component<{ instrument: InstrumentObject; }> { connectionParameters: ConnectionParameters | null; dismissError = () => { this.props.instrument.connection.dismissError(); }; render() { let { instrument } = this.props; let connection = this.props.instrument.connection; let info; let error; let connectionParameters; let button; if (connection) { if (connection.isIdle) { error = connection.error && ( {connection.error} ); connectionParameters = ( { this.connectionParameters = connectionParameters; }} availableConnections={ this.props.instrument.availableConnections } serialBaudRates={ this.props.instrument.serialBaudRates } /> ); button = ( ); } else { if (connection.isTransitionState) { info = ; } connectionParameters = ( ); if (connection.isConnected) { button = ( ); } else { button = ( ); } } } return (
{info} {error} {connectionParameters}
{button}
); } } );