• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Simulation using simconnect

Messages
9
Country
india
Hi to all ,
I am doing a small project and want to know how can we set avionics master switch on/off using simconnect ?
 
Messages
2,077
Country
us-ohio
By reading through the SDK and understanding how to read variables and send events via SimConnect. Lots of example projects in the SDK.
 
Messages
9
Country
india
can someone give me a link to example how to add simconnect event and get data and set data through those events ?
 
Messages
2,077
Country
us-ohio
In the FSX SDK, Core Utilities Kit/SimConnect SDK/SimConnect there are Working Samples.
 
Messages
9
Country
india
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 ?
 

Vitus

Resource contributor
Messages
1,480
Country
newzealand
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.
 
Messages
9
Country
india
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 ?
 
Messages
9
Country
india
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 ?
 
Messages
1,243
Country
canada
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.
 
Messages
9
Country
india
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.
 
Messages
9
Country
india
One more thing I want to know that is
how can I read using simconnect if Sim is paused or not ?
 
Messages
9
Country
india
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
 
Messages
2,077
Country
us-ohio
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