Пример #1
0
        /// <summary>
        /// 复位WM8510
        /// </summary>
        /// <param name="usedPort"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        protected virtual int ClockWM8510Reset(COMMPort usedPort, RichTextBox msg = null)
        {
            if (usedPort == null)
            {
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "通信端口初始化失败!\r\n", Color.Red, false);
                }
                return(1);
            }
            int _return = 0;

            byte[] cmd = new byte[] { CMD_RFASK_CMD1_FREQ_WM8510, (byte)CLOCKWM8510CMD.CMD_RFASK_CMD2_RESET_WM8510 };
            byte[] res = null;

            //---将命令写入设备
            _return = usedPort.SendCmdAndReadResponse(cmd, ref res, 200);

            //---通信验证
            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, "时钟设备复位成功!\r\n", Color.Black, false);
                }
            }
            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);
        }
Пример #2
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);
        }
Пример #3
0
        /// <summary>
        /// 设置设备的电流配置参数
        /// </summary>
        /// <param name="freqPointIndex"></param>
        /// <param name="deviceCurrent"></param>
        /// <param name="usedPort"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        protected virtual int FreqCurrentSetCurrentParm(int freqPointIndexCMD, FreqCurrentControl deviceCurrent, COMMPort usedPort, 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_CURRENT_SET,
                0x00, 0x00,
                0x00, 0x00,
                0x00, 0x00,
                0x00, 0x00,
                0x00, 0x00,
                0x00, 0x00,
                0x00, 0x00
            };

            //---参数设置---起始频率点的电流最大值
            _return = (int)(deviceCurrent.m_StartPassMax * 100);
            cmd[2]  = (byte)(_return >> 8);
            cmd[3]  = (byte)(_return);

            //---参数设置---起始频率点的电流最小值
            _return = (int)(deviceCurrent.m_StartPassMin * 100);
            cmd[4]  = (byte)(_return >> 8);
            cmd[5]  = (byte)(_return);

            //---参数设置---ADC采样结果比对的点的间隔数
            _return = (int)(deviceCurrent.m_PassSpacePointNum);
            cmd[6]  = (byte)(_return >> 8);
            cmd[7]  = (byte)(_return);

            //---参数设置---ADC采样结果差值的最大值
            _return = (int)(deviceCurrent.m_PassSpacePointMax);
            cmd[8]  = (byte)(_return >> 8);
            cmd[9]  = (byte)(_return);

            //---参数设置---ADC采样结果差值的最小值
            _return = (int)(deviceCurrent.m_PassSpacePointMin);
            cmd[10] = (byte)(_return >> 8);
            cmd[11] = (byte)(_return);

            //---参数设置---终止频率点的电流最大值
            _return = (int)(deviceCurrent.m_StopPassMax * 100);
            cmd[12] = (byte)(_return >> 8);
            cmd[13] = (byte)(_return);

            //---参数设置---终止频率点的电流最小值
            _return = (int)(deviceCurrent.m_StopPassMin * 100);
            cmd[14] = (byte)(_return >> 8);
            cmd[15] = (byte)(_return);

            //---返回的结果
            byte[] res = null;

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

            //---通信验证
            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);
                }
            }
            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);
        }
