Beispiel #1
0
        // Set up all the SimConnect related event handlers
        private void initClientEvent()
        {
            try
            {
                // listen to connect and quit msgs
                simconnect.OnRecvOpen      += new SimConnect.RecvOpenEventHandler(simconnect_OnRecvOpen);
                simconnect.OnRecvQuit      += new SimConnect.RecvQuitEventHandler(simconnect_OnRecvQuit);
                simconnect.OnRecvException += new SimConnect.RecvExceptionEventHandler(simconnect_OnRecvException);
                simconnect.OnRecvEvent     += new SimConnect.RecvEventEventHandler(simconnect_OnRecvEvent);

                //Subscribe to events. Used to trigger data requests.
                simconnect.MapClientEventToSimEvent(EVENTS.AP_MASTER, "AP_MASTER");
                simconnect.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENTS.AP_MASTER, false);

                //Data request definitions. These are used when when we receive events.
                simconnect.AddToDataDefinition(DEFINITION.MCP, "Autopilot Master", "Boolean", SIMCONNECT_DATATYPE.INT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

                simconnect.RegisterDataDefineStruct <MCP>(DEFINITION.MCP);

                simconnect.OnRecvSimobjectDataBytype += new SimConnect.RecvSimobjectDataBytypeEventHandler(simconnect_OnRecvSimobjectDataBytype);

                // set the group priority
                simconnect.SetNotificationGroupPriority(NOTIFICATION_GROUPS.GROUP0, SimConnect.SIMCONNECT_GROUP_PRIORITY_HIGHEST);
            }
            catch (COMException ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Beispiel #2
0
        private void InitClientEvent()
        {
            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);
                // set the group priority
                simconnect.SetNotificationGroupPriority(NOTIFICATION_GROUPS.GROUP0, SimConnect.SIMCONNECT_GROUP_PRIORITY_HIGHEST);
                // add event
                foreach (CLIENT_EVENTS ce in Enum.GetValues(typeof(CLIENT_EVENTS)))
                {
                    addSimEvent(ce);
                }

                RegistDefine();
                // catch a simobject data request
                simconnect.OnRecvSimobjectDataBytype += new SimConnect.RecvSimobjectDataBytypeEventHandler(simconnect_OnRecvSimobjectDataBytype);
            }
            catch (COMException ex)
            {
                this.Log(ex.Message);
            }
        }
        public bool Connect()
        {
            Console.WriteLine("Connect SimConnect");

            try {
                _simConnect = new SimConnect("Touch Portal Plugin", GetConsoleWindow(), WM_USER_SIMCONNECT, _scReady, 0);

                _connected = true;

                // System Events
                _simConnect.OnRecvOpen      += new SimConnect.RecvOpenEventHandler(simconnect_OnRecvOpen);
                _simConnect.OnRecvQuit      += new SimConnect.RecvQuitEventHandler(simconnect_OnRecvQuit);
                _simConnect.OnRecvException += new SimConnect.RecvExceptionEventHandler(simconnect_OnRecvException);

                // Sim mapped events
                _simConnect.OnRecvEvent += new SimConnect.RecvEventEventHandler(simconnect_OnRecvEvent);

                // simconnect.OnRecvAssignedObjectId += new SimConnect.RecvAssignedObjectIdEventHandler(simconnect_OnRecvAssignedObjectId);

                // Sim Data
                _simConnect.OnRecvSimobjectData       += new SimConnect.RecvSimobjectDataEventHandler(simconnect_OnRecvSimObjectData);
                _simConnect.OnRecvSimobjectDataBytype += new SimConnect.RecvSimobjectDataBytypeEventHandler(simconnect_OnRecvSimobjectDataBytype);

                _simConnect.ClearNotificationGroup(Groups.System);
                _simConnect.SetNotificationGroupPriority(Groups.System, NOTIFICATION_PRIORITY);

                _simConnect.ClearNotificationGroup(Groups.AutoPilot);
                _simConnect.SetNotificationGroupPriority(Groups.AutoPilot, NOTIFICATION_PRIORITY);

                _simConnect.ClearNotificationGroup(Groups.Fuel);
                _simConnect.SetNotificationGroupPriority(Groups.Fuel, NOTIFICATION_PRIORITY);

                _simConnect.Text(SIMCONNECT_TEXT_TYPE.PRINT_BLACK, 5, Events.StartupMessage, "TouchPortal Connected");

                // Invoke Handler
                OnConnect();

                return(true);
            } catch (COMException ex) {
                Console.WriteLine("Connection to Sim failed: " + ex.Message);
            }

            return(false);
        }
