Monitoring SimConnect and lost connections...

#1
Hi there, I have a pretty fundamental question about SimConnect that hopefully a lot of people could answer, I'd really appreciate help...

I'm writing a C++ .exe SimConnect client. On establishing a connection, among other things, it requests that certain variables be sent to me every frame. Of course, I want my program to establish a connection when it starts up, or if FSX is not running, to establish a connection when the Sim starts up. In addition, I've noticed that SimConnect sometimes, somehow, fails - that is, every once in a while I stop receiving messages while the sim is running, for no apparent reason (though it seems to happen during heavy weather/scenery loads or after switching the user aircraft many times). So if this happens, I'd like my program to reestablish a connection.

What I've done so far is to create a windows timer, which checks to see if my simconnect DispatchProcedure function has been called in the last ten seconds. If it hasn't been called, I attempt to close and reopen SimConnect. I quickly noticed that information was not sent while the sim is paused or in UI mode, and the client would needlessly disconnect and reconnect. Requesting a four-second timer from SimConnect solves this problem when the sim is paused, and sometimes when it's in UI. However, often when it is in UI mode, especially in the main FS UI at startup and while the "flight loading" progress bar is displayed, I don't seem to get the timer messages.

So my question is: is there a correct way to evaluate the status of the connection during all phases of FSX operation (running, paused, UI, Loading, etc.) and reconnect if necessary, as well as to insure that the client connects relatively quickly every time the simulator is started? I also tried checking the return value of SimConnect_CallDispatch() but it seems often to return OK when the sim is not even running?

I'd really appreciate any help, Thanks!

Farley
 
#2
You need to subscribe to the events "SimStart" and "SimStop." On loading you begin in the stopped state, then after the user selects the aircraft and location you will get several start/stop events but end on "start." Likewise if the user later goes into the UI, or scenery needs to reload you will get a stop then start when it comes back.
 
Top