Beispiel #1
0
        /// <summary>
        /// 获取有关时钟芯片WM8510的设置
        /// </summary>
        /// <param name="freq"></param>
        /// <param name="index"></param>
        /// <param name="usedPort"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public virtual int ClockWM8510Set(int freq, int index, COMMPort usedPort, RichTextBox msg = null)
        {
            int _return = 0;

            switch (index)
            {
            case 1:
                _return = this.ClockWM8510SetFreq(freq, usedPort, msg);
                break;

            case 2:
                _return = this.ClockWM8510GetFreq(freq, usedPort, msg);
                break;

            case 3:
                _return = this.ClockWM8510Reset(usedPort, msg);
                break;

            default:
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "WM8510的设置操作不合法!\r\n", Color.Red, false);
                }
                _return = 1;
                break;
            }
            return(_return);
        }
Beispiel #2
0
        /// <summary>
        /// 设置通信端口的参数
        /// </summary>
        private void SetCOMMSerialPortParam()
        {
            if ((this.m_COMMComboBox.Text != null) && (this.m_COMMComboBox.Items.Count > 0))
            {
                COMMSerialPortParamForm p = new COMMSerialPortParamForm(this.m_COMMComboBox.Text, this.m_COMMSerialPortParam);

                if (p.ShowDialog(this.m_COMMComboBox) != System.Windows.Forms.DialogResult.OK)
                {
                    if (this.m_COMMRichTextBox != null)
                    {
                        RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.m_COMMRichTextBox, "通信端口参数配置失败。\r\n", Color.Red, false);
                    }
                }
                else
                {
                    this.m_COMMSerialPortParam = ((COMMSerialPortParamForm)p).m_COMMSerialPortParam;

                    if (this.m_COMMRichTextBox != null)
                    {
                        RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.m_COMMRichTextBox, "通信端口参数配置成功。\r\n", Color.Black, false);
                    }

                    p.CloseForm();
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 设置参数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void COMMSerialPortParam_Click(object sender, EventArgs e)
        {
            if ((this.m_COMMComboBox.Text != null) && (this.m_COMMComboBox.Items.Count > 0))
            {
                COMMSerialPortParamForm p = new COMMSerialPortParamForm(this.m_COMMComboBox.Text);

                if (p.ShowDialog(this.m_COMMComboBox) != System.Windows.Forms.DialogResult.OK)
                {
                    if (this.m_COMMRichTextBox != null)
                    {
                        RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.m_COMMRichTextBox, "通信端口参数配置失败。\r\n", Color.Red, false);
                    }
                    return;
                }

                this.m_COMMSerialPortParam = ((COMMSerialPortParamForm)p).m_COMMSerialPortParam;

                if (this.m_COMMRichTextBox != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.m_COMMRichTextBox, "通信端口参数配置成功。\r\n", Color.Black, false);
                }

                p.CloseForm();
            }
        }
Beispiel #4
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);
        }
        /// <summary>
        /// 设备类型的设置和获取
        /// </summary>
        /// <param name="index"></param>
        /// <param name="deviceType"></param>
        /// <param name="usedPort"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public virtual int DeviceTypeSet(int index, DeviceTypeControl deviceType, COMMPort usedPort, RichTextBox msg = null)
        {
            int _return = 0;

            switch (index)
            {
            case 1:
                _return = this.DeviceTypeGetDevice(deviceType, usedPort, msg);
                break;

            case 2:
                _return = this.DeviceTypeSetDevice(deviceType, usedPort, msg);
                break;

            default:
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "预设频率点操作不合法!\r\n", Color.Red, false);
                }
                _return = 1;
                break;
            }
            return(_return);
        }
Beispiel #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        /// <param name="freq"></param>
        /// <returns></returns>
        public virtual int PreFreqYSELSet(int index, int preFreqIndex, PreFreqControl freqControl, COMMPort usedPort, RichTextBox msg = null)
        {
            int _return = 0;

            switch (index)
            {
            case 1:
                _return = this.PreFreqYSELGetFreq(preFreqIndex, freqControl, usedPort, msg);
                break;

            case 2:
                _return = this.PreFreqYSELSetFreq(preFreqIndex, freqControl, usedPort, msg);
                break;

            default:
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "预设频率点操作不合法!\r\n", Color.Red, false);
                }
                _return = 1;
                break;
            }
            return(_return);
        }
Beispiel #7
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);
        }
