public void ClosePort() { try { serialPort.Close(); //if (serialPort != null) //{ // serialPort.Dispose(); // serialPort = null; //} OpenStateChanged?.Invoke(false); } catch (Exception ex) { CommonModules.Notifier.NotifyHelper.Notify(CommonModules.Notifier.NotifyLevel.FATAL, $"串口{PortName}关闭失败,错误信息:{ex.Message}。"); } }
/// <summary> /// 打开串口,发开成功返回True,打开失败返回False /// </summary> /// <returns></returns> public bool OpenSerialPort() { try { serialPort.Open(); if (serialPort.IsOpen) { OpenStateChanged?.Invoke(true); return(true); } else { return(false); } } catch (Exception ex) { CommonModules.Notifier.NotifyHelper.Notify(CommonModules.Notifier.NotifyLevel.FATAL, $"串口{PortName}打开失败,错误信息:{ex.Message}。"); return(false); } }