/// <summary> /// setting comport /// </summary> /// <param name="port">comport name</param> public void SetPort(String port) { initPort = new InitialPort(); initPort.Comport = port; initPort.BaudRate = 9600; initPort.DataBits = 8; initPort.DtrEnable = true; _serialPort = Initial(initPort); }
/// <summary> /// Initial serial port /// </summary> /// <param name="init">port config class</param> /// <returns></returns> protected SerialPort Initial(InitialPort init) { SerialPort _serialport = new SerialPort(); _serialport.PortName = init.Comport; _serialport.BaudRate = init.BaudRate; _serialport.DataBits = init.DataBits; _serialport.StopBits = StopBits.One; _serialport.DtrEnable = init.DtrEnable; _serialport.Parity = Parity.None; //_serialport.NewLine = "\r\n"; _serialport.ReceivedBytesThreshold = 1; //_serialport.WriteTimeout = 500; //_serialport.ReadTimeout = 2000; _serialport.RtsEnable = true; return(_serialport); }