Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

SimConnect inside a gauge - not connecting

Featured Replies

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

  • Author
  • Commercial Member

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.

  • Author
  • Commercial Member

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.

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.

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));
}

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.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.