Simulation using simconnect

#2
By reading through the SDK and understanding how to read variables and send events via SimConnect. Lots of example projects in the SDK.
 
#5
using simconnect when i am trying to read a group of data , it works perfect but when i try to read same group of data second time , it throes exception 19 do you knwo why ?
 
#6
Maybe you're trying to call some of the constructors for a second time? Make sure to call the SimConnect_Open function just once, the same for the CallDispatch function and the AddToDataDefinitions.
 
#7
I am using c#. I have used:
public static void initDataRequestForSettingPlaneOnRunway()
{
try
{
// listen to connect and quit msgs
simconnect.OnRecvOpen += new SimConnect.RecvOpenEventHandler(simconnect_OnRecvOpen);
simconnect.OnRecvQuit += new SimConnect.RecvQuitEventHandler(simconnect_OnRecvQuit);

// listen to exceptions
simconnect.OnRecvException += new SimConnect.RecvExceptionEventHandler(simconnect_OnRecvException);

//event registering

simconnect.MapClientEventToSimEvent(EVENT_ID.ENG_FUEL_PUMP, "TOGGLE_ELECT_FUEL_PUMP1");
simconnect.MapClientEventToSimEvent(EVENT_ID.MASTER_AVIONICS_SWITCH, "AVIONICS_MASTER_SET");
simconnect.MapClientEventToSimEvent(EVENT_ID.SOUND_SWITCH, "SOUND_SET");

//handler for event notification

simconnect.OnRecvEvent += new SimConnect.RecvEventEventHandler(ReceiveEvent);
//for reading data
simconnect.AddToDataDefinition(DEFINITIONS.currentLatLonAlt, "Plane Latitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
simconnect.AddToDataDefinition(DEFINITIONS.currentLatLonAlt, "Plane Longitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
simconnect.AddToDataDefinition(DEFINITIONS.currentLatLonAlt, "Plane Altitude", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
simconnect.AddToDataDefinition(DEFINITIONS.currentLatLonAlt, "SIM ON GROUND", "Bool", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
simconnect.AddToDataDefinition(DEFINITIONS.currentLatLonAlt, "MAGVAR", "Degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
simconnect.AddToDataDefinition(DEFINITIONS.currentLatLonAlt, "PLANE HEADING DEGREES TRUE", "Degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);}

called this function once .......

static void simconnect_OnRecvSimobjectDataBytype(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE data)
{
switch ((DATA_REQUESTS)data.dwRequestID)
{
case DATA_REQUESTS.REQUEST_1:
currentLatLonAlt s1 = (currentLatLonAlt)data.dwData[0];
CAxFlightCurrentData.currLat = s1.currLat;
CAxFlightCurrentData.currLong = s1.currLong;
CAxFlightCurrentData.currAlt = s1.currAlt;
CAxFlightCurrentData.simOnGround = s1.simOnGround;
CAxFlightCurrentData.magVar = s1.magVar;
CAxFlightCurrentData.currHeading = s1.currHeading;

break;

default:
MessageBox.Show("Unknown request ID: " + data.dwRequestID);
break;
}
}
public static void ReadCurrentData()
{
// The following call returns identical information to:
// simconnect.RequestDataOnSimObject(DATA_REQUESTS.REQUEST_1, DEFINITIONS.Struct1, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD.ONCE);
if (simconnect != null)
{
simconnect.RequestDataOnSimObjectType(DATA_REQUESTS.REQUEST_1, DEFINITIONS.currentLatLonAlt, 0, SIMCONNECT_SIMOBJECT_TYPE.USER);
simconnect.ReceiveMessage();



}
}

calling this ReadCurrentData() again and again ?
first time it works fine second time it throws exception 19 ?
can someone help ?
 
#8
can anyone tell me if i am reading data continuously using a thread and in main thread i am trying to write to prepar3d , it gives exception 19 but my data is read by p3d /
why this exception 19 was raised ?
 
#9
Think you have the

Code:
simconnect.ReceiveMessage();
in the wrong spot. Should be in your defaultWindowProc.

See the exmple code in the SDK. DataRequest.cs

You might be flooding the sim with requests and not waiting. You only posted partial code.

Also try using the [ CODE ] blocks in the post. See three dots next to the smiley face in the menu above, while typing your post.
 
#10
I have placed that simconnect.receivemessage() inside defWndProc() function.
But the problem is same that is
If I am reading in loop then no issue but once I write to P3D and after that when I read it throws exception 19 and then everything is normal.
 
#14
C#:
    //registering             
                simconnect.MapClientEventToSimEvent(EVENT_ID.SIM_PAUSE, "PAUSE_ON");
                simconnect.AddClientEventToNotificationGroup(GROUP_ID.GROUP0, EVENT_ID.SIM_PAUSE, false);
                simconnect.SubscribeToSystemEvent(EVENT_ID.SIM_PAUSE, "PAUSE_ON");
//notification group priority
                simconnect.SetNotificationGroupPriority(GROUP_ID.GROUP0, SimConnect.SIMCONNECT_GROUP_PRIORITY_HIGHEST);

                //handler for event notification

                simconnect.OnRecvEvent += new SimConnect.RecvEventEventHandler(ReceiveEvent);
//call back function
 static void ReceiveEvent(SimConnect sender, SIMCONNECT_RECV_EVENT data)
        {
            switch ((GROUP_ID)data.uGroupID) {
                case GROUP_ID.GROUP0:
            switch ((EVENT_ID)data.uEventID)
            {
                 case EVENT_ID.SIM_PAUSE:
                    CAxFlightCurrentData.simCtrl.simFreeze = true;
                    break;
                    default:
                    MessageBox.Show("Unknown Event Id...!");
                    break;
                    //MessageBox.Show("Unknown event id");
            }
                    break;
                default:
                    MessageBox.Show("Unknown group...!");
                    break;
        }
    }

now to pause sim i am using
    simconnect.TransmitClientEvent(0, CAxSimconnectData.EVENT_ID.SIM_PAUSE, 1, CAxSimconnectData.GROUP_ID.GROUP0, SIMCONNECT_EVENT_FLAG.DEFAULT);
      

//The sim is paused when I do it but  callback function ReceiveEvent() i not getting called
I am struggling with receiving events.
Can someone tell why callback function is not getting called .

**receivemessage() is placed inside DefWndProc() function
 
#15
I don't see where you're creating the SimConnect interface, so I will assume you are doing something like this somewhere in your code?
Code:
simconnect = new SimConnect("Managed Client Events", this.Handle, WM_USER_SIMCONNECT, null, 0);
I do not believe you will see the event you are sending to the sim. When the system event comes in, it will not belong to any group.
 
Last edited:
Top