예제 #1
0
        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);
                }
            });
        }
예제 #2
0
        public static void Run()
        {
            ui = new ConsoleUI();
            //Header
            ui.WriteSectionHeader("AUTODRIVE EXCEL RUNNER");
            ui.WriteSectionHeader("By Rex Cardan | UAB ");
            ui.SkipLines(2);

            //Connect to RS232
            var ports  = SerialPort.GetPortNames();
            var adPort = ui.GetStringResponse("Which port is the Autodrive on?", ports);

            ports = ports.Where(p => p != adPort).ToArray();

            var _1dport = ui.GetStringResponse("Which port is the 1D scanner on?", ports);

            ports = ports.Where(p => p != _1dport).ToArray();

            var elPort = ui.GetStringResponse("Which port is the electrometer on?", ports);

            ui.Write("Connecting to Autodrive...");
            _linac = new CSeriesLinac();
            _linac.Initialize(adPort);
            ui.Write("Connecting to DsoeView1D...");
            _1ds = new DoseView1D();
            _1ds.Initialize(_1dport);
            ui.Write($"Connected to DoseView {_1ds.GetVersion()}");

            ui.Write("Connecting to Max4000...");
            _el = new Max4000();
            _el.Initialize(elPort);
            if (_el.Verify())
            {
                ui.Write($"Connected to Max4000");
            }
            else
            {
                ui.WriteError($"Could not connect to Max4000! Check connections");
            }

            //Find Excel Sheet to key tasks from
            string excel = null;

            while (excel == null)
            {
                ui.WritePrompt("Please select the Excel file where the tasks are located.");
                var startingLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "toDoList.xlsx");
                excel = ui.GetOpenFilePath(startingLocation);
                if (excel == null)
                {
                    ui.WriteError("You must select a file!");
                }
            }

            //Read Excel
            var jobs = XCelJobList.Read(excel);
            var toDo = jobs.RowJobs.Where(j => !j.Item1.IsComplete());

            ui.Write($"Found {toDo}/{jobs.RowJobs.Count} jobs left to complete");

            var logger = new Logger();

            logger.Logged += Logger_Logged;
            jobs.Run(_linac, _el, _1ds, logger);
        }