public bool Init(RS232Settings settings) { string portName; this.settings = (RS232Settings)settings; if (serialPort == null || !serialPort.IsOpen)// !isConnected) { portName = "COM" + this.settings.CommunicationPort.ToString(); serialPort = new SerialPort(portName, (int)this.settings.BaudRate, this.settings.Parity, this.settings.DataBits, this.settings.StopBits); serialPort.ReadTimeout = Timeout.Infinite; serialPort.WriteTimeout = Timeout.Infinite; serialPort.Encoding = System.Text.Encoding.ASCII; try { serialPort.Open(); //if (serialPort.IsOpen) // isConnected = true; } catch (UnauthorizedAccessException uaExc) { lastErrorMsg = uaExc.Message; } catch (System.IO.IOException ioExc) { lastErrorMsg = ioExc.Message; } } return(serialPort.IsOpen); }
//public int DeviceId //{ // get { return deviceId; } // set { deviceId = value; } //} #endregion #endregion public object Clone() { RS232Settings db = new RS232Settings(); //db.DeviceId = DeviceId; db.CommunicationPort = CommunicationPort; db.BaudRate = BaudRate; db.DataBits = DataBits; db.Parity = Parity; db.StopBits = StopBits; db.ResponseDelay = responseDelay; db.InterCharGap = interCharGap; return(db); }