Exemplo n.º 1
0
        protected override IEnumerator ProcessPayload(VisualPayload payload)
        {
            payload.VisualData.Bound.name = "Line Graph Bound";

            var lineGraph = VisualizerFactory.InstantiateLineGraph();

            lineGraph.Initialize(this, payload);

            AssignStates(lineGraph);

            var entries = EntryField.GetLastKeyValue(payload.Data) as IEnumerable <MutableObject>;

            if (entries == null)
            {
                throw new Exception("Illegal mutable field here!  " + EntryField.AbsoluteKey + " is not an enumerable of mutables!");
            }

            if (!entries.Any())
            {
                yield return(null);

                yield break;
            }

            foreach (var entry in entries)
            {
                Vector3 entryPosition =
                    new Vector3(
                        XAxis.GetLastKeyValue(entry),
                        YAxis.GetLastKeyValue(entry),
                        ZAxis.GetLastKeyValue(entry)
                        );

                Color pointColor = PointColor.GetLastKeyValue(entry);

                lineGraph.AddPoint(entryPosition, pointColor);

                yield return(null);
            }

            yield return(null);

            lineGraph.SetLineData(MainColor.GetLastKeyValue(payload.Data),
                                  LineWidth.GetLastKeyValue(payload.Data),
                                  ZDepthOffset.GetLastKeyValue(payload.Data),
                                  EdgeColor.GetLastKeyValue(payload.Data),
                                  EdgeWidth.GetLastKeyValue(payload.Data),
                                  PointWidth.GetLastKeyValue(payload.Data),
                                  PulseLine.GetLastKeyValue(payload.Data),
                                  PulseWidth.GetLastKeyValue(payload.Data),
                                  Wipe.GetLastKeyValue(payload.Data),
                                  StartTime.GetLastKeyValue(payload.Data),
                                  WipeDuration.GetLastKeyValue(payload.Data)
                                  );

            lineGraph.ApplyPoints();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="v1">The initial value</param>
 /// <param name="v2">The peak value</param>
 /// <param name="td">The initial delay time in seconds</param>
 /// <param name="tr">The rise time in seconds</param>
 /// <param name="tf">The fall time in seconds</param>
 /// <param name="pw">The pulse width in seconds</param>
 /// <param name="per">The period in seconds</param>
 public Pulse(double v1, double v2, double td, double tr, double tf, double pw, double per) : base("PULSE")
 {
     V1.Set(v1);
     V2.Set(v2);
     Delay.Set(td);
     RiseTime.Set(tr);
     FallTime.Set(tf);
     PulseWidth.Set(pw);
     Period.Set(per);
 }
Exemplo n.º 3
0
 /// <summary>
 ///     <inheritdoc />
 /// </summary>
 public void SetPulseWidth(double width, PulseWidth pulseWidth)
 {
     try
     {
         E8257D.SetPulseWidth(width, pulseWidth);
     }
     catch (Exception exception)
     {
         throw new SignalGeneratorException(exception.Message);
     }
 }
 /// <summary>
 ///     <inheritdoc />
 /// </summary>
 public void SetPulseWidth(double width, PulseWidth pulseWidth)
 {
     try
     {
         ScpiDataExchanger.Request(":PULM:WIDT " + width + " " + pulseWidth + ";");
     }
     catch (Exception exception)
     {
         throw new SignalGeneratorException(exception.Message);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 ///     <inheritdoc />
 /// </summary>
 public void SetPulseModulationInternalPulseWidth(double width, PulseWidth type)
 {
     try
     {
         E8257D.SetPulseModulationInternalPulseWidth(width, type);
     }
     catch (Exception exception)
     {
         throw new SignalGeneratorException(exception.Message);
     }
 }
 /// <summary>
 ///     <inheritdoc />
 /// </summary>
 public void SetPulseModulationInternalPulseWidth(double width, PulseWidth type)
 {
     try
     {
         ScpiDataExchanger.Request(":PULM:INT:PWID " + Convert.ToString(width, CultureInfo.InvariantCulture) +
                                   " " + type + ";");
     }
     catch (Exception exception)
     {
         throw new SignalGeneratorException(exception.Message);
     }
 }
 /// <summary>
 ///     Sets the pulse duration according to the specified parameters
 /// </summary>
 /// <param name="width">Pulse Duration</param>
 /// <param name="timeType">Dimension type</param>
 public void SetPulseWidth(double width, PulseWidth timeType)
 {
     try
     {
         _deviceExchanger.SendDataWithOutReturn(":PULM:WIDT " + width + " " + timeType + ";");
     }
     catch (Smb100AException smb100AException)
     {
         throw new Smb100AException("Failed to set signal pulse width to " + width +
                                    " " +
                                    timeType + ": " + smb100AException.Message);
     }
 }
Exemplo n.º 8
0
 public bool SetCurrentPulseWidth(PulseWidth pulseWidth, bool confirm)
 {
     if (/*terminated?*/ _cancelEvent.WaitOne(0))
     {
         return(false);
     }
     CommandDefinition.CommandFormat command  = ConstructCommand(CommandEnum.PulseWidth, BooleanValue.True, ActionEnum.Set, (byte)pulseWidth);
     CommandDefinition.CommandFormat?response = SendCommand(command, confirm);
     if (confirm && !ConfirmSetActionResponse(response, CommandEnum.PulseWidth, (byte)pulseWidth))
     {
         return(false);
     }
     CurrentPulseWidth = pulseWidth;
     return(true);
 }
Exemplo n.º 9
0
 public bool GetCurrentPulseWidth(out PulseWidth?width, bool confirm)
 {
     width = null;
     if (/*terminated?*/ _cancelEvent.WaitOne(0))
     {
         return(false);
     }
     CommandDefinition.CommandFormat command  = ConstructCommand(CommandEnum.PulseWidth, BooleanValue.False, ActionEnum.Get, 0);
     CommandDefinition.CommandFormat?response = SendCommand(command, confirm);
     if (response != null && response.Value.CommandAck.Command == CommandEnum.PulseWidth && response.Value.Action.Action == ActionEnum.Response)
     {
         CurrentPulseWidth = (PulseWidth)PulseWidth.ToObject(typeof(PulseWidth), response.Value.Action.SubAction);
         width             = CurrentPulseWidth;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 10
0
 public void SendPulseWidthConfigResponse(PulseWidth width, float time)
 {
     byte[] data = BitConverter.GetBytes(time);
     CommandDefinition.CommandFormat packet = ReplyCreate(CommandEnum.ConfigPulseWidth, BooleanValue.True, ActionEnum.Response, (byte)width, data);
     ReplySend(packet);
 }
Exemplo n.º 11
0
 public void SendPulseWidthResponse(PulseWidth width)
 {
     CommandDefinition.CommandFormat packet = ReplyCreate(CommandEnum.PulseWidth, BooleanValue.True, ActionEnum.Response, (byte)width);
     ReplySend(packet);
 }
Exemplo n.º 12
0
 /// <summary/>
 public bool SetCurrentPulseWidth(PulseWidth width, bool confirm)
 {
     bool status = false;
     try
     {
         CommandDefinition.CommandFormat command = CommandMake(CommandEnum.PulseWidth, BooleanValue.True, ActionEnum.Set, (byte)width);
         CommandDefinition.CommandFormat? reply = CommandSend(command, /*reply expected*/ true);
         if (/*ignore results?*/ !confirm)
             status = true;
         else
         {
             string text = CommandReplyValidate(reply, CommandEnum.PulseWidth, (byte)width);
             if (/*fail?*/ text != string.Empty)
                 throw new Exception(text);
             status = true;
         }
         CurrentPulseWidth = width;
     }
     catch (Exception ex)
     {
         Debug.Assert(!status);
         status = false;
         throw ex;
     }
     try { Logger.LogInfo(MethodBase.GetCurrentMethod() + "(" + width.ToString() + ", " + confirm.ToString() + ") returns " + status.ToString()); }
     catch { }
     return status;
 }
        public Measurement(PointCollection GraphSegment, double TimeRes, double ScaleFactor, int HighLevel)
        {
            Result = new StackPanel();

            if (GraphSegment.Count != 0)
            {
                InputData = new PointCollection();
                for (int PointIndex = 0; PointIndex < GraphSegment.Count; PointIndex++)
                {
                    Point NewPoint = new Point(GraphSegment[PointIndex].X / ScaleFactor, GraphSegment[PointIndex].Y);
                    InputData.Add(NewPoint);
                }

                TimeResolution = TimeRes;
                PulseHighLevel = HighLevel;

                Result.Background      = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFADFF2F"));
                Result.Name            = "MeasureGrid";
                Result.Opacity         = 0.65;// 0.75;
                Result.Orientation     = Orientation.Vertical;
                Result.RenderTransform = new ScaleTransform(1, -1);
                double Duration = GetDuration(InputData[0].X, InputData[InputData.Count - 1].X);
                AddData("Ширина: " + Duration.ToString("0.000") + " мкс");

                int EdgeCount;
                int RisingEdgeCount;
                int FallingEdgeCount;
                int PulseCntResult = PulseCounter(out EdgeCount, out RisingEdgeCount, out FallingEdgeCount);

                if (PulseCntResult == ONE_PULSE)
                {
                    double DutyCycle;
                    double Frequency;
                    double Period;
                    double PulseWidth;

                    Period    = Duration;
                    Frequency = 1000 / Period;             //кГц
                    GetPulseWidth(out PulseWidth);
                    DutyCycle = 100 * PulseWidth / Period; //%

                    AddData("Период: " + Period.ToString("0.000") + " мкс");
                    AddData("Частота: " + Frequency.ToString("0.000") + " кГц");
                    AddData("Длительность импульса: " + DutyCycle.ToString("0.000") + " % / " + PulseWidth.ToString("0.000") + " мкс");
                }

                else if (PulseCntResult == MANY_PULSES)
                {
                    AddData("Количество фронтов: " + EdgeCount.ToString());
                    AddData("Передних фронтов: " + RisingEdgeCount.ToString());
                    AddData("Задних фронтов: " + FallingEdgeCount.ToString());
                }
            }
        }
Exemplo n.º 14
0
 public void SendPulseWidthConfigResponse(PulseWidth width, float time)
 {
     byte[] data = BitConverter.GetBytes(time);
     CommandDefinition.CommandFormat packet = ReplyCreate(CommandEnum.ConfigPulseWidth, BooleanValue.True, ActionEnum.Response, (byte)width, data);
     ReplySend(packet);
 }
Exemplo n.º 15
0
 /// <summary/>
 public bool GetConfigPulseWidth(PulseWidth? width, out float? time, bool confirm)
 {
     bool status = false;
     try
     {
         CommandDefinition.CommandFormat command = CommandMake(CommandEnum.ConfigPulseWidth, BooleanValue.True, ActionEnum.Get, (byte)width);
         CommandDefinition.CommandFormat? reply = CommandSend(command, /*reply expected*/ true);
         string text = CommandReplyValidate(reply, CommandEnum.ConfigPulseWidth);
         if (/*fail?*/ !string.IsNullOrWhiteSpace(text))
             throw new Exception(text);
         time = BitConverter.ToSingle(reply.Value.Payload, 0);
         status = true;
     }
     catch (Exception ex)
     {
         time = null;
         width = null;
         status = false;
         if (/*OK to log?*/ LogPauseExpired)
             try { Logger.LogError(Utilities.TextTidy(ex.ToString())); }
             catch { }
     }
     return status;
 }
Exemplo n.º 16
0
        private void ReadStoredEnergyData(PxeWriteAccess pxeWriteAccess, LINAC_ENERGY_TYPE_VALUE energy, PulseWidth pulseWidth)
        {
            long bufferSize = _dataAccess.Detectors.PixelsPerColumn;
            CalibrationDataCollection collection = GetCalibrationCollection(energy, pulseWidth);
            if (energy == LINAC_ENERGY_TYPE_VALUE.High)
            {
                float[] airHighDataBuffer = new float[bufferSize];
                float[] darkHighDataBuffer = new float[bufferSize];
                float[] normScaleHighDataBuffer = new float[bufferSize];
                if (pxeWriteAccess.ReadHighEngDarkSample(darkHighDataBuffer))
                {
                    collection.AddDarkData(XRayEnergyEnum.HighEnergy, PixelConverter.Convert(darkHighDataBuffer));
                }

                if (pxeWriteAccess.ReadHighEngAirSample(airHighDataBuffer))
                {
                    collection.AddAirData(XRayEnergyEnum.HighEnergy, PixelConverter.Convert(airHighDataBuffer));
                }
            }
            if (energy == LINAC_ENERGY_TYPE_VALUE.Low)
            {
                float[] airLowDataBuffer = new float[bufferSize];
                float[] normScaleLowDataBuffer = new float[bufferSize];
                float[] darkLowDataBuffer = new float[bufferSize];
                if (pxeWriteAccess.ReadLowEngDarkSample(darkLowDataBuffer))
                {
                    collection.AddDarkData(XRayEnergyEnum.LowEnergy, PixelConverter.Convert(darkLowDataBuffer));
                }

                if (pxeWriteAccess.ReadLowEngAirSample(airLowDataBuffer))
                {
                    collection.AddAirData(XRayEnergyEnum.LowEnergy, PixelConverter.Convert(airLowDataBuffer));
                }
            }
            if (energy == LINAC_ENERGY_TYPE_VALUE.Dual)
            {
                float[] airHighDataBuffer = new float[bufferSize];
                float[] darkHighDataBuffer = new float[bufferSize];
                float[] normScaleHighDataBuffer = new float[bufferSize];
                float[] airLowDataBuffer = new float[bufferSize];
                float[] normScaleLowDataBuffer = new float[bufferSize];
                float[] darkLowDataBuffer = new float[bufferSize];
                if (pxeWriteAccess.ReadHighEngDarkSample(darkHighDataBuffer))
                {
                    collection.AddDarkData(XRayEnergyEnum.HighEnergy, PixelConverter.Convert(darkHighDataBuffer));
                }

                if (pxeWriteAccess.ReadHighEngAirSample(airHighDataBuffer))
                {
                    collection.AddAirData(XRayEnergyEnum.HighEnergy, PixelConverter.Convert(airHighDataBuffer));
                }

                if (pxeWriteAccess.ReadLowEngDarkSample(darkLowDataBuffer))
                {
                    collection.AddDarkData(XRayEnergyEnum.LowEnergy, PixelConverter.Convert(darkLowDataBuffer));
                }

                if (pxeWriteAccess.ReadLowEngAirSample(airLowDataBuffer))
                {
                    collection.AddAirData(XRayEnergyEnum.LowEnergy, PixelConverter.Convert(airLowDataBuffer));
                }
            }
        }
Exemplo n.º 17
0
 /// <summary>
 /// Pulse Period gets, by <see cref="PulseWidth"/> enumeration, a pulse width
 /// value.</summary>
 /// <param name="width">
 /// Pulse Width specifies, by <see cref="PulseWidth"/> enumerated value, the pulse width to
 /// be obtained...</param>
 /// <returns>pulse width in microseconds</returns>
 public double PulsePeriod(PulseWidth width)
 {
     int index = 0;
     if (/*prepare?*/ _pulsePeriod == null)
     {
         _pulsePeriod = new double[Enum.GetNames(typeof(PulseWidth)).Length];
         _pulsePeriodDomain = "{";
         Debug.Assert(index == 0);
         foreach (PulseWidth widthType in Enum.GetValues(typeof(PulseWidth)))
         {
             string keyText = "PulseWidth" + ((int)widthType).ToString() + "Microseconds";
             _pulsePeriod[index] = Utilities.PropertyConfigureReal(keyText, 1.0, double.MaxValue, -double.MaxValue, "μs");
             if (/*finish previous entry?*/ index >= 1)
                 _pulsePeriodDomain += "μs, ";
             _pulsePeriodDomain += widthType.ToString() + " = " + _pulsePeriod[index].ToString();
             index++; /*for next cycle*/
         }
         _pulsePeriodDomain += "μs}";
         try { Logger.LogInfo("pulse widths set to " + _pulsePeriodDomain); } catch { }
     }
     index = 0;
     foreach (PulseWidth widthType in Enum.GetValues(typeof(PulseWidth)))
         if (/*not this one?*/ width != widthType)
             index++;
         else /*found: done*/
             return _pulsePeriod[index];
     throw new IndexOutOfRangeException(MethodBase.GetCurrentMethod().Name + ": width (" + width.ToString() + ") must be from " + _pulsePeriodDomain);
 }
Exemplo n.º 18
0
 /// <summary/>
 public bool SetConfigPulseWidth(PulseWidth width, float time, bool confirm)
 {
     bool status = false;
     try
     {
         PulseWidthConfigure(width, time);
         status = true;
     }
     catch { Debug.Assert(!status); }
     return status;
 }
Exemplo n.º 19
0
        private CalibrationDataCollection GetCalibrationCollection(LINAC_ENERGY_TYPE_VALUE energyConfig, PulseWidth pulseWidth)
        {
            switch (energyConfig)
            {
                case LINAC_ENERGY_TYPE_VALUE.Dual:
                    return _DualDataCollection[PulseWidth.PulseWidth1];
                case LINAC_ENERGY_TYPE_VALUE.High:
                    return _HighDataCollection[PulseWidth.PulseWidth2];
                case LINAC_ENERGY_TYPE_VALUE.Low:
                    return _LowDataCollection[PulseWidth.PulseWidth3];
#if LinacLowDose
                case LINAC_ENERGY_TYPE_VALUE.LowDose:
                    return _LowDoseDataCollection[PulseWidth.PulseWidth3];
#endif
                default:
                    return _DualDataCollection[PulseWidth.PulseWidth1];
            }
            //return (energyConfig == LINAC_ENERGY_TYPE_VALUE.Dual) ? _DualDataCollection[PulseWidth.PulseWidth1] :
            //       (energyConfig == LINAC_ENERGY_TYPE_VALUE.High) ? _HighDataCollection[PulseWidth.PulseWidth2] : _LowDataCollection[PulseWidth.PulseWidth3];
        }
Exemplo n.º 20
0
 /// <summary/>
 public bool SetConfigPulseWidth(PulseWidth? width, float time, bool confirm)
 {
     bool status = false;
     try
     {
         PulseWidthConfigure(width, time);
         status = true;
     }
     catch { Debug.Assert(!status); }
     try { Logger.LogInfo(MethodBase.GetCurrentMethod() + "(" + ((width == null) ? "null" : width.ToString()) + ", " + confirm.ToString() + ") returns " + status.ToString()); }
     catch { }
     return status;
 }
Exemplo n.º 21
0
 /// <summary>
 /// Pulse Period gets, by <see cref="PulseWidth"/> enumeration, a pulse width
 /// value.</summary>
 /// <param name="width">
 /// Pulse Width specifies, by <see cref="PulseWidth"/> enumerated value, the pulse width to
 /// be obtained...</param>
 /// <returns>pulse width in microseconds</returns>
 public double PulsePeriod(PulseWidth pulseWidth)
 {
     int pulseWidthIndex = 0;
     string traceText = string.Empty;
     if (/*prepare?*/ _pulsePeriod == null)
     {
         _pulsePeriod = new double[Enum.GetNames(typeof(PulseWidth)).Length];
         traceText = "pulse widths = {";
         foreach (PulseWidth pulseWidthType in Enum.GetValues(typeof(PulseWidth)))
         {
             string keyText = "PulseWidth" + ((int)pulseWidthType).ToString() + "Microseconds";
             _pulsePeriod[pulseWidthIndex] = Utilities.PropertyConfigureReal(keyText, 1.0, double.MaxValue, -double.MaxValue, "μs");
             if (/*prefix comma?*/ pulseWidthIndex >= 1)
                 traceText += "μs, ";
             traceText += _pulsePeriod[pulseWidthIndex].ToString();
             pulseWidthIndex++; /*for next cycle*/
         }
         traceText += "μs}";
         try { Logger.LogInfo(traceText); }
         catch { }
     }
     pulseWidthIndex = 0;
     foreach (PulseWidth pulseWidthValue in Enum.GetValues(typeof(PulseWidth)))
         if (pulseWidth != pulseWidthValue)
             pulseWidthIndex++;
         else
             return _pulsePeriod[pulseWidthIndex];
     traceText = "{";
     foreach (PulseWidth pulseWidthType in Enum.GetValues(typeof(PulseWidth)))
     {
         if (/*prefix comma?*/ pulseWidthIndex >= 1)
             traceText += ", ";
         traceText += pulseWidthType.ToString();
     }
     traceText += "}";
     throw new IndexOutOfRangeException(MethodBase.GetCurrentMethod().Name + ": width (" + pulseWidth.ToString() + ") must be in " + traceText);
 }
Exemplo n.º 22
0
 private void SetApcsPulseWidth(PulseWidth width)
 {
     Thread.Sleep(1000);
     try
     {
         _dataAccess.Apcs.SetCurrentPulseWidth(width, false);
     }
     catch (Exception ex)
     {
         FailedCalibration("APCS Pulse Width unable to be set.\n" + ex.ToString());
     }
 }
Exemplo n.º 23
0
        private void SetNextConfiguration()
        {
            if (_dataAccess.OpcTags.LINAC_ENERGY_TYPE_STATE.Value == LINAC_ENERGY_TYPE_VALUE.Dual)
            {
                _setLinacEnergyType = LINAC_ENERGY_TYPE_VALUE.High;
                _setApcsEnergyMode = ScanEnergyMode.High;
                _setPulseWidth = PulseWidth.PulseWidth2;
            }
            else if (_dataAccess.OpcTags.LINAC_ENERGY_TYPE_STATE.Value == LINAC_ENERGY_TYPE_VALUE.High)
            {
                _setLinacEnergyType = LINAC_ENERGY_TYPE_VALUE.Low;
                _setApcsEnergyMode = ScanEnergyMode.Low;
                _setPulseWidth = PulseWidth.PulseWidth3;
            }
#if LinacLowDose
            else if (_dataAccess.OpcTags.LINAC_ENERGY_TYPE_STATE.Value == LINAC_ENERGY_TYPE_VALUE.Low)
            {
                _setLinacEnergyType = LINAC_ENERGY_TYPE_VALUE.LowDose;
                _setApcsEnergyMode = ScanEnergyMode.LowDose;
                _setPulseWidth = PulseWidth.PulseWidth3;
            }
#endif
            else
            {
                SaveDataToPXE();
                _dataAccess.SetCalibrationState(CALIBRATION_STATE_VALUE.Completed);
                _calibrationLoaded = true;
                _logger.LogInfo("****   Stopping Calibration");
                StopCalibration();
            }
        }
Exemplo n.º 24
0
        private void SetupAgent()
        {
            _setApcsEnergyMode = ScanEnergyMode.Dual;
            _setLinacEnergyType = LINAC_ENERGY_TYPE_VALUE.Dual;
            _setPulseWidth = PulseWidth.PulseWidth1;

            _logger.LogInfo("Getting APCS status");

            //GetApcsStatus();

            _startingApcsEnergyMode = _currentApcsEnergyMode;
            _startingLinacEnergyType = _dataAccess.OpcTags.LINAC_ENERGY_TYPE_STATE.Value;
            _startingPulseWidth = _currentPulseWidth;

            _rawDataColl = new BlockingCollection<DataInfo>();

            if (_dataAccess.OpcTags.LINAC_STATE.Value == LINAC_STATE_VALUE.XRaysOn)
            {
                _logger.LogInfo("Setting x-rays off");
                SetXrayOn(false);
            }
            else
            {
                _logger.LogInfo("Start Collecting Data");

                //if(AppConfiguration.CalibrationMode != AppConfiguration.CalibrationModeEnum.Persistent)
                    StartDataCollection(false);
            }
        }
Exemplo n.º 25
0
 private void Apcs_ApcsUpdate(CommandEnum command, ActionEnum action, byte subAction, object data)
 {
     if (command == CommandEnum.PulseWidth && action == ActionEnum.Response)
         _currentPulseWidth = (PulseWidth)PulseWidth.ToObject(typeof(PulseWidth), subAction);
     else if (command == CommandEnum.ScanMode && action == ActionEnum.Response)
         _currentApcsEnergyMode = (ScanEnergyMode)ScanEnergyMode.ToObject(typeof(ScanEnergyMode), subAction);
 }
Exemplo n.º 26
0
        private void GetApcsStatus()
        {
            while (!_dataAccess.Apcs.Connected)
            {
                Thread.Sleep(1000);
            }

            while (_dataAccess.Apcs.Connected)
            {
                try
                {
                    bool success = false;

                    ScanEnergyMode? energyMode = null; 
                    PulseWidth? pulseWidth = null;

                    Thread.Sleep(500);
                    success = _dataAccess.Apcs.GetScanEnergyMode(out energyMode, false);
                    Thread.Sleep(500);
                    success = _dataAccess.Apcs.GetCurrentPulseWidth(out pulseWidth, false);

                    _currentApcsEnergyMode = (ScanEnergyMode) energyMode;
                    _currentPulseWidth =  (PulseWidth) pulseWidth;

                    //_currentApcsEnergyMode = _dataAccess.Apcs.GetScanEnergyMode();
                    //_currentPulseWidth = _dataAccess.Apcs.GetCurrentPulseWidth();
                    break;
                }
                catch { }
            }
        }
Exemplo n.º 27
0
 private void PulseWidthConfigure(PulseWidth? width, float time, bool relaxed = false)
 {
     try
     {
         CommandDefinition.CommandFormat command = CommandMake(CommandEnum.ConfigPulseWidth, BooleanValue.True, ActionEnum.Set, (byte)width);
         BitConverter.GetBytes(time).CopyTo(command.Payload, 0);
         CommandDefinition.CommandFormat? reply = CommandSend(command, /*reply expected*/ true);
         string text = CommandReplyValidate(reply, CommandEnum.ConfigPulseWidth);
         if (/*fail?*/ text != string.Empty)
             throw new Exception(text);
         float /*value*/ vlu = BitConverter.ToSingle(reply.Value.Payload, 0);
         if (/*incorrect result*/ time != vlu)
             throw new Exception(time.ToString() + " != " + vlu.ToString());
     }
     catch { throw; }
 }
Exemplo n.º 28
0
        static void hostAccess_ProcessCommandEvent(CommandDefinition.CommandFormat command)
        {
            if (command.CommandAck.Command == CommandEnum.ScanMode)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    currentEnergyMode = (ScanEnergyMode)command.Action.SubAction;

                    PWMOutputConfig pwmConfig = (PWMOutputConfig)pc.GetPWMRunStatus();

                    if (pwmConfig == PWMOutputConfig.OutputEnabled)
                    {
                        pc.PWMOutputDisable();
                    }

                    if (currentEnergyMode == ScanEnergyMode.Dual)
                    {
                        Reset.Write(true);
                        Preset.Write(true);
                    }
                    else if (currentEnergyMode == ScanEnergyMode.High)
                    {
                        Reset.Write(true);
                        Preset.Write(false);
                    }
                    else
                    {
                        Reset.Write(false);
                        Preset.Write(true);
                    }

                    if (pwmConfig == PWMOutputConfig.OutputEnabled)
                    {
                        pc.PWMOutputEnable();
                    }
                }

                hostAccess.SendScanModeResponse(currentEnergyMode);
            }
            else if (command.CommandAck.Command == CommandEnum.StaticPulseFreq)
            {
                OperatingMode mode = (OperatingMode)command.Action.SubAction;
                int           freq = BitConverter.ToInt32(command.Payload, 0);;

                if (command.Action.Action == ActionEnum.Set)
                {
                    if (mode == OperatingMode.NonAdaptiveMobile)
                    {
                        StaticPulseFreq[0] = freq;
                    }
                    else if (mode == OperatingMode.NonAdpativePortal)
                    {
                        StaticPulseFreq[1] = freq;
                    }

                    if (currentOperatingMode == mode)
                    {
                        currentStaticPulseFreq = freq;
                        pc.UpdatePWMFrequency(freq);
                    }

                    hostAccess.SendStaticPulseFreqResponse(mode, freq);
                }
                else if (command.Action.Action == ActionEnum.Get)
                {
                    if (mode == OperatingMode.NonAdaptiveMobile)
                    {
                        freq = StaticPulseFreq[0];
                    }
                    else if (mode == OperatingMode.NonAdpativePortal)
                    {
                        freq = StaticPulseFreq[1];
                    }

                    hostAccess.SendStaticPulseFreqResponse(mode, freq);
                }
            }
            else if (command.CommandAck.Command == CommandEnum.PulseWidth)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    if (currentPulseWidth != (PulseWidth)command.Action.SubAction)
                    {
                        currentPulseWidth = (PulseWidth)command.Action.SubAction;
                        pc.UpdatePWMPulseWidth(PulseWidthsDutyCycle[(int)currentPulseWidth - 1]);
                    }
                }

                hostAccess.SendPulseWidthResponse(currentPulseWidth);
            }
            else if (command.CommandAck.Command == CommandEnum.ConfigPulseWidth)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    int index = command.Action.SubAction - 1;
                    PulseWidthsDutyCycle[index] = BitConverter.ToSingle(command.Payload, 0);

                    if (currentPulseWidth == (PulseWidth)command.Action.SubAction)
                    {
                        pc.UpdatePWMPulseWidth(PulseWidthsDutyCycle[index]);
                    }
                }

                PulseWidth width = (PulseWidth)command.Action.SubAction;
                hostAccess.SendPulseWidthConfigResponse(width, PulseWidthsDutyCycle[(byte)width - 1]);
            }
            else if (command.CommandAck.Command == CommandEnum.OperatingMode)
            {
                short minFreq, maxFreq;

                if (command.Action.Action == ActionEnum.Set)
                {
                    minFreq = (short)BitConverter.ToInt16(command.Payload, 0);
                    maxFreq = (short)BitConverter.ToInt16(command.Payload, 2);
                    currentOperatingMode = (OperatingMode)command.Action.SubAction;

                    if ((currentOperatingMode == OperatingMode.NonAdaptiveMobile) || (currentOperatingMode == OperatingMode.NonAdpativePortal))
                    {
                        if (currentOperatingMode == OperatingMode.NonAdaptiveMobile)
                        {
                            currentStaticPulseFreq = StaticPulseFreq[0];
                        }
                        else
                        {
                            currentStaticPulseFreq = StaticPulseFreq[1];
                        }

                        pc.SetOperatingMode(currentOperatingMode);
                        pc.UpdatePWMFrequency(currentStaticPulseFreq);
                        pc.UpdatePWMPulseWidth(PulseWidthsDutyCycle[(int)currentPulseWidth - 1]);
                        pc.PWMOutputEnable();
                    }
                    else if ((currentOperatingMode == OperatingMode.AdaptiveMobile) || (currentOperatingMode == OperatingMode.AdaptivePortal))
                    {
                        pc.SetFrequencyRange(currentOperatingMode, minFreq, maxFreq);
                        pc.SetOperatingMode(currentOperatingMode);
                        pc.PWMOutputEnable();
                    }

                    hostAccess.SendOperatingModeResponse(currentOperatingMode, minFreq, maxFreq);
                }
                else if (command.Action.Action == ActionEnum.Get)
                {
                    pc.GetFrequencyRange(currentOperatingMode, out minFreq, out maxFreq);
                    hostAccess.SendOperatingModeResponse(currentOperatingMode, minFreq, maxFreq);
                }
            }
            else if (command.CommandAck.Command == CommandEnum.AdaptiveModeToTrigRatio)
            {
                float         ratio;
                OperatingMode mode = (OperatingMode)command.Action.SubAction;

                if (command.Action.Action == ActionEnum.Set)
                {
                    ratio = BitConverter.ToSingle(command.Payload, 0);

                    pc.SetInputToOutputRatio(mode, ratio);

                    hostAccess.SendAdaptiveModeToTrigRatioResponse(mode, ratio);
                }
                else if (command.Action.Action == ActionEnum.Get)
                {
                    pc.GetInputToOutputRatio(mode, out ratio);
                    hostAccess.SendAdaptiveModeToTrigRatioResponse(mode, ratio);
                }
            }
            else if (command.CommandAck.Command == CommandEnum.AdaptiveSpeedFeedbackConfig)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    adaptiveSpeedMsgFreq = BitConverter.ToSingle(command.Payload, 0);
                    speedMsgMode         = (AdaptiveSpeedFeedbackConfig)command.Action.SubAction;

                    if ((speedMsgMode == AdaptiveSpeedFeedbackConfig.EnabledWithFreq) && (adaptiveSpeedMsgFreq > 0.0f))
                    {
                        int period = (int)(1000.0f / adaptiveSpeedMsgFreq);
                        adaptiveSpeedMsgTimer.Change(period, period);
                    }
                    else
                    {
                        adaptiveSpeedMsgTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    }
                }

                hostAccess.SendAdaptiveSpeedFeedbackConfigResponse(speedMsgMode, adaptiveSpeedMsgFreq);
            }
            else if (command.CommandAck.Command == CommandEnum.PWMOutput)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    if ((PWMOutputConfig)command.Action.SubAction == PWMOutputConfig.OutputEnabled)
                    {
                        pc.PWMOutputEnable();
                    }
                    else
                    {
                        pc.PWMOutputDisable();
                    }

                    hostAccess.SendPWMOutputStatus((PWMOutputConfig)command.Action.SubAction);
                }
                else if (command.Action.Action == ActionEnum.Get)
                {
                    hostAccess.SendPWMOutputStatus((PWMOutputConfig)pc.GetPWMRunStatus());
                }
            }
            else if (command.CommandAck.Command == CommandEnum.ResetBoard)
            {
                ResetBoard();
            }
        }