Beispiel #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        /// <param name="freqPointIndex"></param>
        /// <param name="deviceFreqCurrent"></param>
        /// <param name="usedPort"></param>
        /// <param name="usedChart"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public virtual int FreqCurrentSet(int index, int freqPointIndex, FreqCurrentControl deviceFreqCurrent, COMMPort usedPort, MyChart usedChart, RichTextBox msg = null)
        {
            int _return = 0;
            int cmd     = 0;

            //---第几个扫描任务的解析
            switch (freqPointIndex)
            {
            case 1:
                cmd = CMD_RFASK_CMD1_FREQ_CURRENT_POINT_ONE;
                break;

            case 2:
                cmd = CMD_RFASK_CMD1_FREQ_CURRENT_POINT_TWO;
                break;

            default:
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "频率电流扫描任务命令不合法!\r\n", Color.Red, false);
                }
                return(1);
            }

            //---频率电流扫描执行的操作
            switch (index)
            {
            case 1:

                //---获取频率参数
                _return = this.FreqCurrentGetFreqParm(cmd, deviceFreqCurrent, usedPort, msg);
                break;

            case 2:

                //---配置频率参数
                _return = this.FreqCurrentSetFreqParm(cmd, deviceFreqCurrent, usedPort, msg);
                break;

            case 3:

                //---获取电流参数
                _return = this.FreqCurrentGetCurrentParm(cmd, deviceFreqCurrent, usedPort, msg);
                break;

            case 4:

                //---设置电流参数
                _return = this.FreqCurrentSetCurrentParm(cmd, deviceFreqCurrent, usedPort, msg);
                break;

            case 5:

                //---执行频率电流扫描
                _return = this.FreqCurrentDo(cmd, deviceFreqCurrent, usedPort, usedChart, msg);
                break;

            default:
                if (msg != null)
                {
                    RichTextBoxPlus.AppendTextInfoTopWithDataTime(msg, "频率电流扫描操作不合法!\r\n", Color.Red, false);
                }
                _return = 1;
                break;
            }
            return(_return);
        }
Beispiel #9
0
        /// <summary>
        /// 点击按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public virtual void button_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            btn.Enabled = false;
            switch (btn.Name)
            {
            case "button_initDevice":
                if (btn.Text == "打开端口")
                {
                    if (this.usedPort.OpenDevice(this.comboBox_portName.Text, this.usedMsg) == 0)
                    {
                        this.pictureBox_portState.Tag = 1;
                        btn.Text = "关闭端口";
                        this.pictureBox_portState.Image = Properties.Resources.open;

                        //---控件不使能
                        this.ComboBoxPortInit(false);

                        //---消息显示
                        if (this.usedMsg != null)
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.usedMsg, "端口" + this.comboBox_portName.Text + "打开成功!\r\n", Color.Black, false);
                        }
                    }
                    else
                    {
                        this.pictureBox_portState.Tag   = 2;
                        this.pictureBox_portState.Image = Properties.Resources.error;
                        if (this.usedMsg != null)
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.usedMsg, "端口" + this.comboBox_portName.Text + "端口打开失败!\r\n", Color.Red, false);
                        }
                    }
                }
                else if (btn.Text == "关闭端口")
                {
                    if (this.usedPort != null)
                    {
                        this.pictureBox_portState.Tag = 3;
                        this.usedPort.CloseDevice();
                        btn.Text = "打开端口";
                        this.pictureBox_portState.Image = Properties.Resources.lost;

                        //---控件不使能
                        this.ComboBoxPortInit(true);

                        //---消息显示
                        if (this.usedMsg != null)
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.usedMsg, "端口" + this.comboBox_portName.Text + "关闭成功!\r\n", Color.Black, false);
                        }
                    }
                }
                else
                {
                    if (this.usedForm != null)
                    {
                        MessageBoxPlus.Show(this.usedForm, "端口操作异常!错误操作:" + btn.Text, "错误提示");
                    }
                    else
                    {
                        MessageBox.Show("端口操作异常!错误操作:" + btn.Text, "错误提示");
                    }
                }
                break;

            default:
                break;
            }
            btn.Enabled = true;
        }
Beispiel #10
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);
        }
Beispiel #11
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);
        }
        /// <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);
        }
Beispiel #13
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);
        }
Beispiel #14
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);
        }
Beispiel #15
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);
        }
        /// <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);
        }
