Jump to content
Sign in to follow this  
dragonflightdesign

SimConnect inside a gauge - not connecting

Recommended Posts

The FLIGHT_LOADED event is happening before you ever get to PANEL_SERVICE_PRE_UPDATE to initiate your connection to SimConnect.

Share this post


Link to post
Share on other sites

This gets more complex... :Big Grin:

 

Ed: thank you for confirming what I'd suspected was the underlying problem. And no, I didn't think you were being facetious. I just don't yet have the SimConnect modus operandi successfully nailed in my head.

Doug: where do you suggest that I trap 'early' events like this?

 

[Edit] Doug: just as I posted I think I figured it out. I won't be able to try until tomorrow morning, so I'd like to see if I've got it right first.

Share this post


Link to post
Share on other sites

I really thought I'd got it this time with Ed's hint about event driven.

 

case    PANEL_SERVICE_PRE_UPDATE:

    if ((strlen(prevFlight) < 3) || strcmp(prevFlight,CURRENT_FLIGHT)!=0)
    {
        hr = SimConnect_RequestSystemState(hSimConnect, SIMCONNECT_RECV_ID_EVENT_FILENAME, "FlightLoaded");
        SimConnect_CallDispatch(hSimConnect, SimConnectProcess, NULL);
        if (strlen(CURRENT_FLIGHT) > 3)
            strncpy(prevFlight, CURRENT_FLIGHT, sizeof(CURRENT_FLIGHT));
    }
    break;

_CallDispatch still isn't being called but the RequestSystemState is definately going out. I went on and did some further coding/checking and found I could easily trap FlightSaved:

 

static enum EVENT_FILENAME
{
        FLIGHT_LOADED,
        FLIGHT_SAVED,
};

void OnRecvOpen (SIMCONNECT_RECV_OPEN *pOpen, DWORD cbData)
{
        SimConnect_SubscribeToSystemEvent(hSimConnect, FLIGHT_LOADED, "FlightLoaded");
        SimConnect_SubscribeToSystemEvent(hSimConnect, FLIGHT_SAVED, "FlightSaved");
}

void OnRecvEventFilename(SIMCONNECT_RECV_EVENT_FILENAME *pData, DWORD cbData)
{
    if (FLIGHT_SAVED)strncpy(SAVED_FLIGHT,pData->szFileName,sizeof(pData->szFileName));
    if (FLIGHT_LOADED)strncpy(CURRENT_FLIGHT, pData->szFileName, sizeof(pData->szFileName));
}

What am I not calling correctly for FlightLoaded? And with apologies, because I'm right at the end of my tether with frustration, may I ask if someone would be kind enough to provide some code? I obviously can't take hints.

Share this post


Link to post
Share on other sites

Dai,

 

Call SimConnect_CallDispatch once, as soon as you call SimConnect_Open.

When you are  running in process (a gauge or module) you do not have to continually call it.

Share this post


Link to post
Share on other sites

That's what I was doing when I found that I could successfully read FlightSaved - the above code was my last despairing try before I went to bed last night. Now I'm seriously beginning to wonder if FlightLoaded actually works.

Share this post


Link to post
Share on other sites

Sorry, I just noticed this.  I think you want

void OnRecvEventFilename(SIMCONNECT_RECV_EVENT_FILENAME *pData, DWORD cbData)
{
    if (pData->uEventID == FLIGHT_SAVED)strncpy(SAVED_FLIGHT,pData->szFileName,sizeof(pData->szFileName));
    if (pData->uEventID == FLIGHT_LOADED)strncpy(CURRENT_FLIGHT, pData->szFileName, sizeof(pData->szFileName));
}

Share this post


Link to post
Share on other sites

I did some testing myself.  I'm now pretty certain that the "FlightLoaded" event occurs before gauges start getting loaded, so we'll never trap it in a gauge.

If you need to know the current flight name, use the SimConnect_RequestSystemState function.

Share this post


Link to post
Share on other sites

Thanks Doug - I was starting to think I was being particularly stupid. If I don't get it tonight, it will have to wait until I get back from Florida in ten days' time.

Share this post


Link to post
Share on other sites

:yahoo: AT LAST!!! That has been one steep learning curve - ! It was like someone turned a (dim) light on sometime over the last two days and I'm now starting to understand the SDK.

 

Thank you both very much for your help :BigGrin::drinks: 

Share this post


Link to post
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
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...