Exemplo n.º 1
0
        public void COMConnect()
        {
            try
            {
                string[] ports = SerialTransmitter.GetPortNames();
                string   portToConnect;

                if (ports.Length > 0)
                {
                    portToConnect = ports[0];
                }
                else
                {
                    AddErrorLogItem("COM connect failed. You should have 1 COM port!");
                    return;
                }

                AddSysLogItem("Connecting to " + portToConnect + "...");

                this.comTransmitter = new SerialTransmitter(portToConnect);
                this.comTransmitter.DateReceived += ComTransmitter_DateReceived;
                this.comTransmitter.Open();

                AddSysLogItem("Connected to " + portToConnect + ".");
            }
            catch (Exception ex)
            {
                this.rCommand = null;
                AddErrorLogItem("COM connection failed.");
                return;
            }

            this.rCommand                    = new Core.RadioCommands(comTransmitter, this.radioConfig);
            this.rCommand.LogOccured        += RCommand_LogOccured;
            this.rCommand.DisconnectOccured += () =>
            {
                AddSysLogItem("COM Error / Force disconnect.");
                COMDisconnect();
            };
            if (this.currentAircraftState != null)
            {
                this.rCommand.SetAircraftValues(this.currentAircraftState);
            }
            this.comInitialized = true;
            RaiseNeedUpdateUI();
        }
Exemplo n.º 2
0
        public void COMDisconnect()
        {
            this.comInitialized = false;

            try
            {
                this.comTransmitter.Close();
            }
            catch (Exception ex)
            {
                AddErrorLogItem("COM disconnect failed. Trying to dispose RadioCommand.");
            }

            try
            {
                this.rCommand.Dispose();
            }
            catch (Exception ex) { }

            this.rCommand = null;
            RaiseNeedUpdateUI();

            AddSysLogItem("COM disconnected.");
        }