Example #1
0
        /// <summary>
        /// 开始监听该串口
        /// </summary>
        public void start()
        {
            if (!comm.IsOpen)
            {
                try
                {
                    comm.Open();
                    //startReading();
                    //使用消息触发事件
                    comm.DataReceived += new SerialDataReceivedEventHandler(comm_DataReceived);
                    Console.WriteLine(comm.PortName + "正在监听中");
                }
                catch (Exception)
                {
                    throw;
                }

                //向主线程发送消息
                if (serverStartEvent != null)
                {
                    ComEventArgs e = new ComEventArgs();
                    e.PortName = comm.PortName;
                    this.serverStartEvent(this, e);
                }
            }
            else
                MessageBox.Show("打开串口失败");
        }
Example #2
0
 //下面是串口消息的处理函数
 //监听某个串口成功
 private void comServer_serverStartEvent(object sender, ComEventArgs e)
 {
     MessageBox.Show( e.PortName+"正在监听中...");
 }