public EECommDeviceUART(string model, int busAddr, ScanConfigurationUART scanConf, bool uniAdapter) : base(scanConf) { _busAddr = busAddr; _isUniAdapter = uniAdapter; ModelText = model; }
/// <summary> /// Copy constructor. /// </summary> public ScanConfigurationUART(ScanConfigurationUART other) { if (other != null) { Port = other.Port; ComPortSettings = new ComPortSettings(other.ComPortSettings); } }
/// <summary> /// Ensures connection status. Connects device if necessary. /// </summary> public override void EnsureConnection() { lock (_lock_serPort) { ScanConfigurationUART uartConf = (ScanConfigurationUART)ScanConfigurationActive; uartConf.UnauthorizedAccess = false; try { if (_serPort == null) { _serPort = new System.IO.Ports.SerialPort() { PortName = uartConf.Port, BaudRate = uartConf.ComPortSettings.Baudrate, Parity = uartConf.ComPortSettings.Parity, DataBits = uartConf.ComPortSettings.Databits, StopBits = uartConf.ComPortSettings.Stopbits, Handshake = uartConf.ComPortSettings.Handshake, DtrEnable = true, RtsEnable = true // Request-to-send (RS232 adapter power supply) }; System.Threading.Thread.Sleep(200); } if (!_serPort.IsOpen) { _serPort.Open(); Connected = true; } } catch (Exception exc) { // Check for UnauthorizedAccessException (port is in use by // another program) if (exc is UnauthorizedAccessException) { // Do not pass along this exception. uartConf.UnauthorizedAccess = true; } else { throw exc; } } } }