Exemplo n.º 29
0
        public string CreatePXEFile(LINAC_ENERGY_TYPE_VALUE energy, PulseWidth pulseWidth, List <DataInfo> ObjectLines)
        {
            lock (_writeLock)
            {
                string pxeFile = Path.Combine(AppConfiguration.HostTempFileLocation, DateTime.Now.ToString(_dateFormat) + _pxeExtension);
                _pxeWriteAccess.CreatePXE(pxeFile);

                try
                {
                    List <Pixel[]>   highEnergyLines = new List <Pixel[]>();
                    List <Pixel[]>   lowEnergyLines  = new List <Pixel[]>();
                    XRayInfoIDStruct highEnergyInfo  = default(XRayInfoIDStruct);
                    XRayInfoIDStruct lowEnergyInfo   = default(XRayInfoIDStruct);

                    if (energy == LINAC_ENERGY_TYPE_VALUE.Dual)
                    {
                        if (ObjectLines[0].XRayInfo.Energy == XRayEnergyEnum.HighEnergy)
                        {
                            ObjectLines.RemoveAt(0);
                        }
                    }

                    //store object line data
                    foreach (DataInfo dataLine in ObjectLines)
                    {
                        if (dataLine.XRayInfo.Energy == XRayEnergyEnum.HighEnergy)
                        {
                            highEnergyLines.Add(dataLine.LineData);
                            highEnergyInfo = dataLine.XRayInfo;
                        }
                        else //low energy
                        {
                            lowEnergyLines.Add(dataLine.LineData);
                            lowEnergyInfo = dataLine.XRayInfo;
                        }
                    }

                    int maxLength = Math.Min(lowEnergyLines.Count, highEnergyLines.Count);

                    if (maxLength == 0)
                    {
                        maxLength = Math.Max(lowEnergyLines.Count, highEnergyLines.Count);
                    }

                    if (maxLength > AppConfiguration.MaxPXEWidth)
                    {
                        maxLength = AppConfiguration.MaxPXEWidth;
                    }

                    if (energy != LINAC_ENERGY_TYPE_VALUE.Low && highEnergyLines.Count > 0)
                    {
                        int bufferSize = maxLength * highEnergyLines[0].Length;

                        if (bufferSize > 0)
                        {
                            float[] buffer = new float[bufferSize];
                            Parallel.For(highEnergyLines.Count - maxLength, maxLength, index =>
                            {
                                float[] pixelArray = PixelConverter.Convert(highEnergyLines[index]);
                                int length         = Buffer.ByteLength(pixelArray);
                                Buffer.BlockCopy(pixelArray, 0, buffer, index * length, length);
                            });


                            if (energy == LINAC_ENERGY_TYPE_VALUE.Dual)
                            {
                                _pxeWriteAccess.CreateHiPXEHeader((uint)maxLength, (uint)highEnergyLines[0].Length);
                                _pxeWriteAccess.WriteHiDataLines(buffer, (uint)maxLength);
                                _pxeWriteAccess.WriteHighEngDarkSample(PixelConverter.Convert(_calibration.GetDarkData(highEnergyInfo)));
                                _pxeWriteAccess.WriteHighEngAirSample(PixelConverter.Convert(_calibration.GetAirData(highEnergyInfo)));

                                if (AppConfiguration.StoreReferenceCorrection)
                                {
                                    _pxeWriteAccess.WriteHiRef(_calibration.GetReferenceCorrections(highEnergyInfo));
                                }

                                if (AppConfiguration.StoreScaleFactor)
                                {
                                    _pxeWriteAccess.WriteHiScaleFactor(_calibration.GetScaleFactor(highEnergyInfo));
                                }

                                if (AppConfiguration.StoreAirDarkSamples)
                                {
                                    _pxeWriteAccess.WriteHiFullAirData(PixelConverter.Convert(_calibration.GetAirDataCollection(highEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                    _pxeWriteAccess.WriteHiFullDarkData(PixelConverter.Convert(_calibration.GetDarkDataCollection(highEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                }
                            }
                            else
                            {
                                _pxeWriteAccess.CreateHiPXEHeader((uint)maxLength, (uint)highEnergyLines[0].Length);
                                _pxeWriteAccess.WriteHiDataLines(buffer, (uint)maxLength);
                                _pxeWriteAccess.WriteHighEngDarkSample(PixelConverter.Convert(_calibration.GetDarkData(highEnergyInfo)));
                                _pxeWriteAccess.WriteHighEngAirSample(PixelConverter.Convert(_calibration.GetAirData(highEnergyInfo)));

                                if (AppConfiguration.StoreReferenceCorrection)
                                {
                                    _pxeWriteAccess.WriteHiRef(_calibration.GetReferenceCorrections(highEnergyInfo));
                                }

                                if (AppConfiguration.StoreScaleFactor)
                                {
                                    _pxeWriteAccess.WriteHiScaleFactor(_calibration.GetScaleFactor(highEnergyInfo));
                                }

                                if (AppConfiguration.StoreAirDarkSamples)
                                {
                                    _pxeWriteAccess.WriteHiFullAirData(PixelConverter.Convert(_calibration.GetAirDataCollection(highEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                    _pxeWriteAccess.WriteHiFullDarkData(PixelConverter.Convert(_calibration.GetDarkDataCollection(highEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                }
                            }
                        }

                        highEnergyLines.Clear();
                    }

                    if (energy != LINAC_ENERGY_TYPE_VALUE.High && lowEnergyLines.Count > 0)
                    {
                        int bufferSize = maxLength * lowEnergyLines[0].Length;

                        if (bufferSize > 0)
                        {
                            float[] buffer = new float[bufferSize];
                            Parallel.For(0, maxLength, index =>
                            {
                                float[] pixelArray = PixelConverter.Convert(lowEnergyLines[index]);
                                int length         = Buffer.ByteLength(pixelArray);
                                Buffer.BlockCopy(pixelArray, 0, buffer, index * length, length);
                            });

                            if (energy == LINAC_ENERGY_TYPE_VALUE.Dual)
                            {
                                _pxeWriteAccess.CreateLoPXEHeader((uint)maxLength, (uint)lowEnergyLines[0].Length);
                                _pxeWriteAccess.WriteLoDataLines(buffer, (uint)maxLength);
                                _pxeWriteAccess.WriteLowEngDarkSample(PixelConverter.Convert(_calibration.GetDarkData(lowEnergyInfo)));
                                _pxeWriteAccess.WriteLowEngAirSample(PixelConverter.Convert(_calibration.GetAirData(lowEnergyInfo)));

                                if (AppConfiguration.StoreReferenceCorrection)
                                {
                                    _pxeWriteAccess.WriteLoRef(_calibration.GetReferenceCorrections(lowEnergyInfo));
                                }

                                if (AppConfiguration.StoreScaleFactor)
                                {
                                    _pxeWriteAccess.WriteLoScaleFactor(_calibration.GetScaleFactor(lowEnergyInfo));
                                }

                                if (AppConfiguration.StoreAirDarkSamples)
                                {
                                    _pxeWriteAccess.WriteLoFullAirData(PixelConverter.Convert(_calibration.GetAirDataCollection(lowEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                    _pxeWriteAccess.WriteLoFullDarkData(PixelConverter.Convert(_calibration.GetDarkDataCollection(lowEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                }
                            }
                            else
                            {
                                _pxeWriteAccess.CreateLoPXEHeader((uint)maxLength, (uint)lowEnergyLines[0].Length);
                                _pxeWriteAccess.WriteLoDataLines(buffer, (uint)maxLength);
                                _pxeWriteAccess.WriteLowEngDarkSample(PixelConverter.Convert(_calibration.GetDarkData(lowEnergyInfo)));
                                _pxeWriteAccess.WriteLowEngAirSample(PixelConverter.Convert(_calibration.GetAirData(lowEnergyInfo)));

                                if (AppConfiguration.StoreReferenceCorrection)
                                {
                                    _pxeWriteAccess.WriteLoRef(_calibration.GetReferenceCorrections(lowEnergyInfo));
                                }

                                if (AppConfiguration.StoreScaleFactor)
                                {
                                    _pxeWriteAccess.WriteLoScaleFactor(_calibration.GetScaleFactor(lowEnergyInfo));
                                }

                                if (AppConfiguration.StoreAirDarkSamples)
                                {
                                    _pxeWriteAccess.WriteLoFullAirData(PixelConverter.Convert(_calibration.GetAirDataCollection(lowEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                    _pxeWriteAccess.WriteLoFullDarkData(PixelConverter.Convert(_calibration.GetDarkDataCollection(lowEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                }
                            }
                        }

                        lowEnergyLines.Clear();
                    }
                }
                catch { }

                try
                {
                    _pxeWriteAccess.ClosePXEWrite();
                }
                catch (Exception e)
                {
                    _log.LogError("Exception closing PXEWrite.");
                    _log.LogError(e.GetType().ToString() + ": " + e.Message);
                    _log.LogError(e.StackTrace);
                }
                return(pxeFile);
            }
        }
Exemplo n.º 30
0
 public void SendPulseWidthResponse(PulseWidth width)
 {
     CommandDefinition.CommandFormat packet = ReplyCreate(CommandEnum.PulseWidth, BooleanValue.True, ActionEnum.Response, (byte)width);
     ReplySend(packet);
 }
Exemplo n.º 31
0
        public string CreatePXEFile(LINAC_ENERGY_TYPE_VALUE energy, PulseWidth pulseWidth, List<DataInfo> ObjectLines)
        {
            lock (_writeLock)
            {
                string pxeFile = Path.Combine(AppConfiguration.HostTempFileLocation, DateTime.Now.ToString(_dateFormat) + _pxeExtension);
                _pxeWriteAccess.CreatePXE(pxeFile);

                try
                {
                    List<Pixel[]> highEnergyLines = new List<Pixel[]>();
                    List<Pixel[]> lowEnergyLines = new List<Pixel[]>();
                    XRayInfoIDStruct highEnergyInfo = default(XRayInfoIDStruct);
                    XRayInfoIDStruct lowEnergyInfo = default(XRayInfoIDStruct);

                    if (energy == LINAC_ENERGY_TYPE_VALUE.Dual)
                    {
                        if (ObjectLines[0].XRayInfo.Energy == XRayEnergyEnum.HighEnergy)
                            ObjectLines.RemoveAt(0);
                    }

                    //store object line data
                    foreach (DataInfo dataLine in ObjectLines)
                    {
                        if (dataLine.XRayInfo.Energy == XRayEnergyEnum.HighEnergy)
                        {
                            highEnergyLines.Add(dataLine.LineData);
                            highEnergyInfo = dataLine.XRayInfo;
                        }
                        else //low energy
                        {
                            lowEnergyLines.Add(dataLine.LineData);
                            lowEnergyInfo = dataLine.XRayInfo;
                        }
                    }

                    int maxLength = Math.Min(lowEnergyLines.Count, highEnergyLines.Count);

                    if (maxLength == 0)
                    {
                        maxLength = Math.Max(lowEnergyLines.Count, highEnergyLines.Count);
                    }
                    
                    if (maxLength > AppConfiguration.MaxPXEWidth)
                    {
                        maxLength = AppConfiguration.MaxPXEWidth;
                    }

                    if (energy != LINAC_ENERGY_TYPE_VALUE.Low && highEnergyLines.Count > 0)
                    {
                        int bufferSize = maxLength * highEnergyLines[0].Length;

                        if (bufferSize > 0)
                        {
                            float[] buffer = new float[bufferSize];
                            Parallel.For(highEnergyLines.Count - maxLength, maxLength, index =>
                            {
                                float[] pixelArray = PixelConverter.Convert(highEnergyLines[index]);
                                int length = Buffer.ByteLength(pixelArray);
                                Buffer.BlockCopy(pixelArray, 0, buffer, index * length, length);
                            });


                            if (energy == LINAC_ENERGY_TYPE_VALUE.Dual)
                            {
                                _pxeWriteAccess.CreateHiPXEHeader((uint)maxLength, (uint)highEnergyLines[0].Length);
                                _pxeWriteAccess.WriteHiDataLines(buffer, (uint)maxLength);
                                _pxeWriteAccess.WriteHighEngDarkSample(PixelConverter.Convert(_calibration.GetDarkData(highEnergyInfo)));
                                _pxeWriteAccess.WriteHighEngAirSample(PixelConverter.Convert(_calibration.GetAirData(highEnergyInfo)));

                                if (AppConfiguration.StoreReferenceCorrection)
                                {
                                    _pxeWriteAccess.WriteHiRef(_calibration.GetReferenceCorrections(highEnergyInfo));
                                }

                                if (AppConfiguration.StoreScaleFactor)
                                {
                                    _pxeWriteAccess.WriteHiScaleFactor(_calibration.GetScaleFactor(highEnergyInfo));
                                }

                                if (AppConfiguration.StoreAirDarkSamples)
                                {
                                    _pxeWriteAccess.WriteHiFullAirData(PixelConverter.Convert(_calibration.GetAirDataCollection(highEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                    _pxeWriteAccess.WriteHiFullDarkData(PixelConverter.Convert(_calibration.GetDarkDataCollection(highEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                }
                            }
                            else
                            {
                                _pxeWriteAccess.CreateHiPXEHeader((uint)maxLength, (uint)highEnergyLines[0].Length);
                                _pxeWriteAccess.WriteHiDataLines(buffer, (uint)maxLength);
                                _pxeWriteAccess.WriteHighEngDarkSample(PixelConverter.Convert(_calibration.GetDarkData(highEnergyInfo)));
                                _pxeWriteAccess.WriteHighEngAirSample(PixelConverter.Convert(_calibration.GetAirData(highEnergyInfo)));

                                if (AppConfiguration.StoreReferenceCorrection)
                                {
                                    _pxeWriteAccess.WriteHiRef(_calibration.GetReferenceCorrections(highEnergyInfo));
                                }

                                if (AppConfiguration.StoreScaleFactor)
                                {
                                    _pxeWriteAccess.WriteHiScaleFactor(_calibration.GetScaleFactor(highEnergyInfo));
                                }

                                if (AppConfiguration.StoreAirDarkSamples)
                                {
                                    _pxeWriteAccess.WriteHiFullAirData(PixelConverter.Convert(_calibration.GetAirDataCollection(highEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                    _pxeWriteAccess.WriteHiFullDarkData(PixelConverter.Convert(_calibration.GetDarkDataCollection(highEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                }
                            }
                        }

                        highEnergyLines.Clear();
                    }

                    if (energy != LINAC_ENERGY_TYPE_VALUE.High && lowEnergyLines.Count > 0)
                    {
                        int bufferSize = maxLength * lowEnergyLines[0].Length;

                        if (bufferSize > 0)
                        {
                            float[] buffer = new float[bufferSize];
                            Parallel.For(0, maxLength, index =>
                            {
                                float[] pixelArray = PixelConverter.Convert(lowEnergyLines[index]);
                                int length = Buffer.ByteLength(pixelArray);
                                Buffer.BlockCopy(pixelArray, 0, buffer, index * length, length);
                            });

                            if (energy == LINAC_ENERGY_TYPE_VALUE.Dual)
                            {
                                _pxeWriteAccess.CreateLoPXEHeader((uint)maxLength, (uint)lowEnergyLines[0].Length);
                                _pxeWriteAccess.WriteLoDataLines(buffer, (uint)maxLength);
                                _pxeWriteAccess.WriteLowEngDarkSample(PixelConverter.Convert(_calibration.GetDarkData(lowEnergyInfo)));
                                _pxeWriteAccess.WriteLowEngAirSample(PixelConverter.Convert(_calibration.GetAirData(lowEnergyInfo)));

                                if (AppConfiguration.StoreReferenceCorrection)
                                {
                                    _pxeWriteAccess.WriteLoRef(_calibration.GetReferenceCorrections(lowEnergyInfo));
                                }

                                if (AppConfiguration.StoreScaleFactor)
                                {
                                    _pxeWriteAccess.WriteLoScaleFactor(_calibration.GetScaleFactor(lowEnergyInfo));
                                }

                                if (AppConfiguration.StoreAirDarkSamples)
                                {
                                    _pxeWriteAccess.WriteLoFullAirData(PixelConverter.Convert(_calibration.GetAirDataCollection(lowEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                    _pxeWriteAccess.WriteLoFullDarkData(PixelConverter.Convert(_calibration.GetDarkDataCollection(lowEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                }
                            }
                            else
                            {
                                _pxeWriteAccess.CreateLoPXEHeader((uint)maxLength, (uint)lowEnergyLines[0].Length);
                                _pxeWriteAccess.WriteLoDataLines(buffer, (uint)maxLength);
                                _pxeWriteAccess.WriteLowEngDarkSample(PixelConverter.Convert(_calibration.GetDarkData(lowEnergyInfo)));
                                _pxeWriteAccess.WriteLowEngAirSample(PixelConverter.Convert(_calibration.GetAirData(lowEnergyInfo)));

                                if (AppConfiguration.StoreReferenceCorrection)
                                {
                                    _pxeWriteAccess.WriteLoRef(_calibration.GetReferenceCorrections(lowEnergyInfo));
                                }

                                if (AppConfiguration.StoreScaleFactor)
                                {
                                    _pxeWriteAccess.WriteLoScaleFactor(_calibration.GetScaleFactor(lowEnergyInfo));
                                }

                                if (AppConfiguration.StoreAirDarkSamples)
                                {
                                    _pxeWriteAccess.WriteLoFullAirData(PixelConverter.Convert(_calibration.GetAirDataCollection(lowEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                    _pxeWriteAccess.WriteLoFullDarkData(PixelConverter.Convert(_calibration.GetDarkDataCollection(lowEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                }
                            }
                        }

                        lowEnergyLines.Clear();
                    }
                }
                catch { }

                try
                {
                    _pxeWriteAccess.ClosePXEWrite();
                }
                catch (Exception e)
                {
                    _log.LogError("Exception closing PXEWrite.");
                    _log.LogError(e.GetType().ToString() + ": " + e.Message);
                    _log.LogError(e.StackTrace);
                }
                return pxeFile;
            }
        }
Exemplo n.º 32
0
 public bool SetConfigPulseWidth(PulseWidth? pulseWidth, float microseconds, bool confirm)
 {
     if (/*terminated?*/ _cancelEvent.WaitOne(0))
         return false;
     CommandDefinition.CommandFormat command = ConstructCommand(CommandEnum.ConfigPulseWidth, BooleanValue.True, ActionEnum.Set, (byte)pulseWidth);
     BitConverter.GetBytes(microseconds).CopyTo(command.Payload, 0);
     CommandDefinition.CommandFormat? response = SendCommand(command, confirm);
     if (confirm && (!ConfirmSetActionResponse(response, CommandEnum.ConfigPulseWidth, (byte)pulseWidth) ||
         microseconds != BitConverter.ToSingle(response.Value.Payload, 0)))
         return false;
     return true;
 }
Exemplo n.º 33
0
 public bool GetConfigPulseWidth(PulseWidth? pulseWidth, out float? time, bool confirm)
 {
     time = null;
     if (/*terminated?*/ _cancelEvent.WaitOne(0))
         return false;
     CommandDefinition.CommandFormat command = ConstructCommand(CommandEnum.ConfigPulseWidth, BooleanValue.True, ActionEnum.Get, (byte)pulseWidth);
     CommandDefinition.CommandFormat? response = SendCommand(command, confirm);
     if (response != null)
     {
         time = BitConverter.ToSingle(response.Value.Payload, 0);
         return true;
     }
     else
         return false;
 }
Exemplo n.º 34
0
 private void PulseWidthConfigure(PulseWidth width, float time)
 {
     string traceText = MethodBase.GetCurrentMethod().Name + "(" + width.ToString() + ", " + time.ToString() + ")";
     try
     {
         CommandDefinition.CommandFormat command = CommandMake(CommandEnum.ConfigPulseWidth, BooleanValue.True, ActionEnum.Set, (byte)width);
         BitConverter.GetBytes(time).CopyTo(command.Payload, 0);
         CommandDefinition.CommandFormat? reply = CommandSend(command, /*reply expected*/ true);
         string text = CommandReplyValidate(reply, CommandEnum.ConfigPulseWidth);
         if (/*fail?*/ text != string.Empty)
             throw new Exception(traceText + "; " + text);
         float timeValue = BitConverter.ToSingle(reply.Value.Payload, 0);
         if (/*incorrect result*/ time != timeValue)
             throw new Exception(traceText + "; " + time.ToString() + " != " + timeValue.ToString());
     }
     catch { throw; }
 }
Exemplo n.º 35
0
 public bool SetCurrentPulseWidth(PulseWidth pulseWidth, bool confirm)
 {
     if (/*terminated?*/ _cancelEvent.WaitOne(0))
         return false;
     CommandDefinition.CommandFormat command = ConstructCommand(CommandEnum.PulseWidth, BooleanValue.True, ActionEnum.Set, (byte)pulseWidth);
     CommandDefinition.CommandFormat? response = SendCommand(command, confirm);
     if (confirm && !ConfirmSetActionResponse(response, CommandEnum.PulseWidth, (byte)pulseWidth))
         return false;
     CurrentPulseWidth = pulseWidth;
     return true;
 }
Exemplo n.º 36
0
 /// <summary/>
 public bool SetCurrentPulseWidth(PulseWidth width, bool confirm)
 {
     bool status = false;
     string traceText = MethodBase.GetCurrentMethod().Name + "(" + width.ToString() + ")";
     try
     {
         CommandDefinition.CommandFormat command = CommandMake(CommandEnum.PulseWidth, BooleanValue.True, ActionEnum.Set, (byte)width);
         CommandDefinition.CommandFormat? reply = CommandSend(command, /*reply expected*/ true);
         if (/*ignore results?*/ !confirm)
             status = true;
         else
         {
             string text = CommandReplyValidate(reply, CommandEnum.PulseWidth, (byte)width);
             if (/*fail?*/ text != string.Empty)
                 throw new Exception(traceText + "; " + text);
             status = true;
         }
         CurrentPulseWidth = width;
     }
     catch (Exception ex)
     {
         status = false;
         throw ex;
     }
     return status;
 }
Exemplo n.º 37
0
 public bool GetCurrentPulseWidth(out PulseWidth? width, bool confirm)
 {
     width = null;
     if (/*terminated?*/ _cancelEvent.WaitOne(0))
         return false;
     CommandDefinition.CommandFormat command = ConstructCommand(CommandEnum.PulseWidth, BooleanValue.False, ActionEnum.Get, 0);
     CommandDefinition.CommandFormat? response = SendCommand(command, confirm);
     if (response != null && response.Value.CommandAck.Command == CommandEnum.PulseWidth && response.Value.Action.Action == ActionEnum.Response)
     {
         CurrentPulseWidth = (PulseWidth)PulseWidth.ToObject(typeof(PulseWidth), response.Value.Action.SubAction);
         width = CurrentPulseWidth;
         return true;
     }
     else
         return false;
 }
Exemplo n.º 38
0
 /// <summary/>
 public bool GetCurrentPulseWidth(out PulseWidth? width, bool confirm)
 {
     bool status = false;
     try
     {
         CommandDefinition.CommandFormat command = CommandMake(CommandEnum.PulseWidth, BooleanValue.False, ActionEnum.Get, 0);
         CommandDefinition.CommandFormat? reply = CommandSend(command, /*reply expected*/ true);
         string text = CommandReplyValidate(reply, CommandEnum.PulseWidth);
         if (/*fail?*/ !string.IsNullOrWhiteSpace(text))
             throw new Exception(text);
         CurrentPulseWidth = (PulseWidth)PulseWidth.ToObject(typeof(PulseWidth), reply.Value.Action.SubAction);
         width = CurrentPulseWidth;
         status = true;
     }
     catch (Exception ex)
     {
         width = null;
         status = false;
         if (/*run?*/ !_monitorEnd.WaitOne(0))
             if (/*OK to log?*/ LogPauseExpired)
                 try { Logger.LogError(Utilities.TextTidy(ex.ToString())); }
                 catch { }
     }
     return status;
 }
Exemplo n.º 39
0
        static void hostAccess_ProcessCommandEvent(CommandDefinition.CommandFormat command)
        {
            if (command.CommandAck.Command == CommandEnum.ScanMode)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    currentEnergyMode = (ScanEnergyMode)command.Action.SubAction;

                    PWMOutputConfig pwmConfig = (PWMOutputConfig)pc.GetPWMRunStatus();

                    if (pwmConfig == PWMOutputConfig.OutputEnabled)
                        pc.PWMOutputDisable();

                    if (currentEnergyMode == ScanEnergyMode.Dual)
                    {
                        Reset.Write(true);
                        Preset.Write(true);
                    }
                    else if (currentEnergyMode == ScanEnergyMode.High)
                    {
                        Reset.Write(true);
                        Preset.Write(false);
                    }
                    else
                    {
                        Reset.Write(false);
                        Preset.Write(true);
                    }

                    if (pwmConfig == PWMOutputConfig.OutputEnabled)
                        pc.PWMOutputEnable();
                }

                hostAccess.SendScanModeResponse(currentEnergyMode);
            }
            else if (command.CommandAck.Command == CommandEnum.StaticPulseFreq)
            {
                OperatingMode mode = (OperatingMode)command.Action.SubAction;
                int freq = BitConverter.ToInt32(command.Payload, 0); ;

                if (command.Action.Action == ActionEnum.Set)
                {
                    if (mode == OperatingMode.NonAdaptiveMobile)
                        StaticPulseFreq[0] = freq;
                    else if (mode == OperatingMode.NonAdpativePortal)
                        StaticPulseFreq[1] = freq;

                    if (currentOperatingMode == mode)
                    {
                        currentStaticPulseFreq = freq;
                        pc.UpdatePWMFrequency(freq);
                    }

                    hostAccess.SendStaticPulseFreqResponse(mode, freq);
                }
                else if (command.Action.Action == ActionEnum.Get)
                {
                    if (mode == OperatingMode.NonAdaptiveMobile)
                        freq = StaticPulseFreq[0];
                    else if (mode == OperatingMode.NonAdpativePortal)
                        freq = StaticPulseFreq[1];

                    hostAccess.SendStaticPulseFreqResponse(mode, freq);
                }
            }
            else if (command.CommandAck.Command == CommandEnum.PulseWidth)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    if (currentPulseWidth != (PulseWidth)command.Action.SubAction)
                    {
                        currentPulseWidth = (PulseWidth)command.Action.SubAction;
                        pc.UpdatePWMPulseWidth(PulseWidthsDutyCycle[(int)currentPulseWidth - 1]);
                    }
                }

                hostAccess.SendPulseWidthResponse(currentPulseWidth);
            }
            else if (command.CommandAck.Command == CommandEnum.ConfigPulseWidth)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    int index = command.Action.SubAction - 1;
                    PulseWidthsDutyCycle[index] = BitConverter.ToSingle(command.Payload, 0);

                    if (currentPulseWidth == (PulseWidth)command.Action.SubAction)
                        pc.UpdatePWMPulseWidth(PulseWidthsDutyCycle[index]);
                }

                PulseWidth width = (PulseWidth)command.Action.SubAction;
                hostAccess.SendPulseWidthConfigResponse(width, PulseWidthsDutyCycle[(byte)width - 1]);
            }
            else if (command.CommandAck.Command == CommandEnum.OperatingMode)
            {
                short minFreq, maxFreq;

                if (command.Action.Action == ActionEnum.Set)
                {
                    minFreq = (short)BitConverter.ToInt16(command.Payload, 0);
                    maxFreq = (short)BitConverter.ToInt16(command.Payload, 2);
                    currentOperatingMode = (OperatingMode)command.Action.SubAction;

                    if ((currentOperatingMode == OperatingMode.NonAdaptiveMobile) || (currentOperatingMode == OperatingMode.NonAdpativePortal))
                    {
                        if (currentOperatingMode == OperatingMode.NonAdaptiveMobile)
                            currentStaticPulseFreq = StaticPulseFreq[0];
                        else
                            currentStaticPulseFreq = StaticPulseFreq[1];

                        pc.SetOperatingMode(currentOperatingMode);
                        pc.UpdatePWMFrequency(currentStaticPulseFreq);
                        pc.UpdatePWMPulseWidth(PulseWidthsDutyCycle[(int)currentPulseWidth - 1]);
                        pc.PWMOutputEnable();
                    }
                    else if ((currentOperatingMode == OperatingMode.AdaptiveMobile) || (currentOperatingMode == OperatingMode.AdaptivePortal))
                    {
                        pc.SetFrequencyRange(currentOperatingMode, minFreq, maxFreq);
                        pc.SetOperatingMode(currentOperatingMode);
                        pc.PWMOutputEnable();
                    }

                    hostAccess.SendOperatingModeResponse(currentOperatingMode, minFreq, maxFreq);
                }
                else if (command.Action.Action == ActionEnum.Get)
                {
                    pc.GetFrequencyRange(currentOperatingMode, out minFreq, out maxFreq);
                    hostAccess.SendOperatingModeResponse(currentOperatingMode, minFreq, maxFreq);
                }
            }
            else if (command.CommandAck.Command == CommandEnum.AdaptiveModeToTrigRatio)
            {
                float ratio;
                OperatingMode mode = (OperatingMode)command.Action.SubAction;

                if (command.Action.Action == ActionEnum.Set)
                {
                    ratio = BitConverter.ToSingle(command.Payload, 0);

                    pc.SetInputToOutputRatio(mode, ratio);

                    hostAccess.SendAdaptiveModeToTrigRatioResponse(mode, ratio);
                }
                else if (command.Action.Action == ActionEnum.Get)
                {
                    pc.GetInputToOutputRatio(mode, out ratio);
                    hostAccess.SendAdaptiveModeToTrigRatioResponse(mode, ratio);
                }
            }
            else if (command.CommandAck.Command == CommandEnum.AdaptiveSpeedFeedbackConfig)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    adaptiveSpeedMsgFreq = BitConverter.ToSingle(command.Payload, 0);
                    speedMsgMode = (AdaptiveSpeedFeedbackConfig)command.Action.SubAction;

                    if ((speedMsgMode == AdaptiveSpeedFeedbackConfig.EnabledWithFreq) && (adaptiveSpeedMsgFreq > 0.0f))
                    {
                        int period = (int)(1000.0f / adaptiveSpeedMsgFreq);
                        adaptiveSpeedMsgTimer.Change(period, period);
                    }
                    else
                        adaptiveSpeedMsgTimer.Change(Timeout.Infinite, Timeout.Infinite);
                }

                hostAccess.SendAdaptiveSpeedFeedbackConfigResponse(speedMsgMode, adaptiveSpeedMsgFreq);
            }
            else if (command.CommandAck.Command == CommandEnum.PWMOutput)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    if ((PWMOutputConfig)command.Action.SubAction == PWMOutputConfig.OutputEnabled)
                        pc.PWMOutputEnable();
                    else
                        pc.PWMOutputDisable();

                    hostAccess.SendPWMOutputStatus((PWMOutputConfig)command.Action.SubAction);
                }
                else if (command.Action.Action == ActionEnum.Get)
                {
                    hostAccess.SendPWMOutputStatus((PWMOutputConfig)pc.GetPWMRunStatus());
                }
            }
            else if (command.CommandAck.Command == CommandEnum.ResetBoard)
                ResetBoard();
        }