Пример #4
0
        /// <summary>
        /// 获取设备的电流配置参数
        /// </summary>
        /// <param name="freqPointIndex"></param>
        /// <param name="deviceCurrent"></param>
        /// <param name="usedPort"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        protected virtual int FreqCurrentGetCurrentParm(int freqPointIndexCMD, FreqCurrentControl deviceCurrent, COMMPort usedPort, 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_CURRENT_GET };
            byte[] res = null;

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

            //---通信验证
            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);
                }

                //---获取起始最大电流
                _return = res[usedPort.m_COMMPortDataReadIndex + 3];
                _return = (_return << 8) + res[usedPort.m_COMMPortDataReadIndex + 4];

                //---刷新起始最大电流
                deviceCurrent.m_StartPassMax = (float)(_return * 1.0 / 100);

                //---获取起始最小电流
                _return = res[usedPort.m_COMMPortDataReadIndex + 5];
                _return = (_return << 8) + res[usedPort.m_COMMPortDataReadIndex + 6];

                //---刷新起始最小电流
                deviceCurrent.m_StartPassMin = (float)(_return * 1.0 / 100);

                //---ADC间隔点数
                _return = res[usedPort.m_COMMPortDataReadIndex + 7];
                _return = (_return << 8) + res[usedPort.m_COMMPortDataReadIndex + 8];

                //---刷新ADC间隔点数
                deviceCurrent.m_PassSpacePointNum = _return;

                //---ADC合格的最大值
                _return = res[usedPort.m_COMMPortDataReadIndex + 9];
                _return = (_return << 8) + res[usedPort.m_COMMPortDataReadIndex + 10];

                //---刷新ADC合格的最大值
                deviceCurrent.m_PassSpacePointMax = _return;

                //---ADC合格的最小值
                _return = res[usedPort.m_COMMPortDataReadIndex + 11];
                _return = (_return << 8) + res[usedPort.m_COMMPortDataReadIndex + 12];

                //---刷新ADC合格的最小值
                deviceCurrent.m_PassSpacePointMin = _return;

                //---获取截止最大电流
                _return = res[usedPort.m_COMMPortDataReadIndex + 13];
                _return = (_return << 8) + res[usedPort.m_COMMPortDataReadIndex + 14];

                //---刷新截止最大电流
                deviceCurrent.m_StopPassMax = (float)(_return * 1.0 / 100);

                //---获取截止最小电流
                _return = res[usedPort.m_COMMPortDataReadIndex + 15];
                _return = (_return << 8) + res[usedPort.m_COMMPortDataReadIndex + 16];

                //---刷新截止最小电流
                deviceCurrent.m_StopPassMin = (float)(_return * 1.0 / 100);

                //---恢复返回值
                _return = 0;
            }
            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);
        }
