Example #1
0
        /// <summary>
        /// Takes measurements using the electrometer and linac input
        /// </summary>
        /// <param name="el"></param>
        /// <param name="linac"></param>
        /// <param name="repeatBeam">flags whether or not this is a repeat measurement</param>
        /// <returns></returns>
        public double TakeMeasurement(IElectrometer el, CSeriesLinac linac, bool repeatBeam)
        {
            if (el != null)
            {
                el.StartMeasurement();
            }
            if (linac != null)
            {
                var ms = MachineStateRun;
                if (repeatBeam)
                {
                    linac.RepeatBeam();
                }
                else
                {
                    linac.BeamOn();
                }
                Thread.Sleep(linac.WaitMsForMU(ms.MU, ms.Accessory != null && AccessoryHelper.IsEDW(ms.Accessory)));
                Thread.Sleep(1000); //Extra second to allow electrometer settling
            }

            if (el != null)
            {
                el.StopMeasurement();
            }

            double val = double.NaN;

            if (el != null)
            {
                val = el.GetValue().Measurement;
                el.Reset();
            }
            AddMeasurement(val);
            return(val);
        }
Example #2
0
        public void Run(bool photons = true, bool electrons = true)
        {
            if (string.IsNullOrEmpty(SavePath))
            {
                Logger.Log("Save path is empty. Will save to desktop\n");
                SavePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "outputFactors.txt");
            }
            ;

            var measurementList = BuildMeasurementList(photons, electrons);

            foreach (var m in measurementList)
            {
                var jr = new Job(m);
                jr.DepthOfMeasurentMM = energyDepths[m.Energy];
                _scan1D.GoToDepth(jr.DepthOfMeasurentMM);

                for (int n = 0; n < RepeatMeasurements; n++)
                {
                    var fov = EnergyHelper.IsPhoton(m.Energy) ? $"{m.X1 * 2} x {m.Y1 * 2}" : m.Accessory;
                    Logger.Log($"Working on {m.Energy}, Depth {jr.DepthOfMeasurentMM}, {fov} ,  Measurement {n + 1}");

                    var state = _linac.GetMachineStateCopy();
                    //Check for cone change
                    if (_linac.GetMachineStateCopy().Accessory != m.Accessory)
                    {
                        Console.Beep(4000, 1000);
                        Logger.Log($"Please change the cone to {m.Accessory}\n");
                        Logger.Log($"Press ENTER when complete\n");
                        while (Console.ReadKey().Key != ConsoleKey.Enter)
                        {
                        }
                        Logger.Log($"{m.Accessory} inserted! Continuing...\n");
                    }

                    _linac.SetMachineState(m);

                    //Start measuring
                    _el.Reset();
                    _el.StartMeasurement();

                    if (n == 0)
                    {
                        _linac.BeamOn();
                    }
                    else
                    {
                        _linac.RepeatBeam();
                    }

                    Thread.Sleep(_linac.WaitMsForMU(m.MU));

                    //Stop and get measurement
                    _el.StopMeasurement();
                    var measured = _el.GetValue().Measurement;
                    Logger?.Log($"Measured : {measured}\n");

                    jr.AddMeasurement(_el.GetValue().Measurement);
                }

                //Save results
                JobWriter.AppendResult(SavePath, jr);
            }
        }
Example #3
0
        public void Run()
        {
            if (string.IsNullOrEmpty(SavePath))
            {
                Logger.Log("Save path is empty. Will save to desktop\n");
                SavePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "outputs.txt");
            }
            ;

            var measurementList = BuildMeasurementList();

            BeamManager.SetFixed();
            BeamManager.SetEnergy(Energy._6X);
            BeamManager.SetDoseRate(measurementList.First().MachineStateRun.DoseRate);

            foreach (var jr in measurementList)
            {
                Task depthTask = Task.Run(() => { });
                if (_scan1D.GetCurrentDepthMM() != jr.DepthOfMeasurentMM)
                {
                    depthTask = _scan1D.GoToDepth(jr.DepthOfMeasurentMM);
                }

                for (int n = 0; n < RepeatMeasurements; n++)
                {
                    Logger.Log($"Working on {jr.MachineStateRun.Energy}, Depth {jr.DepthOfMeasurentMM},  Measurement {n + 1}\n");

                    var state = _linac.GetMachineStateCopy();
                    //Check for cone change
                    if (_linac.GetMachineStateCopy().Accessory != jr.MachineStateRun.Accessory)
                    {
                        Console.Beep(4000, 1000);
                        Logger.Log($"Please change the cone to {jr.MachineStateRun.Accessory}\n");
                        Logger.Log($"Press ENTER when complete\n");
                        while (Console.ReadKey().Key != ConsoleKey.Enter)
                        {
                        }
                        Logger.Log($"{jr.MachineStateRun.Accessory} inserted! Continuing...\n");
                    }

                    _linac.SetMachineState(jr.MachineStateRun);

                    //Start measuring
                    depthTask.Wait();
                    _el.Reset();
                    _el.StartMeasurement();

                    if (n == 0)
                    {
                        _linac.BeamOn();
                    }
                    else
                    {
                        _linac.RepeatBeam();
                    }

                    Thread.Sleep(_linac.WaitMsForMU(jr.MachineStateRun.MU));

                    //Stop and get measurement
                    _el.StopMeasurement();
                    var measured = _el.GetValue().Measurement;
                    Logger?.Log($"Measured : {measured}\n");

                    jr.AddMeasurement(_el.GetValue().Measurement);
                }

                //Save results
                JobWriter.AppendResult(SavePath, jr);
            }
        }