/// <summary> /// 执行强制编程命令 /// </summary> /// <param name="client">PcbTesterClient句柄</param> /// <param name="parameter">命令参数</param> /// <param name="context">不同命令之间的通信参数</param> /// <returns>检测结果</returns> public CommandResult Execute(PcbTesterClient client, CommandParameter parameter, CommandContext context) { var forceProgramParameter = parameter as ForceProgramCommandParameter; WriteResult writeResult = client.Write(Obis, FormatWriteParameter(forceProgramParameter)); if (!writeResult.Success) { string message = string.Format( Resources.ForceProgramCommand_WriteFailedMessageFormat, this.Name, writeResult.Error.ToString(), forceProgramParameter.ToString()); logger.Error(message); throw new CommunicationException(message); } //读取强编状态 ReadResult readResult = client.Read(Obis, string.Empty); while (StringResultToEnum(readResult.Data) == ForceProgramState.ForceProgramProcessing) { System.Threading.Thread.Sleep(1000); readResult = client.Read(Obis, string.Empty); if (!readResult.Success) { break; } if (readResult.Data == ForceProgramState.Succeed.ToString()) { break; } } //强编失败 if (!readResult.Success) { return(new CommandResult( false, readResult.Error.ToString(), string.Format( Resources.ForceProgramCommand_ForceProgramErrorMessageFormat, this.Name, forceProgramParameter.ToString(), ForceProgramState.Succeed.ToString(), readResult.Error.ToString()))); } return(new CommandResult(true)); }
/// <summary> /// 执行断路器检测命令 /// </summary> /// <param name="client">PcbTesterClient句柄</param> /// <param name="parameter">命令参数</param> /// <param name="context">不同命令之间的通信参数</param> /// <returns>检测结果</returns> public CommandResult Execute(PcbTesterClient client, CommandParameter parameter, CommandContext context) { WriteResult writeResult = client.Write("0-0:199.128.11", string.Empty); if (!writeResult.Success) { string message = string.Format("{0};0x{1:X};{2}", Resources.BreakerTest, string.Empty, writeResult.Error.ToString()); logger.ErrorFormat("{0}", message); throw new CommunicationException(message); } ReadResult testResult = client.Read("0-0:199.128.11", string.Empty); //检测结果为错误码 if (!testResult.Success) { logger.ErrorFormat("{0}", testResult.Data); throw new CommunicationException(testResult.Data); } //检测板支持三路断路器检测,三路检测结果用逗号隔开,取值为“OK”/“ERROR”。e.g. OK,ERROR,ERROR string[] breakerState = testResult.Data.Split(','); for (int i = 0; i < breakerState.Length; i++) { if (breakerState[i] == "ERROR") { return(new CommandResult(false, testResult.Data)); } } return(new CommandResult(true, testResult.Data)); }
/// <summary> /// 执行读错误详细信息命令 /// </summary> /// <param name="client">PcbTesterClient句柄</param> /// <param name="parameter">命令参数</param> /// <param name="context">不同命令之间的通信参数</param> /// <returns>检测结果</returns> public CommandResult Execute(PcbTesterClient client, CommandParameter parameter, CommandContext context) { var testResult = client.Read("0-0:199.128.12", string.Empty); //检测结果为错误码 //if (!testResult.Contains(":") && testResult.Length == 6) //{ // logger.ErrorFormat("{0}", testResult); //// throw new CommunicationException(testResult); //} return(new CommandResult(true, testResult.Data)); }
/// <summary> /// 执行读取地址命令 /// </summary> /// <param name="client">PcbTesterClient句柄</param> /// <param name="parameter">命令参数</param> /// <param name="context">不同命令之间的通信参数</param> /// <returns>检测结果</returns> public CommandResult Execute(PcbTesterClient client, CommandParameter parameter, CommandContext context) { var addressParameter = parameter as AddressCommandParameter; ReadResult readResult = client.Read(Obis, FormatReadParameter(addressParameter)); //检测结果为错误码 if (!readResult.Success) { string messgae = string.Format( Resources.ReadAddressCommandBase_ReadFailedMessageFormat, this.Name, readResult.Error.ToString(), addressParameter.ToString()); logger.Error(messgae); throw new CommunicationException(messgae); } //将读到的值与期望值做比较 if (readResult.Data == addressParameter.Data) { return(new CommandResult(true, readResult.Data)); } else { return(new CommandResult( false, readResult.Data, string.Format( Resources.ReadAddressCommandBase_ReadErrorMessageFormat, this.Name, addressParameter.Address, addressParameter.Length, addressParameter.Data, readResult.Data))); } }
/// <summary> /// 执行秒信号检测命令 /// </summary> /// <param name="client">PcbTesterClient句柄</param> /// <param name="parameter">命令参数</param> /// <param name="context">不同命令之间的通信参数</param> /// <returns>检测结果</returns> public CommandResult Execute(PcbTesterClient client, CommandParameter parameter, CommandContext context) { var secondParameter = parameter as SecondSignalCalibrationParameter; while (true) { RelayControlHelper.On5V(client); if (secondParameter.EnableActivateClockSignal) //如果需要激活表秒信号功能 { logger.Debug("Activate second signal..."); ActivateSecond(client, secondParameter); } logger.Debug("Start test second signal..."); WriteResult writeResult = client.Write(Obis, string.Empty); //开始检测秒信号失败 if (!writeResult.Success) { string message = string.Format( Resources.SecondSignalCalibrationCommand_WriteFailedMessageFormat, this.Name, writeResult.Error.ToString(), string.Empty); logger.Error(message); throw new CommunicationException(message); } //等待发送读取秒信号检测结果命令 System.Threading.Thread.Sleep((int)secondParameter.DelayTime); logger.Debug("Read test second signal result..."); ReadResult readResult = client.Read(Obis, string.Empty); //发送读秒信号检测结果帧 //检测结果为错误码 if (!readResult.Success) { string message = string.Format( Resources.SecondSignalCalibrationCommand_ReadResultFailedMessageFormat, this.Name, readResult.Error.ToString(), string.Empty); logger.Error(message); throw new CommunicationException(message); } decimal clockValue = ParseClockSignalResult(readResult.Data); if (clockValue == noValue) //无秒信号值 { logger.Error(Resources.SecondSignalCalibrationCommand_NoValue); throw new CommunicationException(Resources.SecondSignalCalibrationCommand_NoValue); } //结果在误差范围内 正确结果 if (secondParameter.IsWithinRange(clockValue)) { return(new CommandResult(true, readResult.Data)); } //秒信号错误,不在误差范围内,判断是否需要补偿秒信号 if (!secondParameter.EnableAutoClockCompensation) // 不需要补偿,返回错误结果 { string expectedValue = secondParameter.ExpectedValueRange; return(new CommandResult( false, readResult.Data, string.Format( Resources.SecondSignalCalibrationCommand_MeasureErrorMessageFormat, this.Name, secondParameter.ToString(), secondParameter.ExpectedValueRange, readResult.Data))); } logger.Debug("Compensate second signal..."); //补偿秒信号 CompensateClockSignal(client, secondParameter, clockValue); } }
/// <summary> /// 执行脉冲检测命令 /// </summary> /// <param name="client">PcbTesterClient句柄</param> /// <param name="parameter">命令参数</param> /// <param name="context">不同命令之间的通信参数</param> /// <returns>检测结果</returns> public CommandResult Execute(PcbTesterClient client, CommandParameter parameter, CommandContext context) { RelayControlHelper.On5V(client); StringBuilder sb = new StringBuilder(); var relayControlPara = new RelayControlCommandParameter(); relayControlPara.SelectedNumber = "20"; RelayControlHelper.PulseRelayControl(client, RelayControlAction.OPEN); CommandResult commandResult = new CommandResult(); for (int i = 0; i < 2; i++) { if (i == 0) { relayControlPara.Action = RelayControlAction.OPEN; } else if (i == 1) { relayControlPara.Action = RelayControlAction.CLOSE; } //控制脉冲检测对应继电器 var relayControlCommand = new RelayControlCommand(); commandResult = relayControlCommand.Execute(client, relayControlPara, context); //继电器操作失败 if (!commandResult.Success) { return(commandResult); } System.Threading.Thread.Sleep(500); //发送检测命令 WriteResult writeResult = client.Write("0-0:199.128.1", string.Empty); //启动脉冲采集命令异常应答 if (!writeResult.Success) { string message = string.Format("{0};0x{1:X};{2}", this.Name, string.Empty, writeResult.Error.ToString()); logger.ErrorFormat("{0}", message); throw new CommunicationException(message); } //等待1s发送读取脉冲检测结果命令 System.Threading.Thread.Sleep(1000); ReadResult testResult = client.Read("0-0:199.128.1", string.Empty); //检测结果为错误码 if (!testResult.Success) { logger.ErrorFormat("{0}", testResult.Data); throw new CommunicationException(testResult.Data); } commandResult.Success = true; sb.Append(testResult); if (i == 0) { sb.Append(","); } } commandResult.Data = sb.ToString(); return(commandResult); }
/// <summary> /// 执行电量测量 /// </summary> /// <param name="client">PcbTesterClient句柄</param> /// <param name="parameter">命令参数</param> /// <param name="context">不同命令之间的通信参数</param> /// <returns>检测结果</returns> public CommandResult Execute(PcbTesterClient client, CommandParameter parameter, CommandContext context) { var electricalParameter = parameter as MeasureParameter; WriteResult writeResult = client.Write(Obis, FormatWriteParameter(electricalParameter)); if (!writeResult.Success) { string message = string.Format( Resources.MeasureCommandBase_StartFailedMessageFormat, this.Name, writeResult.Error.ToString(), electricalParameter.ToString()); logger.Error(message); throw new CommunicationException(message); } ReadResult readResult = client.Read(ReadResultObis, string.Empty); //检测结果为错误码 if (!readResult.Success) { string message = string.Format( Resources.MeasureCommandBase_ReadResultFailedMessageFormat, this.Name, readResult.Error.ToString(), string.Empty); logger.Error(message); throw new CommunicationException(message); } decimal measureValue = ParseMeasureValue(readResult.Data, Unit); if (Unit == "mV") //单位mv { electricalParameter.LowerLimit *= 1000m; //UI上设置的电压单位是V,直流电压测量的数据单位是mV,将V转为mV electricalParameter.UpperLimit *= 1000m; } //测量结果不在所规定的误差范围 if (!electricalParameter.IsWithinRange(measureValue)) { string expectedValue = string.Format("{0}{1}-{2}{3}", electricalParameter.LowerLimit, Unit, electricalParameter.UpperLimit, Unit); return(new CommandResult( false, readResult.Data, string.Format( Resources.MeasureCommandBase_MeasureErrorMessageFormat, this.Name, electricalParameter.PinNumber, electricalParameter.CurrentRange, electricalParameter.Phase, expectedValue, readResult.Data))); } return(new CommandResult(true, readResult.Data)); }