Пример #5
0
        /// <summary>
        /// 设置设备的频率配置参数
        /// </summary>
        /// <param name="freqPointIndex"></param>
        /// <param name="deviceFreq"></param>
        /// <param name="usedPort"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        protected virtual int FreqCurrentSetFreqParm(int freqPointIndexCMD, FreqCurrentControl deviceFreq, COMMPort usedPort, RichTextBox msg = null)
        {
            if (usedPort == null)
            {
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "通信端口初始化失败!\r\n", Color.Red, false);
                }
                return(1);
            }
            if (deviceFreq == 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_FREQ_SET,
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00,
                0x00, 0x00
            };

            //---数据填充,起始射频频率
            _return = (int)(deviceFreq.m_StartFreq * 100);
            cmd[2]  = (byte)(_return >> 24);
            cmd[3]  = (byte)(_return >> 16);
            cmd[4]  = (byte)(_return >> 8);
            cmd[5]  = (byte)(_return);

            //---数据填充,步进射频频率
            _return = (int)(deviceFreq.m_StepFreq * 100);
            cmd[6]  = (byte)(_return >> 8);
            cmd[7]  = (byte)(_return);

            //---数据填充,步进射频频率
            _return = (int)(deviceFreq.m_StepPointNum);
            cmd[8]  = (byte)(_return >> 8);
            cmd[9]  = (byte)(_return);

            //---回传的命令
            byte[] res = null;

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

            //---通信验证
            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);
                }
            }
            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);
        }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        /// <param name="freq"></param>
        /// <returns></returns>
        protected virtual int PreFreqYSELSetFreq(int preFreqIndex, PreFreqControl freqControl, COMMPort usedPort, RichTextBox msg = null)
        {
            if (usedPort == null)
            {
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "通信端口初始化失败!\r\n", Color.Red, false);
                }
                return(1);
            }
            if (freqControl == null)
            {
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "预设频率点的控件传递错误!\r\n", Color.Red, false);
                }
                return(2);
            }
            int _return = 0;

            byte[] cmd   = new byte[] { CMD_RFASK_CMD1_YSEL_FREQ, 0, 0, 0, 0, 0 };
            int    freq1 = 0;
            int    freq2 = 0;
            int    freq3 = 0;
            int    freq4 = 0;
            string str   = "";

            switch (preFreqIndex)
            {
            case 1:
                freq1  = (int)(freqControl.m_PreFreqOne * 100);
                cmd[1] = (byte)CLOCKYSELCMD.CMD_RFASK_CMD2_YSEL1_FREQ_SET;
                cmd[2] = (byte)(freq1 >> 24);
                cmd[3] = (byte)(freq1 >> 16);
                cmd[4] = (byte)(freq1 >> 8);
                cmd[5] = (byte)(freq1);
                str    = "预设频率点1设置成功,频率是:" + freqControl.m_PreFreqOne.ToString() + "MHz" + "!\r\n";
                break;

            case 2:
                freq2  = (int)(freqControl.m_PreFreqTwo * 100);
                cmd[1] = (byte)CLOCKYSELCMD.CMD_RFASK_CMD2_YSEL2_FREQ_SET;
                cmd[2] = (byte)(freq2 >> 24);
                cmd[3] = (byte)(freq2 >> 16);
                cmd[4] = (byte)(freq2 >> 8);
                cmd[5] = (byte)(freq2);
                str    = "预设频率点2设置成功,频率是:" + freqControl.m_PreFreqTwo.ToString() + "MHz" + "!\r\n";
                break;

            case 3:
                freq3  = (int)(freqControl.m_PreFreqThree * 100);
                cmd[1] = (byte)CLOCKYSELCMD.CMD_RFASK_CMD2_YSEL3_FREQ_SET;
                cmd[2] = (byte)(freq3 >> 24);
                cmd[3] = (byte)(freq3 >> 16);
                cmd[4] = (byte)(freq3 >> 8);
                cmd[5] = (byte)(freq3);

                str = "预设频率点3设置成功,频率是:" + freqControl.m_PreFreqThree.ToString() + "MHz" + "!\r\n";
                break;

            case 4:
                freq4  = (int)(freqControl.m_PreFreqFour * 100);
                cmd[1] = (byte)CLOCKYSELCMD.CMD_RFASK_CMD2_YSEL4_FREQ_SET;
                cmd[2] = (byte)(freq4 >> 24);
                cmd[3] = (byte)(freq4 >> 16);
                cmd[4] = (byte)(freq4 >> 8);
                cmd[5] = (byte)(freq4);

                str = "预设频率点4设置成功,频率是:" + freqControl.m_PreFreqFour.ToString() + "MHz" + "!\r\n";
                break;

            case 5:
                freq1 = (int)(freqControl.m_PreFreqOne * 100);
                freq2 = (int)(freqControl.m_PreFreqTwo * 100);
                freq3 = (int)(freqControl.m_PreFreqThree * 100);
                freq4 = (int)(freqControl.m_PreFreqFour * 100);
                cmd   = new byte[] { CMD_RFASK_CMD1_YSEL_FREQ, (byte)CLOCKYSELCMD.CMD_RFASK_CMD2_YSEL_FREQ_SET, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

                cmd[2] = (byte)(freq1 >> 24);
                cmd[3] = (byte)(freq1 >> 16);
                cmd[4] = (byte)(freq1 >> 8);
                cmd[5] = (byte)(freq1);

                cmd[6] = (byte)(freq2 >> 24);
                cmd[7] = (byte)(freq2 >> 16);
                cmd[8] = (byte)(freq2 >> 8);
                cmd[9] = (byte)(freq2);

                cmd[10] = (byte)(freq3 >> 24);
                cmd[11] = (byte)(freq3 >> 16);
                cmd[12] = (byte)(freq3 >> 8);
                cmd[13] = (byte)(freq3);

                cmd[14] = (byte)(freq4 >> 24);
                cmd[15] = (byte)(freq4 >> 16);
                cmd[16] = (byte)(freq4 >> 8);
                cmd[17] = (byte)(freq4);

                str  = "预设频率点1设置成功,频率是:" + freqControl.m_PreFreqOne.ToString() + "MHz" + "!\r\n";
                str += "预设频率点2设置成功,频率是:" + freqControl.m_PreFreqTwo.ToString() + "MHz" + "!\r\n";
                str += "预设频率点3设置成功,频率是:" + freqControl.m_PreFreqThree.ToString() + "MHz" + "!\r\n";
                str += "预设频率点4设置成功,频率是:" + freqControl.m_PreFreqFour.ToString() + "MHz" + "!\r\n";
                break;

            case 6:
                cmd = new byte[] { CMD_RFASK_CMD1_YSEL_FREQ, (byte)CLOCKYSELCMD.CMD_RFASK_CMD2_YSEL1_FREQ_OUT };
                str = "预设频率点1设置输出,频率是:" + freqControl.m_PreFreqOne.ToString() + "MHz" + "!\r\n";
                break;

            case 7:
                cmd = new byte[] { CMD_RFASK_CMD1_YSEL_FREQ, (byte)CLOCKYSELCMD.CMD_RFASK_CMD2_YSEL2_FREQ_OUT };
                str = "预设频率点2设置输出,频率是:" + freqControl.m_PreFreqTwo.ToString() + "MHz" + "!\r\n";
                break;

            case 8:
                cmd = new byte[] { CMD_RFASK_CMD1_YSEL_FREQ, (byte)CLOCKYSELCMD.CMD_RFASK_CMD2_YSEL3_FREQ_OUT };
                str = "预设频率点3设置输出,频率是:" + freqControl.m_PreFreqThree.ToString() + "MHz" + "!\r\n";
                break;

            case 9:
                cmd = new byte[] { CMD_RFASK_CMD1_YSEL_FREQ, (byte)CLOCKYSELCMD.CMD_RFASK_CMD2_YSEL4_FREQ_OUT };
                str = "预设频率点4设置输出,频率是:" + freqControl.m_PreFreqFour.ToString() + "MHz" + "!\r\n";
                break;

            default:
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "预设频率点的信息传递错误!\r\n", Color.Red, false);
                }
                return(3);
            }
            byte[] res = null;

            //---将命令写入设备
            _return = usedPort.SendCmdAndReadResponse(cmd, ref res, 300);

            //---通信验证
            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, "预设频率设置成功!\r\n" + str, Color.Black, false);
                }
            }
            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);
        }
