/// <summary/> public bool SetPWMOutputEnable(PWMOutputConfig? enable, bool confirm) { bool status = false; try { CommandDefinition.CommandFormat command = CommandMake(CommandEnum.PWMOutput, BooleanValue.True, ActionEnum.Set, (byte)enable); CommandDefinition.CommandFormat? reply = CommandSend(command, /*reply expected*/ true); if (/*ignore results?*/ !confirm) status = true; else { string text = CommandReplyValidate(reply, CommandEnum.PWMOutput, (byte)enable); if (/*fail?*/ text != string.Empty) 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() + "(" + ((enable == null) ? "null" : enable.ToString()) + ", " + confirm.ToString() + ") returns " + status.ToString()); } catch { } #endif return status; }
/// <summary/> public bool GetPWMOutputEnable(out PWMOutputConfig? enable, bool confirm) { bool status = false; try { CommandDefinition.CommandFormat command = CommandMake(CommandEnum.PWMOutput, BooleanValue.False, ActionEnum.Get, 0); CommandDefinition.CommandFormat? reply = CommandSend(command, /*reply expected*/ true); string text = CommandReplyValidate(reply, CommandEnum.PWMOutput); if (/*fail?*/ !string.IsNullOrWhiteSpace(text)) throw new Exception(text); enable = (PWMOutputConfig)reply.Value.Action.SubAction; status = true; } catch (Exception ex) { enable = null; status = false; if (/*OK to log?*/ LogPauseExpired) try { Logger.LogError(Utilities.TextTidy(ex.ToString())); } catch { } } return status; }
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 void SendPWMOutputStatus(PWMOutputConfig status) { CommandDefinition.CommandFormat packet = ReplyCreate(CommandEnum.PWMOutput, BooleanValue.True, ActionEnum.Response, (byte)status); ReplySend(packet); }
public void SendPWMOutputStatus(PWMOutputConfig status) { CommandDefinition.CommandFormat packet = ReplyCreate(CommandEnum.PWMOutput, BooleanValue.True, ActionEnum.Response, (byte)status); ReplySend(packet); }
public bool GetPWMOutput(out PWMOutputConfig? config, bool confirm) { config = null; if (/*terminated?*/ _cancelEvent.WaitOne(0)) return false; CommandDefinition.CommandFormat command = ConstructCommand(CommandEnum.PWMOutput, BooleanValue.False, ActionEnum.Get, 0); CommandDefinition.CommandFormat? response = SendCommand(command, confirm); if (response != null && response.Value.CommandAck.Command == CommandEnum.PWMOutput && response.Value.Action.Action == ActionEnum.Response) { config = (PWMOutputConfig)response.Value.Action.SubAction; return true; } else return false; }
public bool SetPWMOutput(PWMOutputConfig? config, bool confirm) { if (/*terminated?*/ _cancelEvent.WaitOne(0)) return false; CommandDefinition.CommandFormat command = ConstructCommand(CommandEnum.PWMOutput, BooleanValue.True, ActionEnum.Set, (byte)config); CommandDefinition.CommandFormat? response = SendCommand(command, confirm); if (confirm && (!ConfirmSetActionResponse(response, CommandEnum.PWMOutput, (byte)config))) return false; return true; }
public bool SetPWMOutputEnable(PWMOutputConfig? /*enabled?*/ Enb, bool /*confirm*/ Cnf) { string /*trace text*/ trc = MethodBase.GetCurrentMethod().Name + "(" + ((Enb != null) ? Enb.ToString() : "null") + ", " + Cnf.ToString() + ")"; bool /*status (returned)*/ sts = false; try { CommandDefinition.CommandFormat /*command */ cmd = ConstructCommand( CommandEnum.PWMOutput, BooleanValue.True, ActionEnum.Set, (byte)Enb); CommandDefinition.CommandFormat? /*response*/ rsp = SendCommand(cmd, Cnf); sts = !Cnf || ConfirmSetActionResponse(rsp, CommandEnum.PWMOutput, (byte)Enb); } catch (Exception ex) { Lgr.LogError(ex); } return sts; }
public bool GetPWMOutputEnable( out PWMOutputConfig? /*enabled?*/ Enb, bool /*confirm*/ Cnf) { CommandDefinition.CommandFormat /*command*/ cmd = ConstructCommand(CommandEnum.PWMOutput, BooleanValue.False, ActionEnum.Get, 0); CommandDefinition.CommandFormat? /*response; might be null*/ rsp = SendCommand(cmd, Cnf); Enb = null; if ((rsp != null) && (rsp.Value.CommandAck.Command == CommandEnum.PWMOutput) && (rsp.Value.Action.Action == ActionEnum.Response)) { Enb = (PWMOutputConfig)rsp.Value.Action.SubAction; return true; } else return false; }