Jump to content
The simFlight Network Forums

Recommended Posts

Posted

I am trying to get the active fuel tanks from payload services. However, it is throwing an exception saying that the fsuipc connection isn't open, when in fact it already is open. I can be sure of it because I am getting data from other offsets, including payload services itself. Any idea what might be going on? Below is the code in question. I put a connection check around it just to get the app to start. I tried putting a new open before it to see if that worked. It does, but the connection manager gets somewhat confused about connection start.

 

        private void DetectFuelTanks()
        {
            FSUIPCConnection.Open();            
            if (FSUIPCConnection.IsOpen)
            {

                FSUIPCConnection.PayloadServices.RefreshData();
                _activeFuelTanks.Clear();

                // Assign the fuel tanks to our class level variable for easier access
                _fuelTanks = FSUIPCConnection.PayloadServices.FuelTanks;
                foreach (FsFuelTank tank in _fuelTanks)
                {
                    if (tank.IsPresent)
                    {
                        _activeFuelTanks.Add(tank);
                        logger.Info("found " + tank.Tank.ToString());
                    }
                }
            }
        }                           

Posted

Hi Andy,

It's a bit puzzling.

I've had a look at the code and the FSUIPCConnection.Open() and FSUIPCConnection.IsOpen wasn't very thread safe. The connection was marked as open before the opening procedure completed.  

I've improved this in Version 3.3.11 - Now on NuGet. 

Can you please try this version to see if it fixes your problem.

Note that you need to remove the FSUIPCConnection.Open() from the fuel tank code. You can't open the connection twice.

The check for IsOpen is good and should remain.

Paul

Posted

Ok, removed the FSUIPC.Open call and tried again with an open connection and the new library build. I am still not able to detect fuel tanks from payload services. When the check for the open connection is in place, an entry is written to the log about the fuel tanks found. There is nothing in the log about fuel tanks. I even went so far as to delete the entire log file and start from a new one. Same code as above with the following log.

 

[Info]: Creating audio output devices.: [tfm.Utilities.AudioManager.SetupAudio]: [2024-06-22 08:02]
[Info]: Creating sound mixer.: [tfm.Utilities.AudioManager.SetupAudio]: [2024-06-22 08:02]
[Info]: Starting audio services.: [tfm.Utilities.AudioManager.SetupAudio]: [2024-06-22 08:02]
[Info]: Loaded 41552 airports.: [tfm.Utilities.AirportServices.LoadAirportsDatabase]: [2024-06-22 08:02]
[Info]: Connected to flight simulator (auto connect).: [tfm.Utilities.ConnectionManager.AutoConnect]: [2024-06-22 08:02]
 

When I remove the connection check, I get an fsuipc connection isn't open error.

Posted

To be clear, the connection check only allows me to run TFM at this point. In normal operation, it would detect fuel tanks, setup fuel services in TFM, then write to the log. Since there isn't a TFM log entry about fuel tanks, and removing the check for the connection throws a connection not open error, I assume the problem still exists.

 

Posted

Then I think the problem is that DetectFuelTanks() is being called before the connection is open. Add a log entry when DetectFuelTanks runs. If it comes before 

[Info]: Connected to flight simulator (auto connect).: [tfm.Utilities.ConnectionManager.AutoConnect]: [2024-06-22 08:02]

then you need change your code to make sure everything happens after the connection is open.

Paul

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.