/// <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); }