Esempio n. 1
0
        public bool Connect()
        {
            if (ValueBag.Connected)
            {
                return(false);
            }
            try
            {
                FSUIPCConnection.Open();
                ValueBag.Clear();
                ValueBag.Connected = true;
                FsxiConnected?.Invoke(this, EventArgs.Empty);
                FsxiValueBagUpdated?.Invoke(this, EventArgs.Empty);

                updateThread = new Thread(new ParameterizedThreadStart(ThreadFunc));
                updateThread.Start(this);
                return(true);
            }
            catch (FSUIPCException)
            {
                return(false);
            }
            catch (Exception e)
            {
                log.Error(e);
                return(false);
            }
        }
Esempio n. 2
0
        public static void CheckConnection(Object myObject = null, EventArgs myEventArgs = null)
        {
            mainForm.setProgress(true);
            try
            {
                FSUIPCConnection.Open();
                connected = true;
                Logger.Log("Connected to FS");
                Logger.Log("DLL version:" + FSUIPCConnection.DLLVersion.ToString());
                mainForm.setStatus("Connected to FS");
                mainForm.setProgress(false);
                TIMER.Enabled = false;
                TIMER.Tick   += new EventHandler(CheckConnected);
                TIMER.Stop();

                sendMessage(AppTitle + " is now connected!", 10);
                FLIGHTTIMER.Enabled  = true;
                FLIGHTTIMER.Interval = 1000;

                FLIGHTTIMER.Tick += new EventHandler(updateData);
                FLIGHTTIMER.Start();

                mainForm.fplForm.startInfoTimer();
            }
            catch (Exception ex)
            {
                string e = ex.ToString();
            }
        }
