Exemplo n.º 1
0
 /// <summary>
 /// 初始化串口
 /// </summary>
 private void InitSerialPort()
 {
     try {
         _portSetting.ApplySettings(Port);
         Port.NewLine = NewLine;
         Port.Open();
     } catch (Exception ex) {
         Trace.TraceWarning("InitSerialPort Error, {0}", ex.Message);
         this.OnPropertyChanged(nameof(Enable));
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 初始化串口
        /// </summary>
        private void InitSerialPort()
        {
            try {
                if (this.Port == null)
                {
                    Port = _portSetting.CreatePort();
                }
                else
                {
                    Port.DataReceived -= Port_DataReceived;
                    Port.Close();
                    _portSetting.ApplySettings(Port);
                }

                Port.NewLine = NewLine;
                Port.Open();
                Port.DataReceived += Port_DataReceived;
            } catch (Exception ex) {
                Trace.TraceWarning("InitSerialPort Error, {0}", ex.Message);
                this.OnPropertyChanged(nameof(Enable));
            }
        }