Ejemplo n.º 1
0
        public void setupSimConnect()
        {
            try
            {
                p3d = new SimConnect("P3DAutoSave", dummyWindow.Handle, SimConnectDummyWindow.WM_USER_SIMCONNECT, null, 0);
            }
            catch (COMException e)
            {
                MessageBox.Show(e.Message);
                MessageBox.Show("Please start P3D before launching this application.");
                Environment.Exit(1);
            }

            // listen to quit msg
            p3d.OnRecvQuit += new SimConnect.RecvQuitEventHandler(p3d_OnRecvQuit);

            // listen to events
            p3d.OnRecvEvent += new SimConnect.RecvEventEventHandler(p3d_OnRecvEvent);

            // Subscribe to system events
            p3d.SubscribeToSystemEvent(EVENTS.SIM_START, "SimStart");
            p3d.SubscribeToSystemEvent(EVENTS.SIM_STOP, "SimStop");
            p3d.SubscribeToSystemEvent(EVENTS.SIM_PAUSE, "Pause");

            // Turn events on
            p3d.SetSystemEventState(EVENTS.SIM_START, SIMCONNECT_STATE.ON);
            p3d.SetSystemEventState(EVENTS.SIM_STOP, SIMCONNECT_STATE.ON);
            p3d.SetSystemEventState(EVENTS.SIM_PAUSE, SIMCONNECT_STATE.ON);

            // SimConnect variables
            p3d.AddToDataDefinition(VARIABLES.ON_GROUND, "SIM ON GROUND", "Bool", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
            p3d.RequestDataOnSimObject(EVENTS.RECEIVE_DATA, VARIABLES.ON_GROUND, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD.SECOND, 0, 0, 0, 0);

            Console.WriteLine("SimConnect initialized");
        }
Ejemplo n.º 2
0
        // Set up all the SimConnect related event handlers
        private void initSystemEvent()
        {
            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);

                // listen to events
                simconnect.OnRecvEvent     += new SimConnect.RecvEventEventHandler(simconnect_OnRecvEvent);
                simconnect.OnRecvEventText += new SimConnect.RecvEventTextEventHandler(simconnect_OnTextEvent);

                // Subscribe to system events
                simconnect.SubscribeToSystemEvent(EVENTS.FOURSECS, "4sec");
                simconnect.SubscribeToSystemEvent(EVENTS.SIMSTART, "SimStart");
                simconnect.SubscribeToSystemEvent(EVENTS.SIMSTOP, "SimStop");

                // use with TextMenu sample to show an example of listening for text events
                simconnect.SubscribeToSystemEvent(EVENTS.TEXTWINDOW, "TextEventCreated");

                // Initially turn the events off
                simconnect.SetSystemEventState(EVENTS.FOURSECS, SIMCONNECT_STATE.OFF);
                simconnect.SetSystemEventState(EVENTS.SIMSTART, SIMCONNECT_STATE.OFF);
                simconnect.SetSystemEventState(EVENTS.SIMSTOP, SIMCONNECT_STATE.OFF);
            }
            catch (COMException ex)
            {
                displayText(ex.Message);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Attempt to create the SimConnect connection with Prepar3D.
        /// </summary>
        private bool PollForConnection()
        {
            int retryCounter = 1000;

            while (SimConnect == null && retryCounter > 0)
            {
                try
                {
                    SimConnect = new SimConnect("Managed Scenario Controller", IntPtr.Zero, 0, null, 0);
                    if (SimConnect != null)
                    {
                        SimConnect.OnRecvOpen  += new LockheedMartin.Prepar3D.SimConnect.SimConnect.RecvOpenEventHandler(SimConnect_OnRecvOpen);
                        SimConnect.OnRecvQuit  += new LockheedMartin.Prepar3D.SimConnect.SimConnect.RecvQuitEventHandler(SimConnect_OnRecvQuit);
                        SimConnect.OnRecvEvent += new LockheedMartin.Prepar3D.SimConnect.SimConnect.RecvEventEventHandler(SimConnect_OnRecvEvent);

                        // Subscribe to system events
                        SimConnect.SubscribeToSystemEvent(EventIdentifier.MissionCompleted, "MissionCompleted");

                        // Turn the events on
                        SimConnect.SetSystemEventState(EventIdentifier.MissionCompleted, SIMCONNECT_STATE.ON);
                    }
                }
                catch
                {
                }

                if (SimConnect == null)
                {
                    Thread.Sleep(500);
                    --retryCounter;
                }
            }

            return(retryCounter > 0);
        }
Ejemplo n.º 4
0
 // Request events mission completed, sim stop and, application quit events from simConnect so we can take focus
 private void initFocusGrab()
 {
     try
     {
         closeFocusGrab();
         simconnect              = new SimConnect("Launcher SimConnect Interface", this.Handle, WM_USER_SIMCONNECT, null, 0);
         simconnect.OnRecvQuit  += new SimConnect.RecvQuitEventHandler(simconnect_OnRecvQuit);
         simconnect.OnRecvEvent += new SimConnect.RecvEventEventHandler(simconnect_OnRecvEvent);
         simconnect.SubscribeToSystemEvent(Event.MISSION_END, MISSION_COMPLETED);
         simconnect.SetSystemEventState(Event.MISSION_END, SIMCONNECT_STATE.ON);
     }
     catch //if the app has not started yet this will throw
     {
         closeFocusGrab();
     }
 }
Ejemplo n.º 5
0
        private void initDataRequest()
        {
            try
            {
                simconnect.OnRecvOpen += new SimConnect.RecvOpenEventHandler(simconnect_OnRecvOpen);
                simconnect.OnRecvQuit += new SimConnect.RecvQuitEventHandler(simconnect_OnRecvQuit);

                simconnect.OnRecvException += new SimConnect.RecvExceptionEventHandler(simconnect_OnRecvError);

                //simconnect.AddToDataDefinition(DEFINITIONS.StructMapData, "title", null, SIMCONNECT_DATATYPE.STRING256, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                //simconnect.AddToDataDefinition(DEFINITIONS.StructMapData, "Plane Altitude", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.StructMapData, "Plane Latitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.StructMapData, "Plane Longitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.StructMapData, "PLANE HEADING DEGREES TRUE", "Radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

                simconnect.RegisterDataDefineStruct <StructMapData>(DEFINITIONS.StructMapData);

                simconnect.OnRecvSimobjectDataBytype += new SimConnect.RecvSimobjectDataBytypeEventHandler(simconnect_OnRecvSimobjectDataByType);
                simconnect.OnRecvSimobjectData       += new SimConnect.RecvSimobjectDataEventHandler(simconnect_OnRecvSimObjectData);
                simconnect.OnRecvSystemState         += new SimConnect.RecvSystemStateEventHandler(simconnect_OnRecvSystemState);

                simconnect.OnRecvEvent         += new SimConnect.RecvEventEventHandler(simconnect_OnRecvEvent);
                simconnect.OnRecvEventFilename += new SimConnect.RecvEventFilenameEventHandler(simconnect_OnRecvEventFilename);

                simconnect.SubscribeToSystemEvent(EVENTS.SIM_START, "SimStart");
                simconnect.SubscribeToSystemEvent(EVENTS.SIM_STOP, "SimStop");
                simconnect.SubscribeToSystemEvent(EVENTS.FLIGHTPLAN_LOADED, "FlightPlanActivated");
                simconnect.SubscribeToSystemEvent(EVENTS.FLIGHTPLAN_DIACTIVATED, "FlightPlanDeactivated");

                simconnect.SetSystemEventState(EVENTS.SIM_START, SIMCONNECT_STATE.ON);
                simconnect.SetSystemEventState(EVENTS.SIM_STOP, SIMCONNECT_STATE.ON);
                simconnect.SetSystemEventState(EVENTS.FLIGHTPLAN_LOADED, SIMCONNECT_STATE.OFF);
                simconnect.SetSystemEventState(EVENTS.FLIGHTPLAN_DIACTIVATED, SIMCONNECT_STATE.OFF);
            }
            catch (COMException ex)
            {
                OnError(this, ex);
            }
        }
Ejemplo n.º 6
0
        // Set up all the SimConnect related data definitions and event handlers
        private void initDataRequest()
        {
            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);

                // map the data structure to ESP's Simulation Variables
                // there are more than 200 variables that are available to be queried and/or set via SimConnect
                // define & register PositionData, used for LLAPBH updates on Sim Objects
                simconnect.AddToDataDefinition(DEFINITIONS.PositionData_Definition,
                                               "Plane Latitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionData_Definition,
                                               "Plane Longitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionData_Definition,
                                               "Plane Altitude", "meters", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionData_Definition,
                                               "Plane Pitch Degrees", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionData_Definition,
                                               "Plane Bank Degrees", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionData_Definition,
                                               "Plane Heading Degrees True", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionData_Definition,
                                               "Plane Heading Degrees True", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionData_Definition,
                                               "Ground Velocity", "knots", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionData_Definition,
                                               "NAV ACTIVE FREQUENCY:1", "Mhz", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionData_Definition,
                                               "NAV STANDBY FREQUENCY:1", "Mhz", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionData_Definition,
                                               "NAV ACTIVE FREQUENCY:2", "Mhz", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionData_Definition,
                                               "NAV STANDBY FREQUENCY:2", "Mhz", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionData_Definition,
                                               "TRANSPONDER CODE:1", "Mhz", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

                // IMPORTANT: register it with the simconnect managed wrapper marshaller
                // if you skip this step, you will only receive a uint in the .dwData field.
                simconnect.RegisterDataDefineStruct <PositionData>(DEFINITIONS.PositionData_Definition);

                // define & register AircraftData, used for info about Sim Objects
                simconnect.AddToDataDefinition(DEFINITIONS.AI_Entity_Definition,
                                               "IS USER SIM", "Bool", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AI_Entity_Definition,
                                               "CATEGORY", null, SIMCONNECT_DATATYPE.STRING256, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AI_Entity_Definition,
                                               "ATC TYPE", null, SIMCONNECT_DATATYPE.STRING32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AI_Entity_Definition,
                                               "ATC MODEL", null, SIMCONNECT_DATATYPE.STRING32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AI_Entity_Definition,
                                               "ATC ID", null, SIMCONNECT_DATATYPE.STRING32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AI_Entity_Definition,
                                               "ATC AIRLINE", null, SIMCONNECT_DATATYPE.STRING64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AI_Entity_Definition,
                                               "ATC FLIGHT NUMBER", null, SIMCONNECT_DATATYPE.STRING8, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AI_Entity_Definition,
                                               "TITLE", null, SIMCONNECT_DATATYPE.STRING256, 0.0f, SimConnect.SIMCONNECT_UNUSED);

                simconnect.RegisterDataDefineStruct <AI_Entity_Details>(DEFINITIONS.AI_Entity_Definition);

                // setup various data requests
                simconnect.SubscribeToSystemEvent(DATA_REQUESTS.REQUEST_AI_ADDED, "ObjectAdded");
                simconnect.SubscribeToSystemEvent(DATA_REQUESTS.REQUEST_AI_REMOVED, "ObjectRemoved");

                // enable the notifications of the above system events
                simconnect.SetSystemEventState(DATA_REQUESTS.REQUEST_AI_ADDED, SIMCONNECT_STATE.ON);
                simconnect.SetSystemEventState(DATA_REQUESTS.REQUEST_AI_REMOVED, SIMCONNECT_STATE.ON);

                // catch simobject data requests
                simconnect.OnRecvEventObjectAddremove +=
                    new SimConnect.RecvEventObjectAddremoveEventHandler(SimConnect_OnRecvEventObjectAddremove);
                simconnect.OnRecvSimobjectData +=
                    new SimConnect.RecvSimobjectDataEventHandler(SimConnect_OnRecvSimobjectData);
                simconnect.OnRecvSimobjectDataBytype +=
                    new SimConnect.RecvSimobjectDataBytypeEventHandler(SimConnect_OnRecvSimobjectDataBytype);

                // Initialize the list with current aircraft
                simconnect.RequestDataOnSimObjectType(DATA_REQUESTS.REQUEST_AI_OBJECT_ID_BYTYPE,
                                                      DEFINITIONS.AI_Entity_Definition, MONITOR_RADIUS, SIMCONNECT_SIMOBJECT_TYPE.AIRCRAFT);
            }
            catch (COMException ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// See interface docs.
 /// </summary>
 /// <param name="eventId"></param>
 /// <param name="on"></param>
 public void SetSystemEventState(Enum eventId, bool on)
 {
     _SimConnect.SetSystemEventState(eventId, on ? SIMCONNECT_STATE.ON : SIMCONNECT_STATE.OFF);
 }
Ejemplo n.º 8
0
        // Set up all the SimConnect related data definitions and event handlers
        private void initDataRequest()
        {
            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);

                // listen to events
                simconnect.OnRecvEvent += new SimConnect.RecvEventEventHandler(simconnect_OnRecvEvent);

                // Subscribe to system events
                simconnect.SubscribeToSystemEvent(EVENTS.SIMSTART, "SimStart");
                simconnect.SubscribeToSystemEvent(EVENTS.SIMSTOP, "SimStop");
                simconnect.SubscribeToSystemEvent(EVENTS.PAUSED, "Paused");
                simconnect.SubscribeToSystemEvent(EVENTS.UNPAUSED, "Unpaused");

                simconnect.SetSystemEventState(EVENTS.SIMSTART, SIMCONNECT_STATE.ON);
                simconnect.SetSystemEventState(EVENTS.SIMSTOP, SIMCONNECT_STATE.ON);
                simconnect.SetSystemEventState(EVENTS.PAUSED, SIMCONNECT_STATE.ON);
                simconnect.SetSystemEventState(EVENTS.UNPAUSED, SIMCONNECT_STATE.ON);


                // define a data structure

                // Struct 1
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "PLANE ALT ABOVE GROUND", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Altitude", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "INCIDENCE ALPHA", "Radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "VELOCITY BODY X", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "VELOCITY BODY Y", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "VELOCITY BODY Z", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "VELOCITY WORLD X", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "VELOCITY WORLD Y", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "VELOCITY WORLD Z", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "ROTATION VELOCITY BODY X", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "ROTATION VELOCITY BODY Y", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "ROTATION VELOCITY BODY Z", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "RELATIVE WIND VELOCITY BODY X", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "RELATIVE WIND VELOCITY BODY Y", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "RELATIVE WIND VELOCITY BODY Z", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "AMBIENT WIND X", "Meters per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "AMBIENT WIND Y", "Meters per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "AMBIENT WIND Z", "Meters per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "ACCELERATION BODY X", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "ACCELERATION BODY Y", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "ACCELERATION BODY Z", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "PLANE PITCH DEGREES", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "PLANE BANK DEGREES", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "PLANE HEADING DEGREES MAGNETIC", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "RUDDER POSITION", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "ELEVATOR POSITION", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "AILERON POSITION", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "FLAPS HANDLE INDEX", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "SPOILERS HANDLE POSITION", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);

                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "GENERAL ENG RPM:1", "rpm", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "General Eng Throttle Lever Position:1", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);


                // Struct 2
                simconnect.AddToDataDefinition(DEFINITIONS.Struct2, "title", null, SIMCONNECT_DATATYPE.STRING256, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct2, "AMBIENT DENSITY", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct2, "AMBIENT TEMPERATURE", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct2, "AMBIENT PRESSURE", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct2, "SEA LEVEL PRESSURE", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct2, "GEAR POSITION", "enum", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.Struct2, "FUEL TOTAL QUANTITY WEIGHT", "Pounds", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);

                // IMPORTANT: register it with the simconnect managed wrapper marshaller
                // if you skip this step, you will only receive a uint in the .dwData field.
                simconnect.RegisterDataDefineStruct <Struct1>(DEFINITIONS.Struct1);
                simconnect.RegisterDataDefineStruct <Struct2>(DEFINITIONS.Struct2);


                // catch a simobject data request
                simconnect.OnRecvSimobjectData += new SimConnect.RecvSimobjectDataEventHandler(simconnect_OnRecvSimobjectData);
            }
            catch (COMException ex)
            {
                displayText(ex.Message);
            }
        }