Esempio n. 3
0
 // The connect/disconnect buton
 private void btnToggleConnection_Click(object sender, EventArgs e)
 {
     if (FSUIPCConnection.IsOpen)
     {
         // Connection is currently open
         // Stop the main timer
         this.timerMain.Stop();
         // Close the connection
         FSUIPCConnection.Close();
     }
     else
     {
         // Try to open the connection
         try
         {
             this.lblConnectionStatus.Text      = "Looking for a flight simulator...";
             this.lblConnectionStatus.ForeColor = Color.Goldenrod;
             FSUIPCConnection.Open();
             // If there was no problem, start the main timer
             this.timerMain.Start();
         }
         catch (Exception ex)
         {
             // An error occured. Tell the user.
             MessageBox.Show("Connection Failed\n\n" + ex.Message, "FSUIPC", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
     configureForm();
 }
Esempio n. 4
0
        /// <summary>
        /// Metodo per attivare la connessione ad FSUIPC
        /// </summary>
        public void ConnectToFS()
        {
#if !FEDE_DEBUG
            FSUIPCConnection.Open();
#endif
            connected = true;
        }
        static void Main(string[] args)
        {
            FSUIPCConnection.Open();

            Offset <long> playerLatitude = new Offset <long>(0x0560);

            Offset <long> playerLongitude = new Offset <long>(0x0568);

            Offset <int> autoThrottle = new Offset <int>(0x0810);

            Offset <int> flightDirector = new Offset <int>(0x2EE0);

            while (true)
            {
                FSUIPCConnection.Process();
                FsLongitude lon = new FsLongitude(playerLongitude.Value);
                FsLatitude  lat = new FsLatitude(playerLatitude.Value);

                var atSwitch = autoThrottle.Value;

                var fdSwitch = flightDirector.Value;

                Thread.Sleep(5000);
            }
        }
Esempio n. 6
0
 private static void OnTimedEvent(Object source, ElapsedEventArgs e)
 {
     if (!isConnectedtoFSUIPC)
     {
         try
         {
             Console.Write(".");
             FSUIPCConnection.Open();
             isConnectedtoFSUIPC = true;
         } catch (Exception ex)
         {
             isConnectedtoFSUIPC = false;
         }
     }
     else
     {
         try
         {
             FSUIPCConnection.Process();
         } catch (Exception ex)
         {
             Errormessage.sendErrorMessage("FSUIPC Process", ex.Message);
             FSUIPCConnection.Close();
             isConnectedtoFSUIPC = false;
         }
     }
 }
Esempio n. 7
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            switch (btnConnect.Text)
            {
            case "Connect":

                switch (cboxServer.Text)
                {
                case "Beta":
                    sck.Connect("192.168.56.102", 6809);

                    FSUIPCConnection.Open();

                    LATandLON.Start();

                    txtCallsign.Enabled = false;
                    txtAircraft.Enabled = false;
                    txtChatText.Enabled = true;
                    btnChatSend.Enabled = true;

                    lblStatus.Text      = "Connected";
                    lblStatus.ForeColor = Color.ForestGreen;
                    txtChat.Text        = "You are now connect on network server!";

                    btnConnect.Text  = "Flight Plan";
                    btnClose.Enabled = true;
                    break;

                default:
                    LATandLON.Stop();
                    FSUIPCConnection.Close();
                    sck.Close();
                    sck.Dispose();

                    txtCallsign.Enabled = true;
                    txtAircraft.Enabled = true;
                    txtChatText.Enabled = false;
                    btnChatSend.Enabled = false;
                    btnClose.Enabled    = false;
                    btnConnect.Enabled  = false;

                    lblStatus.Text      = "Server Error";
                    lblStatus.ForeColor = Color.DarkRed;

                    btnConnect.Text = "Connect";
                    txtChat.Text    = txtChat.Text + "\r\nSelect one server!";
                    break;
                }

                break;

            case "Flight Plan":
                f.Show();
                break;

            default:
                break;
            }
        }
        /// <summary>
        /// Returns an FSUIPCSnapshot instance with the current state of the sim
        ///
        ///
        /// </summary>
        /// <param name="connectCooldown">Time between reconnect tries to Simulator, in miliseconds.
        /// Defaults to 30000.</param>
        /// <returns></returns>
        public static FSUIPCSnapshot Pool(int connectCooldown = 30000)
        {
            // TODO: do not block the current thread on this
            //       application may receive a OS taskkill command.
            //       Maybe expose connected = true?
            while (!connected)
            {
                try
                {
                    FSUIPCConnection.Open();

                    connected = true;
                }
                catch (FSUIPCException crap)
                {
                    switch (crap.FSUIPCErrorCode)
                    {
                    case FSUIPCError.FSUIPC_ERR_OPEN:
                        connected = true;
                        break;

                    case FSUIPCError.FSUIPC_ERR_NOFS:
                        Thread.Sleep(connectCooldown);
                        break;

                    default:
                        throw new ApplicationException(
                                  "Unexpected exception trying FSUIPC.Open(). Check inner exception.",
                                  crap);
                    }
                }
            }

            try
            {
                FSUIPCConnection.Process();
            }
            catch (Exception crap)
            {
                // TODO: catch ONLY relevant execeptions
                //       connected = false;
                throw new ApplicationException("Provider.Pool() failed with:", crap);
            }

            if (connected)
            {
                FSUIPCSnapshot data = new FSUIPCSnapshot(true);

                // FSUIPC will return data even if the user is in scenario screen
                // or any other screen really.
                // TODO: actually filter invalid locations
                return(data.Position.SequenceEqual(new double[] { 0, 0 }) ? null : data);
            }

            return(null);
        }
Esempio n. 9
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            sck.Connect("37.59.115.154", 6809);

            FSUIPCConnection.Open();

            lblStatus.Text      = "Connected";
            lblStatus.ForeColor = Color.ForestGreen;
            txtChat.Text        = "You are now connect on network server!";
        }
Esempio n. 10
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     try
     {
         FSUIPCConnection.Open();
     }
     catch
     {
         ;
     }
 }