Пример #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        /// <param name="freq"></param>
        /// <returns></returns>
        protected virtual int PreFreqYSELGetFreq(int preFreqIndex, PreFreqControl freqControl, COMMPort usedPort, RichTextBox msg = null)
        {
            if (usedPort == null)
            {
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "通信端口初始化失败!\r\n", Color.Red, false);
                }
                return(1);
            }
            if (freqControl == null)
            {
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "预设频率点的控件传递错误!\r\n", Color.Red, false);
                }
                return(2);
            }
            int _return = 0;

            byte[] cmd   = new byte[] { CMD_RFASK_CMD1_YSEL_FREQ, 0, };
            float  freq1 = 0;
            float  freq2 = 0;
            float  freq3 = 0;
            float  freq4 = 0;
            string str   = "";

            switch (preFreqIndex)
            {
            case 1:
                cmd[1] = (byte)CLOCKYSELCMD.CMD_RFASK_CMD2_YSEL1_FREQ_GET;
                break;

            case 2:
                cmd[1] = (byte)CLOCKYSELCMD.CMD_RFASK_CMD2_YSEL2_FREQ_GET;
                break;

            case 3:
                cmd[1] = (byte)CLOCKYSELCMD.CMD_RFASK_CMD2_YSEL3_FREQ_GET;
                break;

            case 4:
                cmd[1] = (byte)CLOCKYSELCMD.CMD_RFASK_CMD2_YSEL4_FREQ_GET;
                break;

            case 5:
                cmd[1] = (byte)CLOCKYSELCMD.CMD_RFASK_CMD2_YSEL_FREQ_GET;
                break;

            default:
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "预设频率点的信息传递错误!\r\n", Color.Red, false);
                }
                return(3);
            }
            byte[] res = null;

            //---将命令写入设备
            _return = usedPort.SendCmdAndReadResponse(cmd, ref res, 300);

            //---通信验证
            if ((_return == 0) && (usedPort.m_COMMPortDataFormatPassed == true) && (res[usedPort.m_COMMPortDataReadIndex + 1] == 0) && (res[usedPort.m_COMMPortDataReadIndex + 2] == cmd[1]))
            {
                switch (preFreqIndex)
                {
                case 1:
                    freq1 = res[usedPort.m_COMMPortDataReadIndex + 3];
                    freq1 = ((int)freq1 << 8) + res[usedPort.m_COMMPortDataReadIndex + 4];
                    freq1 = ((int)freq1 << 8) + res[usedPort.m_COMMPortDataReadIndex + 5];
                    freq1 = ((int)freq1 << 8) + res[usedPort.m_COMMPortDataReadIndex + 6];
                    freqControl.m_PreFreqOne = (float)(freq1 / 100.00);
                    str = "预设频率点1读取成功,频率是:" + freqControl.m_PreFreqOne.ToString("0.00") + "MHz" + "!\r\n";
                    break;

                case 2:
                    freq2 = res[usedPort.m_COMMPortDataReadIndex + 3];
                    freq2 = ((int)freq2 << 8) + res[usedPort.m_COMMPortDataReadIndex + 4];
                    freq2 = ((int)freq2 << 8) + res[usedPort.m_COMMPortDataReadIndex + 5];
                    freq2 = ((int)freq2 << 8) + res[usedPort.m_COMMPortDataReadIndex + 6];
                    freqControl.m_PreFreqTwo = (float)(freq2 / 100.00);
                    str = "预设频率点2读取成功,频率是:" + freqControl.m_PreFreqTwo.ToString("0.00") + "MHz" + "!\r\n";
                    break;

                case 3:
                    freq3 = res[usedPort.m_COMMPortDataReadIndex + 3];
                    freq3 = ((int)freq3 << 8) + res[usedPort.m_COMMPortDataReadIndex + 4];
                    freq3 = ((int)freq3 << 8) + res[usedPort.m_COMMPortDataReadIndex + 5];
                    freq3 = ((int)freq3 << 8) + res[usedPort.m_COMMPortDataReadIndex + 6];
                    freqControl.m_PreFreqThree = (float)(freq3 / 100.00);
                    str = "预设频率点3读取成功,频率是:" + freqControl.m_PreFreqThree.ToString("0.00") + "MHz" + "!\r\n";
                    break;

                case 4:
                    freq4 = res[usedPort.m_COMMPortDataReadIndex + 3];
                    freq4 = ((int)freq4 << 8) + res[usedPort.m_COMMPortDataReadIndex + 4];
                    freq4 = ((int)freq4 << 8) + res[usedPort.m_COMMPortDataReadIndex + 5];
                    freq4 = ((int)freq4 << 8) + res[usedPort.m_COMMPortDataReadIndex + 6];
                    freqControl.m_PreFreqFour = (float)(freq4 / 100.00);
                    str = "预设频率点4读取成功,频率是:" + freqControl.m_PreFreqFour.ToString("0.00") + "MHz" + "!\r\n";
                    break;

                case 5:
                    freq1 = res[usedPort.m_COMMPortDataReadIndex + 3];
                    freq1 = ((int)freq1 << 8) + res[usedPort.m_COMMPortDataReadIndex + 4];
                    freq1 = ((int)freq1 << 8) + res[usedPort.m_COMMPortDataReadIndex + 5];
                    freq1 = ((int)freq1 << 8) + res[usedPort.m_COMMPortDataReadIndex + 6];
                    freqControl.m_PreFreqOne = (float)(freq1 / 100.00);
                    str = "预设频率点1读取成功,频率是:" + freqControl.m_PreFreqOne.ToString("0.00") + "MHz" + "!\r\n";

                    freq2 = res[usedPort.m_COMMPortDataReadIndex + 7];
                    freq2 = ((int)freq2 << 8) + res[usedPort.m_COMMPortDataReadIndex + 8];
                    freq2 = ((int)freq2 << 8) + res[usedPort.m_COMMPortDataReadIndex + 9];
                    freq2 = ((int)freq2 << 8) + res[usedPort.m_COMMPortDataReadIndex + 10];

                    freqControl.m_PreFreqTwo = (float)(freq2 / 100.00);
                    str += "预设频率点2读取成功,频率是:" + freqControl.m_PreFreqTwo.ToString("0.00") + "MHz" + "!\r\n";

                    freq3 = res[usedPort.m_COMMPortDataReadIndex + 11];
                    freq3 = ((int)freq3 << 8) + res[usedPort.m_COMMPortDataReadIndex + 12];
                    freq3 = ((int)freq3 << 8) + res[usedPort.m_COMMPortDataReadIndex + 13];
                    freq3 = ((int)freq3 << 8) + res[usedPort.m_COMMPortDataReadIndex + 14];
                    freqControl.m_PreFreqThree = (float)(freq3 / 100.00);
                    str += "预设频率点3读取成功,频率是:" + freqControl.m_PreFreqThree.ToString("0.00") + "MHz" + "!\r\n";

                    freq4 = res[usedPort.m_COMMPortDataReadIndex + 15];
                    freq4 = ((int)freq4 << 8) + res[usedPort.m_COMMPortDataReadIndex + 16];
                    freq4 = ((int)freq4 << 8) + res[usedPort.m_COMMPortDataReadIndex + 17];
                    freq4 = ((int)freq4 << 8) + res[usedPort.m_COMMPortDataReadIndex + 18];
                    freqControl.m_PreFreqFour = (float)(freq4 / 100.00);
                    str += "预设频率点4读取成功,频率是:" + freqControl.m_PreFreqFour.ToString("0.00") + "MHz" + "!\r\n";
                    break;

                default:
                    return(4);
                }
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "预设频率读取成功!\r\n" + str, Color.Black, false);
                }
            }
            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);
        }
