public static void openStaticSerialPort()
 {
     if (!StaticSerialPort.getStaticSerialPort().IsOpen)
     {
         StaticSerialPort.getStaticSerialPort().Open();
     }
 }
 //关闭串口的时候必须考虑死锁问题
 public static void closeStaticSerialPort()
 {
     if (StaticSerialPort.getStaticSerialPort().IsOpen)
     {
         StaticSerialPort.getStaticSerialPort().Close();
     }
 }
Example #3
0
 public void StartRunning()
 {
     StaticSerialPort.AddParser(this.Parse);
     //this.refreshTimer.Elapsed += new ElapsedEventHandler(refreshTimer_Elapsed);
     //this.refreshTimer.Start();
     StaticSerialPort.openStaticSerialPort();
 }
Example #4
0
 public void StopRunning()
 {
     //this.refreshTimer.Elapsed -= refreshTimer_Elapsed;
     //this.refreshTimer.Stop();
     StaticSerialPort.removeParser(this.Parse);
     this.tagsInfo.Rows.Clear();
 }
 public static SerialPort getStaticSerialPort()
 {
     if (StaticSerialPort.comport == null)
     {
         StaticSerialPort.comport = new SerialPort();
         comport.DataReceived    += StaticSerialPort.port_DataReceived;
         StaticSerialPort.resetStaticSerialPort();//使用统一配置参数
     }
     return(StaticSerialPort.comport);
 }
 private void btnSaveConfig_Click(object sender, EventArgs e)
 {
     ConfigManager.SaveSerialPortConfigurnation(cmbPortName.Text,
                                                cmbBaudRate.Text,
                                                cmbParity.Text,
                                                cmbDataBits.Text,
                                                cmbStopBits.Text);
     StaticSerialPort.resetStaticSerialPort();
     this.Close();
 }
Example #7
0
        private void btnSaveConfig_Click(object sender, EventArgs e)
        {
            //ConfigManager.SaveSerialPortConfigurnation(cmbPortName.Text,
            //                                 cmbBaudRate.Text,
            //                                 cmbParity.Text,
            //                                 cmbDataBits.Text,
            //                                 cmbStopBits.Text);


            serialPortConfig config = new serialPortConfig("default", cmbPortName.Text,
                                                           cmbBaudRate.Text,
                                                           cmbParity.Text,
                                                           cmbDataBits.Text,
                                                           cmbStopBits.Text);

            serialPortConfig.saveConfig(config);
            //MessageBox.Show("保存完成!", "串口设置");
            StaticSerialPort.resetStaticSerialPort();
            this.Close();
        }
        /// <summary>
        /// 串口关闭时可能引起线程死锁,因此这里要求首先安全关闭串口
        /// </summary>
        /// <param name="portName"></param>
        /// <param name="baudRate"></param>
        /// <param name="parity"></param>
        /// <param name="dataBits"></param>
        /// <param name="stopBits"></param>
        public static void resetStaticSerialPort(string portName, string baudRate, string parity, string dataBits, string stopBits)
        {
            SerialPort sp         = StaticSerialPort.getStaticSerialPort();
            bool       biniOpened = sp.IsOpen;

            if (biniOpened)
            {
                //sp.Close();
                MessageBox.Show("请先关闭串口!");
                return;
            }
            try
            {
                sp.PortName = portName;
                sp.BaudRate = int.Parse(baudRate);
                sp.DataBits = int.Parse(dataBits);
                sp.StopBits = (StopBits)Enum.Parse(typeof(StopBits), stopBits);
                sp.Parity   = (Parity)Enum.Parse(typeof(Parity), parity);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("设置串口时出现异常错误!" + ex.Message);
            }
        }
Example #9
0
 public void closeSerialPort()
 {
     StaticSerialPort.removeParser(_RFIDHelper.Parse);
 }
Example #10
0
 public void openSerialPort()
 {
     StaticSerialPort.AddParser(_RFIDHelper.Parse);
 }