コード例 #1
0
        public RadioCommands(SerialTransmitter sTransmitter, RadioConfigurations config)
        {
            this.sTransmitter = sTransmitter;
            this.config       = config;

            this.isSendingData = true;
        }
コード例 #2
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();
        }