Пример #8
0
        /// <summary>
        /// 时钟输出通道
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="isOpen"></param>
        /// <param name="usedPort"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public virtual int ClockWM8510SetChannel(int channel, bool isOpen, COMMPort usedPort, RichTextBox msg = null)
        {
            if (usedPort == null)
            {
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "通信端口初始化失败!\r\n", Color.Red, false);
                }
                return(1);
            }
            int    _return = 0;
            string str     = null;

            byte[] cmd = new byte[] { CMD_RFASK_CMD1_FREQ_WM8510, 0x00, 0x00 };
            switch (channel)
            {
            case 1:
                cmd[1] = (byte)CLOCKWM8510CMD.CMD_RFASK_CMD2_CHANNELA_WM8510;
                str    = "时钟频率A通道输出";
                break;

            case 2:
                cmd[1] = (byte)CLOCKWM8510CMD.CMD_RFASK_CMD2_CHANNELB_WM8510;
                str    = "时钟频率B通道输出";
                break;

            case 3:
                cmd[1] = (byte)CLOCKWM8510CMD.CMD_RFASK_CMD2_CHANNELC_WM8510;
                str    = "时钟频率C通道输出";
                break;

            case 4:
                cmd[1] = (byte)CLOCKWM8510CMD.CMD_RFASK_CMD2_CHANNELD_WM8510;
                str    = "时钟频率D通道输出";
                break;

            case 5:
                cmd[1] = (byte)CLOCKWM8510CMD.CMD_RFASK_CMD2_CHANNELS_WM8510;
                str    = "时钟频率全通道输出";
                break;

            default:
                return(2);
            }
            if (isOpen == true)
            {
                cmd[2] = 0x01;
            }
            byte[] res = null;

            //---将命令写入设备
            _return = usedPort.SendCmdAndReadResponse(cmd, ref res, 200);

            //---通信验证
            if ((_return == 0) && (usedPort.m_COMMPortDataFormatPassed == true) && (res[usedPort.m_COMMPortDataReadIndex + 1] == 0) && (res[usedPort.m_COMMPortDataReadIndex + 2] == cmd[1]))
            {
                if (isOpen == true)
                {
                    str += "打开!\r\n";
                }
                else
                {
                    str += "关闭!\r\n";
                }
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, str, Color.Black, false);
                }
            }
            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);
        }
