public ComInfo() { a_comValue = new ComValue(); }
/// <summary> /// 读取XML配置文件的参数设置,获取下载的TXT文件路径与上传的数据文件路径 /// </summary> /// <returns></returns> private void MyOpenCOM(ref SerialPort m_serialPort, ref ComValue m_comValue) { try { // Allow the user to set the appropriate properties. m_serialPort.PortName = a_comInfo.a_comValue.comName; m_serialPort.BaudRate = Convert.ToInt16(m_comValue.comBand); switch (m_comValue.comParity) { case "n": m_serialPort.Parity = Parity.None; break; case "o": m_serialPort.Parity = Parity.Odd; break; case "e": m_serialPort.Parity = Parity.Even; break; default: m_serialPort.Parity = Parity.None; break; } m_serialPort.DataBits = 8; m_serialPort.StopBits = StopBits.One; m_serialPort.ReadTimeout = 2000; //读超时。2秒未读到数据,即引发读超时异常。 m_serialPort.WriteTimeout = 2000; //写超时,2秒未读到数据,即引发写超时异常。 m_serialPort.ReadBufferSize = 1024; //数据读缓存 m_serialPort.WriteBufferSize = 1024; //数据写缓存 m_serialPort.ReceivedBytesThreshold =checked((int)a_itfaceInfo.recBitNum); m_serialPort.DataReceived += new SerialDataReceivedEventHandler(SerialPort_DataReceived); m_serialPort.Open(); } catch (System.Exception e) { LogHelper.WriteLog(null, e as Exception); //throw (e); } }