Beispiel #17
0
        //========================================================
        #region  钮事件

        /// <summary>
        /// 按钮点击事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_Click(object sender, EventArgs e)
        {
            string str = sender.ToString();

            if (str == "清除")
            {
                this.richTextBox_msg.Clear();
            }
            else
            {
                if (this.usedBootLoader == null)
                {
                    MessageBoxPlus.Show(this, "应用发生配置错误,请重新启动!", "错误提示!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                Button btn = (Button)sender;
                btn.Enabled = false;
                DialogResult dgTemp;
                int          _return = 0;
                //---检查那个按钮使用
                switch (btn.Name)
                {
                case "button_openPort":
                    _return = this.usedBootLoader.OpenDevice(this.comboBox_portName.Text, this.richTextBox_msg);
                    if (_return == 0)
                    {
                        this.button_closePort.Enabled  = true;
                        this.panel_update.Enabled      = true;
                        this.comboBox_portName.Enabled = false;
                        return;
                    }
                    break;

                case "button_closePort":
                    _return = this.usedBootLoader.CloseDevice(this.comboBox_portName.Text, this.richTextBox_msg);
                    if (_return == 0)
                    {
                        this.button_openPort.Enabled   = true;
                        this.panel_update.Enabled      = false;
                        this.comboBox_portName.Enabled = true;
                        return;
                    }
                    break;

                case "button_openFirmware":
                    //---重新初始化打开文件
                    openFirmwareFile = new OpenFileDialog();
                    //---过滤文件
                    openFirmwareFile.AddExtension = true;
                    openFirmwareFile.DefaultExt   = "hex";
                    openFirmwareFile.Filter       = " hex files(*.hex)|*.hex";
                    openFirmwareFile.FilterIndex  = 0;

                    //---获取文件打开的状态
                    dgTemp = openFirmwareFile.ShowDialog();

                    //---判断是否选择固件
                    if (dgTemp == DialogResult.OK)
                    {
                        this.textBox_firmware.Text = openFirmwareFile.FileName;
                        RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.richTextBox_msg, "固件打开成功! \r\n", Color.Black, false);
                    }
                    else if (dgTemp == DialogResult.Cancel)
                    {
                        this.textBox_firmware.Text = string.Empty;
                        RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.richTextBox_msg, "取消固件打开! \r\n", Color.Black, false);
                    }
                    else
                    {
                        this.textBox_firmware.Text = string.Empty;
                        RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.richTextBox_msg, "固件打开失败!\r\n", Color.Red, false);
                    }
                    break;

                case "button_updateFirmware":
                    if ((this.textBox_firmware.Text == null) || (this.textBox_firmware.Text == string.Empty) || (this.openFirmwareFile.SafeFileNames.Length == 0))
                    {
                        //---弹出警告框
                        MessageBoxPlus.Show(this, "固件文件错误,请重新选择!", "错误提示!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        //---弹出警告框
                        if (DialogResult.OK == MessageBoxPlus.Show(this, "???是否确定更新固件!", "更新提示!", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.richTextBox_msg, "取消更新固件!\r\n", Color.Red, false);
                        }
                        else
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.richTextBox_msg, "准备更新固件!\r\n", Color.Red, false);
                        }
                    }
                    break;

                default:
                    break;
                }
                btn.Enabled = true;
            }
        }
Beispiel #18
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);
        }
Beispiel #19
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);
        }
Beispiel #20
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);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public virtual void Button_Click(object sender, System.EventArgs e)
        {
            Button btn = (Button)sender;

            btn.Enabled = false;
            switch (btn.Name)
            {
            case "button_COMMInit":
                if (btn.Text == "打开设备")
                {
                    //if ((this.commPort != null) &&(this.commPort.OpenDevice(this.comboBox_COMMName.Text, this.commRichTextBox) == 0))
                    if ((this.commPort != null) && (this.commPort.OpenDevice(this.m_COMMSerialPortParam, this.commRichTextBox) == 0))
                    {
                        btn.Text = "关闭设备";
                        this.pictureBox_COMMState.Image = Properties.Resources.open;

                        //---消息显示
                        if (this.commRichTextBox != null)
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.commRichTextBox, "设备打开成功!\r\n",
                                                                          Color.Black, false);
                        }

                        this.COMMControl(false);

                        //---加载设备移除处理
                        if (this.commPort.m_OnRemoveDeviceEvent == null)
                        {
                            this.commPort.m_OnRemoveDeviceEvent = this.AddWatcherPortRemove;
                        }
                    }
                    else
                    {
                        this.pictureBox_COMMState.Image = Properties.Resources.error;
                        if (this.commRichTextBox != null)
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.commRichTextBox, "设备打开失败!\r\n",
                                                                          Color.Red, false);
                        }
                    }
                }
                else if (btn.Text == "关闭设备")
                {
                    if (this.commPort != null)
                    {
                        this.commPort.CloseDevice();
                        btn.Text = "打开设备";
                        this.pictureBox_COMMState.Image = Properties.Resources.lost;

                        //---消息显示
                        if (this.commRichTextBox != null)
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.commRichTextBox, "设备关闭成功!\r\n",
                                                                          Color.Black, false);
                        }

                        this.COMMControl(true);
                    }
                }
                else if (btn.Text == "配置设备")
                {
                    //---更新设备配置参数
                }
                else
                {
                    MessageBoxPlus.Show(this.commForm, "设备操作异常!错误操作:" + btn.Text, "错误提示");
                }
                break;

            default:
                break;
            }
            btn.Enabled = true;
        }