Пример #9
0
        /// <summary>
        /// 读取WM8510输出频率
        /// </summary>
        /// <param name="freq"></param>
        /// <param name="usedPort"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        protected virtual int ClockWM8510GetFreq(float freq, COMMPort usedPort, RichTextBox msg = null)
        {
            if (usedPort == null)
            {
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "通信端口初始化失败!\r\n", Color.Red, false);
                }
                return(1);
            }
            int _return = 0;
            int getFreq = 0;

            byte[] cmd = new byte[] { CMD_RFASK_CMD1_FREQ_WM8510, (byte)CLOCKWM8510CMD.CMD_RFASK_CMD2_GET_WM8510 };
            byte[] res = null;

            //---将命令写入设备
            _return = usedPort.SendCmdAndReadResponse(cmd, ref res, 200);

            //---通信验证
            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, "时钟频率读取成功!\r\n", Color.Black, false);
                }
                getFreq = res[usedPort.m_COMMPortDataReadIndex + 3];
                getFreq = (getFreq << 8) + res[usedPort.m_COMMPortDataReadIndex + 4];
                getFreq = (getFreq << 8) + res[usedPort.m_COMMPortDataReadIndex + 5];
                getFreq = (getFreq << 8) + res[usedPort.m_COMMPortDataReadIndex + 6];

                //---时钟频率的校验
                if (getFreq < freq)
                {
                    if ((freq - getFreq) < 5000)
                    {
                        if (msg != null)
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "时钟频率验证成功!\r\n", Color.Black, false);
                        }
                    }
                    else
                    {
                        if (msg != null)
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "时钟频率验证失败!\t读取频率是:" + getFreq.ToString() + "Hz\r\n", Color.Red, false);
                        }
                    }
                }
                else
                {
                    if ((getFreq - freq) < 5000)
                    {
                        if (msg != null)
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "时钟频率验证成功!\r\n", Color.Black, false);
                        }
                    }
                    else
                    {
                        if (msg != null)
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "时钟频率验证失败!\t读取频率是:" + getFreq.ToString() + "Hz\r\n", Color.Red, false);
                        }
                    }
                }
            }
            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);
        }
