Beispiel #1
0
        public void Disconnect()
        {
            Log.Debug("Disconnecting");
            try
            {
                this.SerialPort.Close();
            }
            catch
            {
                // The connection may already be closed due to a failure. 
            }

            this.CommandReuniter.StopListening();
            this.CommandReuniter = null;
        }
Beispiel #2
0
        public void Connect()
        {
            var connectionSettings = (SerialConnectionSettings)this.ConnectionSettings;
            this.SerialPort = new SerialPort(
                connectionSettings.PortName,
                connectionSettings.Baudrate,
                connectionSettings.Parity,
                connectionSettings.DataBits,
                connectionSettings.StopBits);

            this.SerialPort.DataReceived += this.SerialPort_DataReceived;

            Log.DebugFormat("Connecting to device. Opening Port : {0}", connectionSettings.PortName);
            this.SerialPort.Open();
            Log.Debug("Port opened");

            this.CommandReuniter = new CommandReuniter { ParentProtocol = this };
            this.CommandReuniter.CommandReceived += this.CommandReuniter_CommandReceived;
            this.CommandReuniter.StartListening();
        }