コード例 #1
0
ファイル: MainViewModel.cs プロジェクト: lynch829/Autodrive
        private void SetCommands()
        {
            RelaySpreadsheetControlCommand = new DelegateCommand <SfSpreadsheet>((sp) =>
            {
                this.spreadsheet = sp;
            });

            RefreshCommCommand = new DelegateCommand(() =>
            {
                SetDefaultComPorts();
            });

            StopCommand = new DelegateCommand(() =>
            {
                ServiceModeSession.Instance.Keyboard.IsEnabled = false; // Turn off keyboard immediately
                IsStopRequested = true;
                cTokenSource.Cancel();
                this.logger.Log($"Stopping measurement...");
            });

            ToggleDefaultInterlocksCommand = new DelegateCommand(() =>
            {
                if (linac != null)
                {
                    linac.OverrideDefaultInterlocks();
                }
                else
                {
                    MessageBox.Show("Connect to linac Autodrive first!");
                }
            });

            ConnectADCommand = new DelegateCommand(() =>
            {
                this.linac        = new CSeriesLinac();
                this.linac.Logger = logger;
                try
                {
                    linac.Initialize(ADComPort); ADConnected = "(Connected)";
                }
                catch (Exception e)
                {
                    ADConnected = "(Error)";
                }
            });

            ConnectELCommand = new DelegateCommand(() =>
            {
                this.el   = new Max4000();
                el.Logger = logger;
                try
                {
                    el.Initialize(ELComPort);
                    if (!el.Verify())
                    {
                        MessageBox.Show("Couldn't find Max 4000!");
                    }
                    else
                    {
                        ELConnected = "(Connected)";
                    }
                }
                catch (Exception e) { ELConnected = "(Error)"; }
            });

            Connect1DCommand = new DelegateCommand(() =>
            {
                this.scan1D   = new DoseView1D();
                scan1D.Logger = logger;
                try
                {
                    scan1D.Initialize(DVComPort);
                    var version = scan1D.GetVersion();
                    if (string.IsNullOrEmpty(version))
                    {
                        MessageBox.Show("Couldn't find DoseView 1D!");
                    }
                    else
                    {
                        DVConnected = "(Connected)";
                        logger.Log($"Found DoseView 1D version {version}");
                        ChamberDepth = scan1D.GetCurrentDepthMM();
                    }
                }
                catch (Exception e) { DVConnected = "(Error)"; }
            });

            MoveChamberCommand = new DelegateCommand(async() =>
            {
                if (!double.IsNaN(ChamberDepth))
                {
                    await MoveChamber(ChamberDepth);
                }
            });
        }