Esempio n. 11
0
 private void FSUIPCReconnectTimer_Tick(object sender, EventArgs e)
 {
     try
     {
         FSUIPCConnection.Close();
         FSUIPCConnection.Open();
     }
     catch
     {
     }
 }
Esempio n. 12
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Connect to FSUIPC button
            FSUIPCConnection.Open();

            if (FSUIPCConnection.IsOpen)
            {
                label1.Show();
                BroadcastPosition();
            }
        }
Esempio n. 13
0
        private void btnConnectar_Click(object sender, EventArgs e)
        {
            try
            {
                // Attempt to open a connection to FSUIPC (running on any version of Flight Sim)
                FSUIPCConnection.Open();
                // Opened OK so disable the Connect button
                this.btnConnectar.Enabled     = false;
                this.chkEnableAIRadar.Enabled = true;
                // Start the timer ticking to drive the rest of the application
                this.timer1.Interval = 200;
                this.timer1.Enabled  = true;
                // Set the AI object
                AI = FSUIPCConnection.AITrafficServices;
            }
            catch (Exception ex)
            {
                // Badness occurred - show the error message
                MessageBox.Show(ex.Message, AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                FSUIPCConnection.Close();
                Debug.WriteLine(ex.Message);
            }

            if (simconnect == null)
            {
                try
                {
                    // the constructor is similar to SimConnect_Open in the native API
                    // the ConfigIndex enables you to choose which Simconnect profile to use (in a SimConnect.cfg) if you are
                    // connecting over a network. Leaving it to zero for a local connection here.
                    simconnect = new SimConnect("C# Monitoring AI Objects", this.Handle, WM_USER_SIMCONNECT, null, 0);

                    // setButtons(false, true, true);

                    initDataRequest();
                }
                catch
                {
                    MessageBox.Show("Make sure Microsoft ESP is running and that you have the SimConnect client installed.", "Unable to connect to ESP");
                }
            }

            // Store the current object type being monitored
            monitoredObjectType = SIMCONNECT_SIMOBJECT_TYPE.AIRCRAFT;

            // Refresh the list of monitored objects for this specific request
            // first, Clear any current objects and stop all data requests for those objects
            ResetDataAndShutDownRequests();

            // Now, Initiate a request for the list of objects we are interested in monitoring in the given radius
            simconnect.RequestDataOnSimObjectType(DATA_REQUESTS.REQUEST_AI_OBJECT_ID_BYTYPE,
                                                  DEFINITIONS.AI_Entity_Definition, MONITOR_RADIUS, monitoredObjectType);
        }
Esempio n. 14
0
        /// <summary>
        /// Returns true on successfull connection, false otherwise
        /// </summary>
        /// <returns></returns>
        public static bool Connect()
        {
            try
            {
                FSUIPCConnection.Open();
            }
            catch (Exception crap)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 15
0
 public bool DwcOpen()
 {
     try
     {
         FSUIPCConnection.Close();
         FSUIPCConnection.Open();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 16
0
 /// <summary>
 /// Tries to connect to FSX
 /// </summary>
 /// <returns></returns>
 private bool ConnectToFSX()
 {
     try
     {
         // Attempt to open a connection to FSUIPC (running on any version of Flight Sim)
         FSUIPCConnection.Open();
         return(true);
     }
     catch (Exception)
     {
         FSUIPCConnection.Close();
         return(false);
     }
 }
Esempio n. 17
0
 private void openFSUIPC()
 {
     try
     {
         FSUIPCConnection.Open();
         bridgeTimer.Interval = 200;
         bridgeTimer.Enabled  = true;
     }
     catch (Exception ex)
     {
         // Badness occurred - show the error message
         MessageBox.Show(ex.Message, "Bridge Test", MessageBoxButtons.OK, MessageBoxIcon.Error);
         FSUIPCConnection.Close();
     }
 }
Esempio n. 18
0
 private void TimerConnection_Tick(Object sender, EventArgs e)
 {
     try
     {
         FSUIPCConnection.Open();
         // 如果连接上 FSUIPC 就停止
         timerConnection.Stop();
         timerMain.Start();
         GetFullObject();
         // 更新显示状态
         ConfigureForm();  
     }
     catch
     {
         // No connection found. Don't need to do anything, just keep trying
     }
 }
 private void FsuipcConnectTimerCallback(object state)
 {
     if (!_isFsuipcConnected)
     {
         try
         {
             FSUIPCConnection.Open();
             _isFsuipcConnected = true;
             Log.Info("FSUIPC connection is opened.");
         }
         catch (Exception ex)
         {
             _isFsuipcConnected = false;
             Log.Error("FSUIPC connection could not be made!", ex);
         }
     }
 }
Esempio n. 20
0
 // This method is called every 1 second by the connection timer.
 private void timerConnection_Tick(object sender, EventArgs e)
 {
     // Try to open the connection
     try
     {
         FSUIPCConnection.Open();
         // If there was no problem, stop this timer and start the main timer
         this.timerConnection.Stop();
         this.timerMain.Start();
         // Update the connection status
         configureForm();
     }
     catch
     {
         // No connection found. Don't need to do anything, just keep trying
     }
 }
        // This method is called every 1 second by the connection timer.
        private void TimerConnection_Tick(object sender, ElapsedEventArgs e)
        {
            // The connection counter prevents excessive instances of an error
            // from appearing in the log.
            connectionCounter++;

            // Try to open the connection
            try
            {
                FSUIPCConnection.Open();

                // If there was no problem, stop this timer and start the main timer
                this.TimerConnection.Stop();
                this.SetCommandKeyMenuText();
                this.TimerMain.Elapsed  += TimerMain_Tick;
                this.TimerMain.AutoReset = true;
                this.TimerMain.Start();
                this.TimerLowPriority.Elapsed  += TimerLowPriority_Tick;
                this.TimerLowPriority.AutoReset = true;
                this.TimerLowPriority.Start();
                // load airport database
                inst.Speak("loading airport database");
                dbLoadWorker.RunWorkerAsync();
                // write version info to the debug log
                logger.Debug($"simulator version: {FSUIPCConnection.FlightSimVersionConnected}");
                logger.Debug($"FSUIPC version: {FSUIPCConnection.FSUIPCVersion}");
                logger.Debug($"FSUIPC .net DLL version: {FSUIPCConnection.DLLVersion}");
            }
            catch (Exception ex)
            {
                if (connectionCounter <= 5)
                {
                    logger.Debug($"Connection failed [attempt #{connectionCounter}]: {ex.Message}: {ex.Source}:{ex.StackTrace}");
                    //logger.Debug($"Inner exception {ex.InnerException.Message}");
                }
                else if (connectionCounter == 35)
                {
                    Tolk.Output("Connection timed out. See the TFM log for more details. Please restart TFM to continue.");
                    logger.Debug("Connection timeout: The simulator or fsuipc are not running. Make sure they are running before starting TFM.");
                    this.TimerConnection.Stop();
                    // Command keys menu item is not needed when FSUIPC is not running.
                    commandKeysMenuItem.Visible = false;
                }
            }
        }
Esempio n. 22
0
        public bool Connect()
        {
            try
            {
                FSUIPCConnection.Open();

                if (FSUIPCConnection.IsOpen)
                {
                    Log.Logger.Information("IPCManager: FSUIPC Connected");
                }
            }
            catch
            {
                Log.Logger.Error("IPCManager: Exception while opening FSUIPC");
            }

            return(IsConnected);
        }
Esempio n. 23
0
        private void openFSUIPC()
        {
            try
            {
                FSUIPCConnection.Open();
                //this.connect.Enabled = false;

                Logger.Log("Connected to FS");
                mainForm.setStatus("Connected to FS");
                mainForm.setProgress(false);
                TIMER.Enabled = false;
                TIMER.Stop();
                sendMessage(AppTitle + " is now connected!", 10);
                startRUNTIMER();
            }
            catch (Exception)
            {
            }
        }
Esempio n. 24
0
        private void OnConnectionTimerEvent(Object source, ElapsedEventArgs e)
        {
            try
            {
                FSUIPCConnection.Open();
            }
            catch
            {
                Logger.Instance.LogMessage(TracingLevel.INFO, "connection failed");
            }

            if (FSUIPCConnection.IsOpen)
            {
                _connectionTimer.Enabled = false;
                Logger.Instance.LogMessage(TracingLevel.INFO, "connected");
                ConnectionChanged?.Invoke(this, true);
                SetupMainTimer();
            }
        }
Esempio n. 25
0
        public Boolean Connect()
        {
            try
            {
                if (!isopen)
                {
                    FSUIPCConnection.Open();
                    isopen = FSUIPCConnection.IsOpen;
                }

                status = "Connection opened to Simulator: " + FSUIPCConnection.FlightSimVersionConnected;
                return(isopen);
            }
            catch (Exception e)
            {
                isopen = false;
                status = e.Message;
                return(isopen);
            }
        }
Esempio n. 26
0
        public static void Reconnect()
        {
            try
            {
                FSUIPCConnection.Close();
                FSUIPCConnection.Open();

                /*FSUIPCConnection.Open();
                 * connected = true;
                 * Logger.Log("Connected to FS");
                 * Logger.Log("DLL version:" + FSUIPCConnection.DLLVersion.ToString());
                 * mainForm.setStatus("Connected to FS");
                 * mainForm.setProgress(false);
                 * sendMessage(AppTitle + " is now connected!", 10);*/
            }
            catch (Exception ex)
            {
                string e = ex.ToString();
            }
        }
Esempio n. 27
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (ModifierKeys.HasFlag(Keys.Control))
     {
         ConnectionStatus(true);
     }
     else
     {
         try
         {
             FSUIPCConnection.Open(FlightSim.Any);
             ConnectionStatus();
         }
         catch (FSUIPCException ex)
         {
             GlobalData.ErrorLogInput(ex, "WARNING");
             MessageBox.Show("Error: " + ex.Message, "Uh oh!", MessageBoxButtons.OK);
         }
     }
 }
Esempio n. 28
0
        public static void FSUIPC_Connect()
        {
            try
            {
                FSUIPCConnection.Open();

                FsuiipcOpen = true;
            }
            catch (Exception crap)
            {
                Console.WriteLine("{0} Exception caught.", crap);

                if (FSUIPCConnection.FlightSimVersionConnected.ToString() == "Any")
                {
                    FsuiipcOpen = false;

                    FSUIPCConnection.Close();
                    FSUIPC_Connect();
                }
            }
        }
Esempio n. 29
0
        private bool ConnectToSim()
        {
            try
            {
                FSUIPCConnection.Open();

                return(true);
            }
            catch (FSUIPCException crap)
            {
                switch (crap.FSUIPCErrorCode)
                {
                case FSUIPCError.FSUIPC_ERR_NOFS:
                    break;

                case FSUIPCError.FSUIPC_ERR_OPEN:
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 30
0
 private void btnFS_Click(object sender, RoutedEventArgs e)
 {
     if (FSUIPCConnection.IsOpen)
     {
         HandleDroneActions(false);
         FSUIPCConnection.Close();
     }
     else
     {
         lblStatus.Content = "Looking for a flight simulator...";
         try
         {
             FSUIPCConnection.Open();
             HandleDroneActions(true);
         }
         catch (FSUIPCException ex)
         {
             System.Windows.MessageBox.Show(ex.Message, "Connection Failed. ");
         }
     }
     setConnectionStatus();
 }