Пример #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="deviceType"></param>
        /// <returns></returns>
        protected virtual int DeviceTypeSetDevice(DeviceTypeControl deviceType, COMMPort usedPort, RichTextBox msg = null)
        {
            if (usedPort == null)
            {
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "通信端口初始化失败!\r\n", Color.Red, false);
                }
                return(1);
            }
            if (deviceType == null)
            {
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "设备类型控件传递错误!\r\n", Color.Red, false);
                }
                return(2);
            }
            int _return = 0;

            byte[] cmd = new byte[] { CMD_RFASK_CMD1_FREQ_CURRENT, (byte)RFASKFreqCurrentCMD.CMD_RFASK_CMD1_FREQ_CURRENT_DEVICE_SET, 0x00, 0x00, 0x00, 0x00, 0x00 };
            cmd[2] = (byte)deviceType.GetDeviceType(deviceType.m_DeviceType);
            if (cmd[2] == 0)
            {
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "设备类型无法识别!\r\n", Color.Red, false);
                }
                return(2);
            }
            float temp = deviceType.m_SampleRes;

            _return = (int)(temp * 100);
            cmd[3]  = (byte)(_return >> 8);
            cmd[4]  = (byte)(_return);
            temp    = deviceType.m_AmpTimes;
            _return = (int)(temp * 1);
            cmd[5]  = (byte)(_return >> 8);
            cmd[6]  = (byte)(_return);
            byte[] res = null;

            //---将命令写入设备
            _return = usedPort.SendCmdAndReadResponse(cmd, ref res, 300);

            //---通信验证
            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, "设备类型参数设置成功!\r\n", Color.Black, false);
                }
            }
            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);
        }
Пример #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="deviceType"></param>
        /// <returns></returns>
        protected virtual int DeviceTypeGetDevice(DeviceTypeControl deviceType, COMMPort usedPort, RichTextBox msg = null)
        {
            if (usedPort == null)
            {
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "通信端口初始化失败!\r\n", Color.Red, false);
                }
                return(1);
            }
            if (deviceType == null)
            {
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "设备类型控件传递错误!\r\n", Color.Red, false);
                }
                return(2);
            }
            int _return = 0;

            byte[] cmd = new byte[] { CMD_RFASK_CMD1_FREQ_CURRENT, (byte)RFASKFreqCurrentCMD.CMD_RFASK_CMD1_FREQ_CURRENT_DEVICE_GET };
            byte[] res = null;

            //---将命令写入设备
            _return = usedPort.SendCmdAndReadResponse(cmd, ref res, 300);

            //---通信验证
            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, "设备类型参数获取成功!\r\n", Color.Black, false);
                }

                //---设置设备的类型
                if (deviceType.SetDeviceType(res[usedPort.m_COMMPortDataReadIndex + 3]) == false)
                {
                    if (msg != null)
                    {
                        RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "设备类型不能识别!\r\n", Color.Black, false);
                    }
                    return(3);
                }
                _return = res[usedPort.m_COMMPortDataReadIndex + 4];
                _return = (_return << 8) + res[usedPort.m_COMMPortDataReadIndex + 5];

                //---设置采样电阻的大小
                deviceType.m_SampleRes = (float)(_return * 1.0 / 100);
                _return = res[usedPort.m_COMMPortDataReadIndex + 6];
                _return = (_return << 8) + res[usedPort.m_COMMPortDataReadIndex + 7];

                //---获取放大倍数
                deviceType.m_AmpTimes = (float)(_return * 1.0);
                _return = 0;
            }
            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);
        }