/// <summary>
        /// 打印Log数据
        /// </summary>
        public void PrintfLog(RichTextBox msg = null)
        {
            if (msg == null)
            {
                return;
            }
            if ((this.siteACurrentX100mA.Count == 0) || (this.siteBCurrentX100mA.Count == 0) || (this.siteCCurrentX100mA.Count == 0) || (this.siteDCurrentX100mA.Count == 0))
            {
                return;
            }
            string str = "粗略起始频率:" + this.startFreqMHz.ToString("D") + "MHz" + ";有效的SITE数:" + this.siteNum.ToString("D") + "\r\n";

            if (msg != null)
            {
                RichTextBoxPlus.AppendTextInfoWithDateTime(msg, str, Color.Black, false);
            }
            int i = 0;

            //---起始频率
            int    freqMHz = 0;
            string fileLog = "";

            for (i = 0; i < this.siteACurrentX100mA.Count; i++)
            {
                if (i == 0)
                {
                    freqMHz = this.startFreqMHz;
                }
                else
                {
                    freqMHz += this.stepFreqMHz;
                }
                str = freqMHz.ToString("D") + ";" + this.siteACurrentX100mA[i].ToString("D") + ";" + this.siteBCurrentX100mA[i].ToString("D") + ";" + this.siteCCurrentX100mA[i].ToString("D") + ";" + this.siteDCurrentX100mA[i].ToString("D") + "\r\n";
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoWithoutDateTime(msg, str, Color.Black, false);
                }
                fileLog += str;
            }
            FileFuncTXT txtFile = new FileFuncTXT();

            txtFile.WriteToTxtFile("sitemA.txt", fileLog);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="usedPort"></param>
        /// <param name="usedChart"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public virtual int FreqCurrentDo(COMMPort usedPort, MyChart usedChart, RichTextBox msg = null)
        {
            if (usedPort == null)
            {
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "通信端口初始化失败!\r\n", Color.Red, false);
                }
                return(1);
            }
            int _return = 0;

            byte[] res = null;

            //---将命令写入设备并读取返回的值
            _return = usedPort.ReadFromDevice(ref res, 1000, msg);

            //---通信验证
            if ((_return == 0) && (usedPort.m_COMMPortReadDataFormatPassed == true) && (res[usedPort.m_COMMPortDataReadIndex + 1] == 0))
            {
                if (msg != null)
                {
                    //---清除文本
                    RichTextBoxPlus.Clear(msg);
                    //---消息
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "频率电流扫描结果读取成功!\r\n", Color.Black, false);

                    //---进行一次频率电流扫描消耗的时间
                    RichTextBoxPlus.AppendTextInfoWithDateTime(msg, "消耗的时间:" + ((int)usedPort.m_COMMPortUsedTime.Milliseconds).ToString("D") + "ms\r\n", Color.Black, false);
                }
                this.usedSiteCurrent = new RFASKSiteCurrent();
                byte[] siteCurrent = new byte[res.Length - usedPort.m_COMMPortDataReadIndex - 4];
                Array.Copy(res, (usedPort.m_COMMPortDataReadIndex + 4), siteCurrent, 0, siteCurrent.Length);

                //---获取各个site的电流
                this.usedSiteCurrent.Init(res[usedPort.m_COMMPortDataReadIndex + 3], siteCurrent);
                //---将数据刷新到画图控件
                this.usedSiteCurrent.Init(res[usedPort.m_COMMPortDataReadIndex + 3], 2, usedChart);
                //---打印Log数据
                this.usedSiteCurrent.PrintfLog(msg);
            }
            else
            {
                if (_return != 0)
                {
                    if (msg != null)
                    {
                        RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "通信发生错误!\r\n", Color.Red, false);
                    }
                }
                else if (usedPort.m_COMMPortDataFormatPassed == false)
                {
                    if (msg != null)
                    {
                        RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "读取的数据格式不合法!\r\n", Color.Red, false);
                    }
                }
                else if (res[usedPort.m_COMMPortDataReadIndex + 1] != 0)
                {
                    if (msg != null)
                    {
                        RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "数据返回的结果错误!\r\n", Color.Red, false);
                    }
                }
                else
                {
                    if (msg != null)
                    {
                        RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "通信命令验证错误!\r\n", Color.Red, false);
                    }
                }
            }
            return(_return);
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="freqPointIndexCMD"></param>
        /// <param name="deviceCurrent"></param>
        /// <param name="usedPort"></param>
        /// <param name="usedChart"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        protected virtual int FreqCurrentDo(int freqPointIndexCMD, FreqCurrentControl deviceCurrent, COMMPort usedPort, MyChart usedChart, RichTextBox msg = null)
        {
            if (usedPort == null)
            {
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "通信端口初始化失败!\r\n", Color.Red, false);
                }
                return(1);
            }
            if (deviceCurrent == null)
            {
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "频率电流控件传递错误!\r\n", Color.Red, false);
                }
                return(2);
            }
            int _return = 0;

            byte[] cmd = new byte[] { (byte)freqPointIndexCMD, (byte)RFASKFreqCurrentPointCMD.CMD_RFASK_CMD1_FREQ_CURRENT_POINT_DO };
            byte[] res = null;

            //---将命令写入设备并读取返回的值
            _return = usedPort.SendCmdAndReadResponse(cmd, ref res, 1000);

            //---通信验证
            if ((_return == 0) && (usedPort.m_COMMPortDataFormatPassed == true) && (res[usedPort.m_COMMPortDataReadIndex + 1] == 0) && (res[usedPort.m_COMMPortDataReadIndex + 2] == cmd[1]))
            {
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "频率电流的第" + (freqPointIndexCMD - 3).ToString() + "个点的频率电流扫描!\r\n", Color.Black, false);

                    //---进行一次频率电流扫描消耗的时间
                    RichTextBoxPlus.AppendTextInfoWithDateTime(msg, "消耗的时间:" + ((int)usedPort.m_COMMPortUsedTime.Milliseconds).ToString("D") + "ms\r\n", Color.Black, false);
                }
                this.usedSiteCurrent = new RFASKSiteCurrent();
                byte[] siteCurrent = new byte[res.Length - usedPort.m_COMMPortDataReadIndex - 4];
                Array.Copy(res, (usedPort.m_COMMPortDataReadIndex + 4), siteCurrent, 0, siteCurrent.Length);

                //---获取各个site的电流
                this.usedSiteCurrent.Init(res[usedPort.m_COMMPortDataReadIndex + 3], siteCurrent);
                this.usedSiteCurrent.Init(res[usedPort.m_COMMPortDataReadIndex + 3], (int)deviceCurrent.m_StepFreq, usedChart);
                //---打印Log数据
                this.usedSiteCurrent.PrintfLog(msg);
            }
            else
            {
                if (_return != 0)
                {
                    if (msg != null)
                    {
                        RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "通信发生错误!\r\n", Color.Red, false);
                    }
                }
                else if (usedPort.m_COMMPortDataFormatPassed == false)
                {
                    if (msg != null)
                    {
                        RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "读取的数据格式不合法!\r\n", Color.Red, false);
                    }
                }
                else if (res[usedPort.m_COMMPortDataReadIndex + 1] != 0)
                {
                    if (msg != null)
                    {
                        RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "数据返回的结果错误!\r\n", Color.Red, false);
                    }
                }
                else
                {
                    if (msg != null)
                    {
                        RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "通信命令验证错误!\r\n", Color.Red, false);
                    }
                }
            }
            return(_return);
        }