Beispiel #4
0
        /// <summary>
        /// Registers a data object with the SimConnect management class
        /// </summary>
        /// <param name="sim"></param>
        public static void RegisterDataObjects(SimConnect sim)
        {
            // Define the data structure from FSX
            sim.AddToDataDefinition(DEFINITIONS.AircraftDataStruct, "Title", null, SIMCONNECT_DATATYPE.STRING256, 0.0f, SimConnect.SIMCONNECT_UNUSED);

            sim.AddToDataDefinition(DEFINITIONS.AircraftDataStruct, "PLANE LATITUDE", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
            sim.AddToDataDefinition(DEFINITIONS.AircraftDataStruct, "PLANE LONGITUDE", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
            sim.AddToDataDefinition(DEFINITIONS.AircraftDataStruct, "INDICATED ALTITUDE", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

            sim.AddToDataDefinition(DEFINITIONS.AircraftDataStruct, "Plane Pitch Degrees", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
            sim.AddToDataDefinition(DEFINITIONS.AircraftDataStruct, "Plane Heading Degrees True", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
            sim.AddToDataDefinition(DEFINITIONS.AircraftDataStruct, "Plane Bank Degrees", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

            sim.AddToDataDefinition(DEFINITIONS.AircraftDataStruct, "Velocity Body Z", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
            sim.AddToDataDefinition(DEFINITIONS.AircraftDataStruct, "Velocity Body X", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
            sim.AddToDataDefinition(DEFINITIONS.AircraftDataStruct, "Velocity Body Y", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

            sim.AddToDataDefinition(DEFINITIONS.AircraftDataStruct, "Rotation Velocity Body Z", "radians per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
            sim.AddToDataDefinition(DEFINITIONS.AircraftDataStruct, "Rotation Velocity Body X", "radians per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
            sim.AddToDataDefinition(DEFINITIONS.AircraftDataStruct, "Rotation Velocity Body Y", "radians per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

            sim.AddToDataDefinition(DEFINITIONS.AircraftDataStruct, "Airspeed Mach", "Mach", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
            sim.AddToDataDefinition(DEFINITIONS.AircraftDataStruct, "INCIDENCE BETA", "Radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

            // Define the data structure to FSX
            sim.AddToDataDefinition(DEFINITIONS.ControlDataStruct, "AILERON POSITION", "Position", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
            sim.AddToDataDefinition(DEFINITIONS.ControlDataStruct, "ELEVATOR POSITION", "Position", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
            sim.AddToDataDefinition(DEFINITIONS.ControlDataStruct, "RUDDER POSITION", "Position", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
            sim.AddToDataDefinition(DEFINITIONS.ControlDataStruct, "GENERAL ENG THROTTLE LEVER POSITION:1", "Percent", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
            sim.AddToDataDefinition(DEFINITIONS.ControlDataStruct, "GENERAL ENG THROTTLE LEVER POSITION:2", "Percent", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
            sim.AddToDataDefinition(DEFINITIONS.ControlDataStruct, "GENERAL ENG THROTTLE LEVER POSITION:3", "Percent", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
            sim.AddToDataDefinition(DEFINITIONS.ControlDataStruct, "GENERAL ENG THROTTLE LEVER POSITION:4", "Percent", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
            //sim.AddToDataDefinition(DEFINITIONS.ControlDataStruct, "SPOILERS HANDLE POSITION", "Percent", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

            // Register data objects with the simconnect managed wrapper marshaller
            sim.RegisterDataDefineStruct <AircraftDataStructure>(DEFINITIONS.AircraftDataStruct);
            sim.RegisterDataDefineStruct <ControlDataStructure>(DEFINITIONS.ControlDataStruct);

            // Map Events
            sim.MapClientEventToSimEvent(EVENTS.FLAPS0, "FLAPS_UP");
            sim.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENTS.FLAPS0, false);

            sim.MapClientEventToSimEvent(EVENTS.FLAPS1, "FLAPS_1");
            sim.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENTS.FLAPS1, false);

            sim.MapClientEventToSimEvent(EVENTS.FLAPS2, "FLAPS_2");
            sim.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENTS.FLAPS2, false);

            sim.MapClientEventToSimEvent(EVENTS.GEAR_DOWN, "GEAR_DOWN");
            sim.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENTS.GEAR_DOWN, false);

            sim.MapClientEventToSimEvent(EVENTS.GEAR_UP, "GEAR_UP");
            sim.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENTS.GEAR_UP, false);

            sim.SetNotificationGroupPriority(NOTIFICATION_GROUPS.GROUP0, SimConnect.SIMCONNECT_GROUP_PRIORITY_HIGHEST);
        }
Beispiel #5
0
 private void InitDataRequest()
 {
     try
     {
         simconnect.SetNotificationGroupPriority(GROUPS.GroupA, SimConnect.SIMCONNECT_GROUP_PRIORITY_HIGHEST);
         foreach (var field in enabledFields)
         {
             InitSimConnectField(field);
         }
     }
     catch (COMException ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Beispiel #6
0
        static void Main()
        {
            simConnect = new SimConnect("SimConnectTest", GetConsoleWindow(), WM_USER_SIMCONNECT, null, 0);

            simConnect.MapClientEventToSimEvent(Events.EventSteerAileron, "AILERON_SET");
            simConnect.AddClientEventToNotificationGroup(NotificationGroups.Group0, Events.EventSteerAileron, false);

            simConnect.SetNotificationGroupPriority(NotificationGroups.Group0, SimConnect.SIMCONNECT_GROUP_PRIORITY_HIGHEST);

            while (true)
            {
                Thread.Sleep(50);
                int d = (int)(Math.Sin((DateTime.Now - DateTime.Today).TotalSeconds / 2) * 16000);
                simConnect.TransmitClientEvent(0, Events.EventSteerAileron, (uint)d, NotificationGroups.Group0, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
            }
        }
Beispiel #7
0
        // Set up all the SimConnect related event handlers
        private void initClientEvent()
        {
            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 pitot heat switch toggle
                simconnect.MapClientEventToSimEvent(EVENTS.PITOT_TOGGLE, "PITOT_HEAT_TOGGLE");
                simconnect.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENTS.PITOT_TOGGLE, false);

                // subscribe to all four flaps controls
                simconnect.MapClientEventToSimEvent(EVENTS.FLAPS_UP, "FLAPS_UP");
                simconnect.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENTS.FLAPS_UP, false);
                simconnect.MapClientEventToSimEvent(EVENTS.FLAPS_DOWN, "FLAPS_DOWN");
                simconnect.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENTS.FLAPS_DOWN, false);
                simconnect.MapClientEventToSimEvent(EVENTS.FLAPS_INC, "FLAPS_INCR");
                simconnect.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENTS.FLAPS_INC, false);
                simconnect.MapClientEventToSimEvent(EVENTS.FLAPS_DEC, "FLAPS_DECR");
                simconnect.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENTS.FLAPS_DEC, false);

                // set the group priority
                simconnect.SetNotificationGroupPriority(NOTIFICATION_GROUPS.GROUP0, SimConnect.SIMCONNECT_GROUP_PRIORITY_HIGHEST);

            }
            catch (COMException ex)
            {
                displayText(ex.Message);
            }
        }
Beispiel #8
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (simconnect == null)
            {
                try
                {
                    simconnect = new SimConnect("FSX Glidertow", this.Handle, WM_USER_SIMCONNECT, null, 0);

                    #region Handlers
                    simconnect.OnRecvSimobjectData       += new SimConnect.RecvSimobjectDataEventHandler(simconnect_OnRecvSimObjectData);
                    simconnect.OnRecvSimobjectDataBytype += new SimConnect.RecvSimobjectDataBytypeEventHandler(simconnect_OnRecvSimObjectByTypeData);
                    simconnect.OnRecvEvent += new SimConnect.RecvEventEventHandler(simconnect_OnRecvEvent);
                    #endregion

                    #region Subscribe to tow request and release
                    simconnect.MapClientEventToSimEvent(EVENTS.EVENT_TOWPLANE_DETACHED, "TOW_PLANE_RELEASE");
                    simconnect.MapClientEventToSimEvent(EVENTS.EVENT_TOWPLANE_REQUESTED, "TOW_PLANE_REQUEST");
                    simconnect.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENTS.EVENT_TOWPLANE_DETACHED, false);
                    simconnect.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENTS.EVENT_TOWPLANE_REQUESTED, true);
                    simconnect.SetNotificationGroupPriority(NOTIFICATION_GROUPS.GROUP0, SimConnect.SIMCONNECT_GROUP_PRIORITY_HIGHEST);
                    #endregion

                    #region Get info when AI spawns
                    simconnect.OnRecvEventObjectAddremove += new SimConnect.RecvEventObjectAddremoveEventHandler(simconnect_OnRecvEventObjectAddremove);
                    simconnect.OnRecvAssignedObjectId     += new SimConnect.RecvAssignedObjectIdEventHandler(simconnect_OnRecvAssignedObjectId);

                    #endregion

                    #region DataDefinition AirplaneData
                    simconnect.AddToDataDefinition(DEFINITIONS.AirplaneData, "Title", null, SIMCONNECT_DATATYPE.STRING256, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                    simconnect.AddToDataDefinition(DEFINITIONS.AirplaneData, "Plane Latitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                    simconnect.AddToDataDefinition(DEFINITIONS.AirplaneData, "Plane Longitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                    simconnect.AddToDataDefinition(DEFINITIONS.AirplaneData, "Plane Altitude", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                    simconnect.AddToDataDefinition(DEFINITIONS.AirplaneData, "PLANE BANK DEGREES", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                    simconnect.AddToDataDefinition(DEFINITIONS.AirplaneData, "PLANE HEADING DEGREES TRUE", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                    simconnect.AddToDataDefinition(DEFINITIONS.AirplaneData, "PLANE PITCH DEGREES", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                    simconnect.AddToDataDefinition(DEFINITIONS.AirplaneData, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                    simconnect.RegisterDataDefineStruct <AirplaneData>(DEFINITIONS.AirplaneData);
                    #endregion

                    /*
                     #region DataDefinition AIData
                     * simconnect.AddToDataDefinition(DEFINITIONS.AIData, "Title", null, SIMCONNECT_DATATYPE.STRING256, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                     * simconnect.AddToDataDefinition(DEFINITIONS.AIData, "Plane Latitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                     * simconnect.AddToDataDefinition(DEFINITIONS.AIData, "Plane Longitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                     * simconnect.AddToDataDefinition(DEFINITIONS.AIData, "Plane Altitude", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                     * simconnect.AddToDataDefinition(DEFINITIONS.AIData, "PLANE BANK DEGREES", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                     * simconnect.AddToDataDefinition(DEFINITIONS.AIData, "PLANE HEADING DEGREES TRUE", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                     * simconnect.AddToDataDefinition(DEFINITIONS.AIData, "PLANE PITCH DEGREES", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                     * simconnect.AddToDataDefinition(DEFINITIONS.AIData, "AI DESIRED SPEED ", "knots", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                     * simconnect.RegisterDataDefineStruct<AIData>(DEFINITIONS.AIData);
                     #endregion
                     * //*/

                    #region Misc
                    button1.Text    = "Disconnect from FSX";
                    button2.Enabled = true;
                    #endregion

                    //simconnect.AICreateParkedATCAircraft("Extra 300S", "ABCD", "EDDS", EVENTS.EVENT_TOWPLANE_REQUESTED);
                }
                catch
                {
                    MessageBox.Show("Could not connect to FSX");
                    button1.Text    = "Connect to FSX";
                    button2.Enabled = false;
                    button3.Enabled = false;
                }
            }
            else
            {
                disconnect();
            }
        }
 private void OnOpenHandler(SimConnect sender, SIMCONNECT_RECV_OPEN data)
 {
     m_oSimConnect.SetNotificationGroupPriority(NOTIFICATION_GROUPS.Group0, SimConnect.SIMCONNECT_GROUP_PRIORITY_HIGHEST);
 }