//======================================================================
        //函数名称:rdo_uart_CheckedChanged
        //函数返回:无
        //参数说明:无
        //功能概要:点击“串口更新”单选按钮,显示串口更新页面并使用串口方式连接终端
        //======================================================================
        private void rdo_uart_CheckedChanged(object sender, EventArgs e)
        {
            //(1)变量申明
            string com;

            //(2)若串口更新未选中,直接退出
            if (this.rdo_uart.Checked == false)
            {
                return;
            }

            //(3)串口更新页面显现
            this.pnl_uart.Visible     = true;
            fmain.lbl_mainstatus.Text = "运行状态:选择串口更新";
            //(4)寻找并连接终端
            if (uart != null && uart.IsOpen)
            {
                uart.close();
            }
            pcNode = new PCNode();//pc节点初始化
            com    = pcNode.findPCNode();
            uart   = pcNode.PCNode_Uart;
            this.lbl_uartstate.Text = com;
            //(5)绑定DataReceived事件(即串口接收中断处理函数)
            if (uart != null)
            {
                //(5.1)连接串口成功
                uartPort = uart.port;
                uartPort.DataReceived -= new System.IO.Ports.SerialDataReceivedEventHandler(this.uartPort_recvData); //先移除委托函数,防止多次触发
                uartPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.uartPort_recvData);
                uart.setReceInt(500);                                                                                //相当于关闭串口中断

                this.btn_autoUpdate.Enabled = true;                                                                  //允许串口更新操作
                //修改主页面提示信息
                this.lbl_uartstate.Text     = "成功连接" + com;
                fmain.lbl_mainstatus.Text   = "运行状态:找到" + com;
                fmain.lbl_protocal.Text     = "协议:串口";
                fmain.lbl_protocalinfo.Text = "协议信息:端口" + com + ",波特率115200";
            }
            else
            {
                //(5.2)连接串口失败
                this.btn_autoUpdate.Enabled = false;  //禁止串口更新操作
                //修改主页面提示信息
                fmain.lbl_mainstatus.Text   = "运行状态:未成功连接终端," + com;
                fmain.lbl_protocal.Text     = "协议:";
                fmain.lbl_protocalinfo.Text = "协议信息:";
            }
        }
        //======================================================================
        //函数名称:btn_uartCheck_Click
        //函数返回:无
        //参数说明:无
        //功能概要:“重新连接”按钮点击事件,重新连接终端
        //======================================================================
        private void btn_uartCheck_Click(object sender, EventArgs e)
        {
            //(1)变量申明
            string com;

            //(2)提示重新连接串口
            fmain.lbl_mainstatus.Text = "运行状态:单击“重新连接”按钮...";
            //(3)重新遍历串口,寻找终端
            if (uart != null && uart.IsOpen)
            {
                uart.close();
            }
            pcNode = new PCNode();//pc节点初始化
            com    = pcNode.findPCNode();
            uart   = pcNode.PCNode_Uart;
            this.lbl_uartstate.Text = com;
            //(4)绑定DataReceived事件(即串口接收中断处理函数)
            if (uart != null)
            {
                //(4.1)连接串口成功
                uartPort = uart.port;
                uartPort.DataReceived -= new System.IO.Ports.SerialDataReceivedEventHandler(this.uartPort_recvData); //先移除委托函数,防止多次触发
                uartPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.uartPort_recvData);
                uart.setReceInt(500);                                                                                //相当于关闭串口中断

                this.btn_autoUpdate.Enabled = true;                                                                  //允许串口更新操作
                //修改主页面提示信息
                this.lbl_uartstate.Text     = "成功连接" + com;
                fmain.lbl_mainstatus.Text   = "运行状态:找到" + com;
                fmain.lbl_protocal.Text     = "协议:串口";
                fmain.lbl_protocalinfo.Text = "协议信息:端口" + com + ",波特率115200";
            }
            else
            {
                //(4.2)连接串口失败
                this.btn_autoUpdate.Enabled = false;  //禁止串口更新操作
                //修改主页面提示信息
                fmain.lbl_mainstatus.Text   = "运行状态:未成功找到串口," + com;
                fmain.lbl_protocal.Text     = "协议:";
                fmain.lbl_protocalinfo.Text = "协议信息:";
            }
        }
Esempio n. 3
0
        private Update update;  //更新变量

        //======================================================================
        //函数名称:frm_uart
        //函数返回:frm_uart窗体构造函数
        //参数说明:无
        //功能概要:完成frm_uart窗体的初始化工作
        //======================================================================
        public frm_uart()
        {
            InitializeComponent();

            pcNode = new PCNode();  //pc节点初始化
        }