public bool SetScanEnergyMode(ScanEnergyMode mode, bool confirm) { if (/*terminated?*/ _cancelEvent.WaitOne(0)) return false; CommandDefinition.CommandFormat command = ConstructCommand(CommandEnum.ScanMode, BooleanValue.True, ActionEnum.Set, (byte)mode); CommandDefinition.CommandFormat? response = SendCommand(command, confirm); if (confirm && !ConfirmSetActionResponse(response, CommandEnum.ScanMode, (byte)mode)) return false; return true; }
public bool SetScanEnergyMode(ScanEnergyMode mode, bool confirm) { if (/*terminated?*/ _cancelEvent.WaitOne(0)) { return(false); } CommandDefinition.CommandFormat command = ConstructCommand(CommandEnum.ScanMode, BooleanValue.True, ActionEnum.Set, (byte)mode); CommandDefinition.CommandFormat?response = SendCommand(command, confirm); if (confirm && !ConfirmSetActionResponse(response, CommandEnum.ScanMode, (byte)mode)) { return(false); } return(true); }
public bool GetScanEnergyMode(out ScanEnergyMode?mode, bool confirm) { mode = null; if (/*terminated?*/ _cancelEvent.WaitOne(0)) { return(false); } CommandDefinition.CommandFormat command = ConstructCommand(CommandEnum.ScanMode, BooleanValue.False, ActionEnum.Get, 0); CommandDefinition.CommandFormat?response = SendCommand(command, confirm); if (response != null && response.Value.CommandAck.Command == CommandEnum.ScanMode && response.Value.Action.Action == ActionEnum.Response) { mode = (ScanEnergyMode)ScanEnergyMode.ToObject(typeof(ScanEnergyMode), response.Value.Action.SubAction); return(true); } else { return(false); } }
/// <summary/> public bool GetScanEnergyMode(out ScanEnergyMode? mode, bool confirm) { bool status = false; try { CommandDefinition.CommandFormat command = CommandMake(CommandEnum.ScanMode, BooleanValue.False, ActionEnum.Get, 0); CommandDefinition.CommandFormat? reply = CommandSend(command, /*reply expected*/ true); string text = CommandReplyValidate(reply, CommandEnum.ScanMode); if (/*fail?*/ !string.IsNullOrWhiteSpace(text)) throw new Exception(text); mode = (ScanEnergyMode)ScanEnergyMode.ToObject(typeof(ScanEnergyMode), reply.Value.Action.SubAction); status = true; } catch (Exception ex) { mode = null; status = false; if (/*OK to log?*/ LogPauseExpired) try { Logger.LogError(Utilities.TextTidy(ex.ToString())); } catch { } } return status; }
/// <summary/> public bool SetScanEnergyMode(ScanEnergyMode mode, bool confirm) { bool status = false; try { CommandDefinition.CommandFormat command = CommandMake(CommandEnum.ScanMode, BooleanValue.True, ActionEnum.Set, (byte)mode); CommandDefinition.CommandFormat? reply = CommandSend(command, /*reply expected*/ true); if (/*ignore results?*/ !confirm) status = true; else { string text = CommandReplyValidate(reply, CommandEnum.ScanMode, (byte)mode); if (/*fail?*/ !string.IsNullOrWhiteSpace(text)) throw new Exception(text); status = true; } } catch (Exception ex) { Debug.Assert(!status); if (/*OK to log?*/ LogPauseExpired) try { Logger.LogError(Utilities.TextTidy(ex.ToString())); } catch { } } #if DEBUG try { Logger.LogInfo(MethodBase.GetCurrentMethod() + "(" + mode.ToString() + ", " + confirm.ToString() + ") returns " + status.ToString()); } catch { } #endif return status; }
public void SendScanModeResponse(ScanEnergyMode mode) { CommandDefinition.CommandFormat packet = ReplyCreate(CommandEnum.ScanMode, BooleanValue.True, ActionEnum.Response, (byte)mode); ReplySend(packet); }
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(); } }
public bool GetScanEnergyMode(out ScanEnergyMode? mode, bool confirm) { mode = null; if (/*terminated?*/ _cancelEvent.WaitOne(0)) return false; CommandDefinition.CommandFormat command = ConstructCommand(CommandEnum.ScanMode, BooleanValue.False, ActionEnum.Get, 0); CommandDefinition.CommandFormat? response = SendCommand(command, confirm); if (response != null && response.Value.CommandAck.Command == CommandEnum.ScanMode && response.Value.Action.Action == ActionEnum.Response) { mode = (ScanEnergyMode)ScanEnergyMode.ToObject(typeof(ScanEnergyMode), response.Value.Action.SubAction); return true; } else return false; }
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 { } } }
private void SetApcsEnergyMode(ScanEnergyMode energyMode) { Thread.Sleep(1000); try { _dataAccess.Apcs.SetScanEnergyMode(energyMode, true); } catch (ThreadAbortException) { /*suppress*/ } catch (Exception ex) { FailedCalibration("APCS Energy Mode unable to be set.\n" + ex.ToString()); } }
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(); } }
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); } }
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); }
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(); }