Пример #1
0
        public void Disconnect()
        {
            LogMessage("Disconnecting");
            ThrowWhenNotConnected();

            try
            {
                TxtCommunication.CloseConnection();
                Connection = ConnectionStatus.NotConnected;
            }
            catch (Exception e)
            {
                LogMessage($"Exception while disconnecting: {e.Message}");
                Connection = ConnectionStatus.Invalid;
                HandleException(e);
            }

            _disconnected?.Invoke(this, new EventArgs());

            TxtCommunication.Dispose();
            TxtCommunication = null;

            TxtCamera.Dispose();
            TxtCamera = null;

            LogMessage("Disconnected");
            _masterInterface.ResetValues();
        }
Пример #2
0
        public void Connect(string ip)
        {
            LogMessage($"Connecting to {ip}");
            Ip = ip;
            if (Connection == ConnectionStatus.Connected || Connection == ConnectionStatus.Online)
            {
                throw new InvalidOperationException("Already connected to an interface");
            }

            TxtCommunication?.Dispose();

            TxtCommunication = new TxtCommunication(this);
            TxtCamera        = new TxtCameraCommunication(TxtCommunication);

            try
            {
                TxtCommunication.OpenConnection();
                Connection = TxtCommunication.Connected ? ConnectionStatus.Connected : ConnectionStatus.NotConnected;
            }
            catch (Exception e)
            {
                LogMessage($"Exception while connecting: {e.Message}");
                Connection = ConnectionStatus.Invalid;
                HandleException(e);
            }


            _masterInterface.ResetValues();

            LogMessage("Connected");
            _connected?.Invoke(this, new EventArgs());
        }
Пример #3
0
        public void Dispose()
        {
            Connection = ConnectionStatus.NotConnected;

            if (TxtCommunication != null)
            {
                TxtCommunication.Dispose();
                TxtCommunication = null;
            }

            if (TxtCamera != null)
            {
                TxtCamera.Dispose();
                TxtCamera = null;
            }

            _masterInterface.ResetValues();
        }