Jump to content
The simFlight Network Forums

FSUIPCConnection.IsOpen problems


Recommended Posts

I have a C# WPF app with a main window that controls startup routines. In the main window, I have the following. The user control displays connection status. Unfortunately, the connection status shows 'not connected' when the window loads if MSFS is closed. It will also display 'connected' when MSFS is loaded. When the app is running and MSFS closes, the status remains at 'connected'. It should toggle between not connected and connected based on the status of MSFS/FSUIPC. Any ideas how I can fix it?

connectionTimer = new()
{
    AutoReset = true,
    Enabled = true,
    Interval = 300,
};

// Connection elapsed event.
#region
connectionTimer.Elapsed += (s, e) =>
{

    // Try to open the connection. Otherwise connection timer will do nothing.
    try
    {
                                                    FSUIPCConnection.Open();
        FSUIPCConnection.Process();
                                            }
    catch(Exception ex)
    {
    }

};
#endregion
connectionTimer.Start();
                        #endregion

In the user control embedded into the main window, I have the following.
var timer = new DispatcherTimer
{
    Interval = TimeSpan.FromMilliseconds(300),
    IsEnabled = true,
                                };
timer.Tick += async (s, args) => await UpdatePanelControlsAsync();

timer.Start();

private async Task UpdatePanelControlsAsync()
{
    await Task.Run(() =>
    {
        string status = FSUIPCConnection.IsOpen? "Connected" : "Not connected";
        Dispatcher.Invoke(() =>
        {
                                connectionStatusTextBox.Text = status.ToString();
            
        });
    });
 

Link to comment
Share on other sites

Hi Andy,

The IsOpen property refers only to the FSUIPC connection, not the flight sim. Prior to FSUIPC7 this was effectively the same thing as FSUIPC ran inside the flight sim. 

WideClient.exe and FSUIPC7 run outside of the flight sim, so the connection will be open if they are running, even if the flight sim is not.

If you want to know if the flight sim is open you can try polling offset 0x337E (activity counter) to make sure it's changing. See the notes in the documentation as there are times it might not update (e.g. loading new aircraft).

Paul

Link to comment
Share on other sites

So I understand, FSUIPCConnection.IsOpen only checks to see if FSUIPC itself is actively running. It knows nothing about MSFS or its current state. When MSFS closes, my app will always return the last known state of FSUIPC, which was open at the end of the test. To deal with this, I should check the activity counter offset since it can determine if MSFS is currently loaded. I can use the offset for now, but is there a way you can add this as a property to FSUIPCConnection?

 

Link to comment
Share on other sites

 

I tried this offset. I have the same result as when checking IsOpen. The app shows not connected until MSFS is active, then changes to connected as expected. However, closing MSFS while the app is open still results in the connected message staying on screen, even when MSFS has completely unloaded. Restarting my app then displays not connected. Wonder why it's doing this...strange.

Link to comment
Share on other sites

Quote

. However, closing MSFS while the app is open still results in the connected message staying on scree

You need to be checking the ValueChanged property of offset 0x337E.  If you close MSFS and this offset is still changing (counting up), you'll need to ask John Dowson in the FSUIPC7 support forum if he has any other ideas for detecting if MSFS is unloaded.

Paul

Link to comment
Share on other sites

Just did a test where all the timer did is report the activity count. When I started my app before MSFS was loaded, the total count is 0. After getting to the welcome screen, it still reported 0, even though IsOpen reported true. After restarting my app, I now have a total count of 219. Now, when I close MSFS, the display in my app still shows 219/connected for the current status. I don't understand, because this method works for other parts like aircraft panels. Not sure why it doesn't work here.

Link to comment
Share on other sites

Quote

 After getting to the welcome screen, it still reported 0, even though IsOpen reported true. 

IsOpen is true because it's connected to FSUIPC7. The counter is probably doesn't update until the player has loaded an aircraft. It should start counting up when you start a flight. 

Quote

Now, when I close MSFS, the display in my app still shows 219/connected for the current status. 

This seems correct then. If it's sticking at 219 then there is no activity. The ValueChanged property on 0x337E will be false. So your app knows that MSFS has been unloaded. The activity counter might also stop when the user has ended the flight and is back in the menus.

Paul

 

 

 

Link to comment
Share on other sites

 

I figured it out. The timer that does the processing for the offsets was missing. Had to stop the connection timer when connection opens and start the process timer. If the process timer throws an exception, restart the connection timer. It all works now. 🙂

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.