Example #1
0
        public static CommandResult PulseRelayControl(PcbTesterClient client, RelayControlAction action)
        {
            var relayControlCommand = new RelayControlCommand();
            var parameter           = new RelayControlCommandParameter(action, "20");

            return(relayControlCommand.Execute(client, parameter, null));
        }
Example #2
0
        public static CommandResult ControlRelay(PcbTesterClient client, RelayControlCommandParameter relayParameter)
        {
            client.Open();
            var relayControlCommand = new RelayControlCommand();

            try
            {
                CommandResult result = relayControlCommand.Execute(client, relayParameter, null);
            }
            catch (CommunicationException ex)
            {
                throw new CommunicationException(ex.Message);
            }
            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)
        {
            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);
        }