private void RegisterEnvironmentDataDefinition() { simconnect.AddToDataDefinition(DEFINITIONS.EnvironmentData, "LOCAL TIME", "seconds", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.EnvironmentData, "ZULU TIME", "seconds", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.EnvironmentData, "ABSOLUTE TIME", "seconds", SIMCONNECT_DATATYPE.INT64, 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 <EnvironmentDataStruct>(DEFINITIONS.EnvironmentData); }
private void RegisterAircraftDataDefinition() { simconnect.AddToDataDefinition(DEFINITIONS.AircraftData, "ATC TYPE", null, SIMCONNECT_DATATYPE.STRING32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.AircraftData, "ATC MODEL", null, SIMCONNECT_DATATYPE.STRING32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.AircraftData, "Title", null, SIMCONNECT_DATATYPE.STRING256, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.AircraftData, "ESTIMATED CRUISE SPEED", "Knots", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); // Register with the simconnect managed wrapper marshaller // Skipping, means you will only receive uint in the .dwData field simconnect.RegisterDataDefineStruct <AircraftDataStruct>(DEFINITIONS.AircraftData); }
private void RegisterSimVars() { if (m_simVarModelList != null && m_oSimConnect != null) { foreach (var simVar in m_simVarModelList) { if (string.IsNullOrEmpty(simVar.UnitysName)) // Strings { m_oSimConnect.AddToDataDefinition(SimVarsEnum.TITLE, simVar.DataName, null, SIMCONNECT_DATATYPE.STRING256, 0, SimConnect.SIMCONNECT_UNUSED); } else { m_oSimConnect.AddToDataDefinition(SimVarsEnum.TITLE, simVar.DataName, simVar.UnitysName, SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); } } for (int i = 1; i <= 15; i++) { m_oSimConnect.AddToDataDefinition(SimVarsEnum.TOTAL_PAYLOAD, $"PAYLOAD STATION WEIGHT:{i}", "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. m_oSimConnect.RegisterDataDefineStruct <SimVarsStruct>(SimVarsEnum.TITLE); m_oSimConnect.RegisterDataDefineStruct <SimVarsPayloadStruct>(SimVarsEnum.TOTAL_PAYLOAD); //m_oSimConnect.WeatherRequestObservationAtStation(SimVarsEnum.WEATHER_INFO, "LOWW"); //m_oSimConnect.WeatherRequestObservationAtNearestStation(SimVarsEnum.WEATHER_INFO, 48.117680599757485f, 16.566300032290759f); } }
void Connect() { try { // Создаем контроллер обрабоки данных и выбираем данные, которые необходимо получать от сима. simConn = new SimConnect("MFSDataGrabber", this.Handle, WM_USER_SIMCONNECT, null, 0); simConn.AddToDataDefinition(DATA_STRUCT_ENUM.Plane, "Plane Heading Degrees True", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simConn.AddToDataDefinition(DATA_STRUCT_ENUM.Plane, "Indicated Altitude", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simConn.AddToDataDefinition(DATA_STRUCT_ENUM.Plane, "AIRSPEED TRUE", "Knots", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simConn.AddToDataDefinition(DATA_STRUCT_ENUM.Plane, "GPS ETA", "Seconds", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simConn.AddToDataDefinition(DATA_STRUCT_ENUM.Plane, "GPS ETE", "Seconds", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simConn.AddToDataDefinition(DATA_STRUCT_ENUM.Plane, "Rotation Velocity Body Y", "feet per second", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simConn.AddToDataDefinition(DATA_STRUCT_ENUM.World, "AMBIENT WIND VELOCITY", "Knots", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simConn.AddToDataDefinition(DATA_STRUCT_ENUM.World, "SIMULATION RATE", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simConn.RegisterDataDefineStruct <Plane>(DATA_STRUCT_ENUM.Plane); simConn.RegisterDataDefineStruct <World>(DATA_STRUCT_ENUM.World); simConn.OnRecvSimobjectDataBytype += OnResiveData; simConnectStatus = true; DataUpdateTimer.Interval = 1500; DataUpdateTimer.Start(); ConnectStatusChange(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
// 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); // define a data structure simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Title", null, SIMCONNECT_DATATYPE.STRING256, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Latitude", "degrees", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Longitude", "degrees", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Altitude", "meters", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Pitch Degrees", "degrees", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Bank Degrees", "degrees", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Heading Degrees Magnetic", "degrees", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Heading Degrees True", "degrees", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Ground Velocity", "meters per second", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Indicated Altitude", "meters", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "GPS Ground True Heading", "degrees", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Airspeed Indicated", "meters per second", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "VELOCITY WORLD X", "meters per second", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "VELOCITY WORLD Y", "meters per second", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "VELOCITY WORLD Z", "meters per second", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "ROTATION VELOCITY BODY Z", "radians per second", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "ROTATION VELOCITY BODY X", "radians per second", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "ROTATION VELOCITY BODY Y", "radians per second", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "GENERAL ENG ELAPSED TIME:1", "hours", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.StructAil, "Aileron Position", "Position", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.StructEle, "Elevator Position", "Position", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.StructThrottle, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.StructThrottle, "GENERAL ENG THROTTLE LEVER POSITION:2", "percent", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.StructThrottle, "GENERAL ENG THROTTLE LEVER POSITION:3", "percent", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.StructThrottle, "GENERAL ENG THROTTLE LEVER POSITION:4", "percent", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.StructRudder, "Rudder Position", "Position", SIMCONNECT_DATATYPE.FLOAT32, 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 <Struct1>(DEFINITIONS.Struct1); simconnect.RegisterDataDefineStruct <Struct1>(DEFINITIONS.StructAil); simconnect.RegisterDataDefineStruct <Struct1>(DEFINITIONS.StructEle); simconnect.RegisterDataDefineStruct <Struct1>(DEFINITIONS.StructThrottle); simconnect.RegisterDataDefineStruct <Struct1>(DEFINITIONS.StructRudder); // catch a simobject data request simconnect.OnRecvSimobjectDataBytype += new SimConnect.RecvSimobjectDataBytypeEventHandler(simconnect_OnRecvSimobjectDataBytype); simconnect.OnRecvSimobjectData += new SimConnect.RecvSimobjectDataEventHandler(simconnect_OnRecvSimobjectData); } catch (COMException ex) { displayText(ex.Message); } }
/// <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); }
public void Connect() { handle = new WindowInteropHelper(Application.Current.MainWindow).Handle; handleSource = HwndSource.FromHwnd(handle); // Get source of handle in order to add event handlers to it handleSource.AddHook(HandleSimConnectEvents); if (sc == null) { try { sc = new SimConnect(appName, handle, WM_USER_SIMCONNECT, null, 0); sc.OnRecvOpen += sc_OnRecvOpen; sc.OnRecvException += sc_OnRecvException; sc.OnRecvQuit += sc_OnRecvQuit; sc.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Latitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); sc.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Longitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); sc.RegisterDataDefineStruct<Struct1>(DEFINITIONS.Struct1); sc.OnRecvSimobjectDataBytype += sc_OnRecvSimobjectData; } catch (Exception ex) { Console.WriteLine("Unable to connect to Sim"); } refreshTimer.Elapsed += (sender, e) => { sc.RequestDataOnSimObjectType(DATA_REQUESTS.REQUEST_1, DEFINITIONS.Struct1, 0, SIMCONNECT_SIMOBJECT_TYPE.USER); }; refreshTimer.Start(); } }
// 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); } }
/// <summary> /// ウィンドウが表示されたときのイベント /// </summary> private void Window_Loaded(object sender, RoutedEventArgs e) { try { simconnect = new SimConnect("Managed Data Request", this.Handle, WM_USER_SIMCONNECT, null, 0); /// 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); /// Catch a simobject data request simconnect.OnRecvSimobjectData += SimConnect_OnRecvSimobjectData; simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Title", null, SIMCONNECT_DATATYPE.STRING256, 0, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "ATTITUDE INDICATOR PITCH DEGREES", "Radians", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "ATTITUDE INDICATOR BANK DEGREES", "Radians", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); simconnect.RegisterDataDefineStruct <Struct1>(DEFINITIONS.Struct1); simconnect.RequestDataOnSimObject(REQUEST.Dummy, DEFINITIONS.Struct1, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD.SIM_FRAME, SIMCONNECT_DATA_REQUEST_FLAG.DEFAULT, 0, 0, 0); } catch (COMException ex) { MessageBox.Show("シミュレーターに接続出来ませんでした。\n終了します。", "エラー", MessageBoxButton.OK, MessageBoxImage.Error); this.Close(); } }
public void Connect() { if (sc == null) { try { sc = new SimConnect("FSWebService Controller", form.Handle, WM_USER_SIMCONNECT, null, 0); sc.OnRecvOpen += OnRecvOpen; sc.OnRecvException += OnRecvException; sc.OnRecvQuit += OnRecvQuit; sc.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Latitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); sc.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Longitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); sc.RegisterDataDefineStruct <Struct1>(DEFINITIONS.Struct1); sc.OnRecvSimobjectDataBytype += OnRecvSimobjectDataByType; IsConnected = true; } catch (Exception ex) { Console.WriteLine("Unable to connect to Sim"); // form.AddText("Unable to connect to Sim"); return; } pollingTimer.Elapsed += (sender, e) => { sc.RequestDataOnSimObjectType(DATA_REQUESTS.REQUEST_1, DEFINITIONS.Struct1, 0, SIMCONNECT_SIMOBJECT_TYPE.USER); }; pollingTimer.Start(); } }
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); // define a data structure simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "title", null, SIMCONNECT_DATATYPE.STRING256, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Latitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Longitude", "degrees", 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, "Airspeed Indicated", "knots", 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 <Struct1>(DEFINITIONS.Struct1); // NearestVorCurrentICAO // catch a simobject data request simconnect.OnRecvSimobjectDataBytype += new SimConnect.RecvSimobjectDataBytypeEventHandler(simconnect_OnRecvSimobjectDataBytype); } catch (COMException ex) { } }
// Set up the SimConnect event handlers private void initComms() { 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); // catch the assigned object IDs simconnect.OnRecvAssignedObjectId += new SimConnect.RecvAssignedObjectIdEventHandler(simconnect_OnRecvAssignedObjectId); // set up the data definiton for the Maule lights simconnect.AddToDataDefinition(DEFINITIONS.MauleLights, "LIGHT STATES", "mask", SIMCONNECT_DATATYPE.INT32, 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 <MauleLights>(DEFINITIONS.MauleLights); // Subscribe to system event Pause simconnect.SubscribeToSystemEvent(EVENTS.PAUSED, "Pause"); simconnect.OnRecvEvent += new SimConnect.RecvEventEventHandler(simconnect_OnRecvEvent); // Map an event to the EventID: PAUSE_OFF simconnect.MapClientEventToSimEvent(EVENTS.SEND_UNPAUSE, "PAUSE_OFF"); } catch (COMException ex) { displayText(ex.Message); } }
public void Connect() { try { m_oSimConnect = new SimConnect("Arduino", m_hWnd, WM_USER_SIMCONNECT, null, 0); /// Catch a simobject data request m_oSimConnect.OnRecvEvent += new SimConnect.RecvEventEventHandler(OnRecvEventHandler); m_oSimConnect.OnRecvOpen += new SimConnect.RecvOpenEventHandler(OnOpenHandler); m_oSimConnect.OnRecvException += new SimConnect.RecvExceptionEventHandler(OnRecvExceptionHandler); m_oSimConnect.OnRecvSimobjectDataBytype += new SimConnect.RecvSimobjectDataBytypeEventHandler(OnRecvSimobjectDataBytype); m_oSimConnect.AddToDataDefinition(DEFINITION.LedStatus, "AUTOPILOT MASTER", "Bool", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); m_oSimConnect.AddToDataDefinition(DEFINITION.LedStatus, "AUTOPILOT NAV1 LOCK", "Bool", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); m_oSimConnect.AddToDataDefinition(DEFINITION.LedStatus, "AUTOPILOT GLIDESLOPE HOLD", "Bool", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); m_oSimConnect.AddToDataDefinition(DEFINITION.LedStatus, "AUTOPILOT NAV1 LOCK", "Bool", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); m_oSimConnect.AddToDataDefinition(DEFINITION.LedStatus, "AUTOPILOT APPROACH HOLD", "Bool", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); m_oSimConnect.AddToDataDefinition(DEFINITION.LedStatus, "AUTOPILOT GLIDESLOPE HOLD", "Bool", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); m_oSimConnect.RegisterDataDefineStruct <Data>(DEFINITION.LedStatus); m_oSimConnect.RequestDataOnSimObjectType(REQUEST.Dummy, DEFINITION.LedStatus, 0, SIMCONNECT_SIMOBJECT_TYPE.USER); isConnected = true; Log("Connected"); Console.WriteLine("Connected"); } catch (COMException ex) { Console.WriteLine("Connection to KH failed: " + ex.Message); } }
public void Connect() { // Connect to FS try { // neue simconnect verbindung aufbauen // event management für open _mySimconnect.OnRecvOpen += simconnect_OnRecvOpen; // event management für close _mySimconnect.OnRecvQuit += simconnect_OnRecvQuit; _mySimconnect.OnRecvAssignedObjectId += mySimconnect_OnRecvAssignedObjectId; // abfragedaten zur verbindung hinzufügen _mySimconnect.AddToDataDefinition(Definitions.StructCoordinates, "Plane Latitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); _mySimconnect.AddToDataDefinition(Definitions.StructCoordinates, "Plane Longitude", "degrees", 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. _mySimconnect.RegisterDataDefineStruct <StructCoordinates>(Definitions.StructCoordinates); // catch a simobject data request _mySimconnect.OnRecvSimobjectDataBytype += simconnect_OnRecvSimobjectDataBytype; _mySimconnect.RequestDataOnSimObjectType(DataRequests.Request_1, Definitions.StructCoordinates, 0, SIMCONNECT_SIMOBJECT_TYPE.USER); _connectionStatus = ConnectionStatus.Connected; } catch (COMException ex) { // A connection to the SimConnect server could not be established _connectionStatus = ConnectionStatus.Pending; Disconnect(); throw new Exception(Resources.SimConnection_Error + ex.Message); } }
private void Connect() { try { if (_simConnectionStatus) { return; } WindowInteropHelper lWih = new WindowInteropHelper(System.Windows.Application.Current.MainWindow); IntPtr lHwnd = lWih.Handle; gHs = HwndSource.FromHwnd(lHwnd); gHs.AddHook(new HwndSourceHook(WndProc)); _simClient = new SimConnect("Pushback Helper", lHwnd, 0x402, null, 0); // Sim connect configurations _simClient.OnRecvOpen += SimClient_OnRecvOpen; _simClient.OnRecvQuit += SimClient_OnRecvQuit; _simClient.OnRecvException += SimClient_OnRecvException; _simClient.AddToDataDefinition(DefinitionsEnum.HeadingDataStruct, "Plane Heading Degrees True", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); _simClient.RegisterDataDefineStruct <HeadingDataStruct>(DefinitionsEnum.HeadingDataStruct); _simClient.OnRecvSimobjectDataBytype += SimClient_OnRecvSimobjectDataBytype; // _simConnectionStatus = true; SetConnectionText(); _timer.Start(); } catch (Exception) { _simConnectionStatus = false; lblSimStatus.Content = "ERROR!"; } }
// Set up all the SimConnect related data definitions and event handlers // Recebe todoas as variaveis da aeronave e guarda em suas variaveis 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); // define a data structure simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "PLANE PITCH DEGREES", "degrees", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "PLANE BANK DEGREES", "degrees", SIMCONNECT_DATATYPE.INT32, 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); // catch a simobject data request simconnect.OnRecvSimobjectDataBytype += new SimConnect.RecvSimobjectDataBytypeEventHandler(simconnect_OnRecvSimobjectDataBytype); } catch (COMException ex) { displayText(ex.Message); } }
private void SetupEvents() { try { simConnect.OnRecvOpen += simConnect_OnRecvOpen; simConnect.OnRecvQuit += new SimConnect.RecvQuitEventHandler(simConnect_OnRecvQuit); simConnect.OnRecvException += new SimConnect.RecvExceptionEventHandler(simConnect_OnRecvException); simConnect.AddToDataDefinition(DEFINITIONS.DataStructure, "AIRSPEED TRUE", "knots", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simConnect.AddToDataDefinition(DEFINITIONS.DataStructure, "PLANE ALTITUDE", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simConnect.AddToDataDefinition(DEFINITIONS.DataStructure, "GPS POSITION LAT", "degrees latitude", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simConnect.AddToDataDefinition(DEFINITIONS.DataStructure, "GPS POSITION LON", "degrees longitude", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simConnect.AddToDataDefinition(DEFINITIONS.DataStructure, "PLANE HEADING DEGREES MAGNETIC", "degrees", 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 <DataStructure>(DEFINITIONS.DataStructure); // catch a simobject data request simConnect.OnRecvSimobjectDataBytype += simConnect_OnRecvSimobjectDataBytype; } catch (COMException) { Console.WriteLine("Encountered an Exception whilst connecting to sim"); } }
// SIMCONNECT private void Connect() { try { if (_simConnectionStatus) { return; } _simClient = new SimConnect("Pushback Helper", Handle, 0x402, null, 0); // Sim connect configurations _simClient.OnRecvOpen += SimClient_OnRecvOpen; _simClient.OnRecvQuit += SimClient_OnRecvQuit; _simClient.OnRecvException += SimClient_OnRecvException; _simClient.AddToDataDefinition(DefinitionsEnum.HeadingDataStruct, "Plane Heading Degrees True", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); _simClient.RegisterDataDefineStruct <HeadingDataStruct>(DefinitionsEnum.HeadingDataStruct); _simClient.OnRecvSimobjectDataBytype += SimClient_OnRecvSimobjectDataBytype; // _simConnectionStatus = true; SimConnectionStatusChangedEvents(); _timer.Start(); } catch (Exception ex) { _simConnectionStatus = false; MessageBox.Show(ex.Message); } SimConnectionStatusChangedEvents(); }
void connect() { const int WM_USER_SIMCONNECT = 0x0402; connection = new SimConnect("simmaps", IntPtr.Zero, WM_USER_SIMCONNECT, null, 0); connection.AddToDataDefinition(DEFINITIONS.SimData, "Plane Altitude", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); connection.AddToDataDefinition(DEFINITIONS.SimData, "Plane Latitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); connection.AddToDataDefinition(DEFINITIONS.SimData, "Plane Longitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); connection.AddToDataDefinition(DEFINITIONS.SimData, "Plane Heading Degrees True", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); connection.RegisterDataDefineStruct <SimData>(DEFINITIONS.SimData); connection.OnRecvSimobjectData += new SimConnect.RecvSimobjectDataEventHandler(simconnect_OnRecvSimobjectData); connection.OnRecvEvent += new SimConnect.RecvEventEventHandler(simconnect_OnRecvEvent); connection.SubscribeToSystemEvent(DEFINITIONS.SimStart, "SimStart"); requestData(); Terminal.WriteLine("Connected to Flight Simulator", ConsoleColor.Green); while (true) { connection.ReceiveMessage(); Thread.Sleep(10); //not a bottleneck } }
void connect() { try { simconnect = new SimConnect("Managed Data Request", this.Handle, WM_USER_SIMCONNECT, null, 0); simconnect.MapClientEventToSimEvent(PAUSE_EVENTS.PAUSE, "PAUSE_ON"); simconnect.MapClientEventToSimEvent(PAUSE_EVENTS.UNPAUSE, "PAUSE_OFF"); simconnect.MapClientEventToSimEvent(PAUSE_EVENTS.GEAR_UP, "GEAR_UP"); simconnect.MapClientEventToSimEvent(PAUSE_EVENTS.GEAR_DOWN, "GEAR_DOWN"); simconnect.MapClientEventToSimEvent(PAUSE_EVENTS.THROTTLE_SET, "THROTTLE_SET"); simconnect.MapClientEventToSimEvent(PAUSE_EVENTS.THROTTLE_FULL, "THROTTLE_FULL"); simconnect.AddToDataDefinition(DEFINITIONS.Control1, "RUDDER POSITION", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Control1, "ELEVATOR POSITION", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Control1, "AILERON POSITION", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Control1, "FLAPS HANDLE INDEX", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Control1, "SPOILERS HANDLE POSITION", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Control1, "General Eng Throttle Lever Position:1", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.Control1, "General Eng Throttle Lever Position:2", "", 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 <Control1>(DEFINITIONS.Control1); // catch a simobject data request simconnect.OnRecvSimobjectData += new SimConnect.RecvSimobjectDataEventHandler(simconnect_OnRecvSimobjectData); } catch (COMException ex) { Console.WriteLine(ex); } }
public void RegisterGenericValues(bool wasEmpty) { if (simconnect == null) { return; } if (!wasEmpty) { logger.LogInformation("Clearing Data definition"); simconnect.ClearDataDefinition(DEFINITIONS.GenericData); } foreach (TOGGLE_VALUE simValue in genericValues) { string value = simValue.ToString().Replace("__", ":").Replace("_", " "); logger.LogInformation("RegisterValue {1} {2}", simValue, value); simconnect?.AddToDataDefinition( DEFINITIONS.GenericData, value, eventLib.GetUnit(simValue), SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED ); } simconnect?.RegisterDataDefineStruct <GenericValuesStruct>(DEFINITIONS.GenericData); }
private void Sim_OnRecvOpen(SimConnect sender, SIMCONNECT_RECV_OPEN data) { connectionLed.Fill = Brushes.Green; /// Define a data structure sim.AddToDataDefinition((DEFINITION)1, "PLANE LATITUDE", "degree", 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. sim.RegisterDataDefineStruct <double>((DEFINITION)1); /// Define a data structure sim.AddToDataDefinition((DEFINITION)2, "PLANE LONGITUDE", "degree", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); sim.RegisterDataDefineStruct <double>((DEFINITION)2); sim.AddToDataDefinition((DEFINITION)3, "PLANE HEADING DEGREES TRUE", "degree", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); sim.RegisterDataDefineStruct <double>((DEFINITION)3); }
private void RegisterStruct <TData>(Enum definition) { foreach (var field in typeof(TData).GetFields(BindingFlags.Instance | BindingFlags.Public)) { var attr = field.GetCustomAttributes <SimLinkAttribute>().First(); m_simConnect.AddToDataDefinition(definition, attr.Name, attr.Type, attr.Type == null ? SIMCONNECT_DATATYPE.STRING256 : SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); } m_simConnect.RegisterDataDefineStruct <TData>(definition); }
/// <summary> /// Register a Struct in SimConnect that corresponds to a SIMVAR_CATEGORY and return the Struct's type. /// </summary> /// <param name="sc">SimConnect instance to register the struct.</param> /// <param name="cat">SIMVAR_CATEGORY that corresponds to the struct to be registered.</param> /// <returns></returns> private static Type SimConnectRegisterDataDefineStruct(SimConnect sc, SIMVAR_CATEGORY cat) { Type retType = null; // Switch the variable categories // Get the fields from the corresponding struct to // set up the simulation variables to be monitored. // Finally, register the struct to the simconnect instance. switch (cat) { case SIMVAR_CATEGORY.ENGINE_DATA: retType = typeof(EngineDataStruct); sc.RegisterDataDefineStruct <EngineDataStruct>(cat); break; case SIMVAR_CATEGORY.AIRCRAFT_MISCELANEOUS: retType = typeof(AircraftMiscelaneousDataStruct); sc.RegisterDataDefineStruct <AircraftMiscelaneousDataStruct>(cat); break; case SIMVAR_CATEGORY.CONTROLS: retType = typeof(AircraftControlsDataStruct); sc.RegisterDataDefineStruct <AircraftControlsDataStruct>(cat); break; case SIMVAR_CATEGORY.FLIGHT_INSTRUMENTATION: retType = typeof(AircraftFlightInstrumentationData); sc.RegisterDataDefineStruct <AircraftFlightInstrumentationData>(cat); break; case SIMVAR_CATEGORY.LANDING_GEAR: retType = typeof(AircraftLandingGearDataStruct); sc.RegisterDataDefineStruct <AircraftLandingGearDataStruct>(cat); break; case SIMVAR_CATEGORY.CREW_INPUT_VARIABLE: case SIMVAR_CATEGORY.OTHER: // The category CREW_INPUT_VARIABLE and OTHER is not registered in simconnect. // The data for this struct is obtained directly from the crew. break; } return(retType); }
private void ConnectButton_Click(object sender, RoutedEventArgs e) { if (!connectedToSim) { try { simConnect = new SimConnect("Managed Data Request", handle, WM_USER_SIMCONNECT, null, 0); } catch (COMException ex) { ConnectButton.Content = "Error connecting"; Console.WriteLine("ERROR CONNECTING TO SIMCONNECT: " + ex.ToString()); } if (simConnect != null) { /// 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); /// Catch a simobject data request //simConnect.OnRecvSimobjectDataBytype += new SimConnect.RecvSimobjectDataBytypeEventHandler(SimConnect_OnRecvSimobjectDataBytype); //set up the data definitions and things simConnect.AddToDataDefinition(DEFINITIONS.PlaneThrottle, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simConnect.AddToDataDefinition(DEFINITIONS.PlaneThrottle, "GENERAL ENG THROTTLE LEVER POSITION:2", "percent", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simConnect.RegisterDataDefineStruct <StructPlaneThrottle>(DEFINITIONS.PlaneThrottle); simConnect.AddToDataDefinition(DEFINITIONS.PlanePitchYaw, "ELEVATOR POSITION:1", "percent", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simConnect.AddToDataDefinition(DEFINITIONS.PlanePitchYaw, "AILERON POSITION:1", "percent", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simConnect.RegisterDataDefineStruct <StructPlanePitchYaw>(DEFINITIONS.PlanePitchYaw); } } else { if (simConnect != null) { continuePolling = false; simConnect.Dispose(); simConnect = null; } } }
void createRegister(SimVar temp) { if (!temp.isEvent) { simconnect.AddToDataDefinition(temp.eDef, temp.sName, temp.sUnits, SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.RegisterDataDefineStruct <double>(temp.eDef); } lSimVars.Add(temp); }
public void Register(SimConnect connection) { // Per P3D documentation, if the variable is a string, then the unit should be left empty string unit = simValue.IsString ? "" : Unit; // Define a new structure for this variable connection.AddToDataDefinition(Id, Name, unit, SimConnectType, 0.0f, SimConnect.SIMCONNECT_UNUSED); // Register it with the SimConnect managed marshaller to allow data fetch connection.RegisterDataDefineStruct <T>(Id); }
public bool RegisterToSimConnect(SimVarItem simVar) { if (_connected) { _simConnect.AddToDataDefinition(simVar.def, simVar.SimVarName, simVar.Unit, SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); _simConnect.RegisterDataDefineStruct <double>(simVar.def); return(true); } return(false); }
public bool RegisterToSimConnect(SimVarItem simVar) { if (_connected) { if (simVar.Unit == Units.String) { _simConnect.AddToDataDefinition(simVar.Def, simVar.SimVarName, null, SIMCONNECT_DATATYPE.STRING64, 0.0f, SimConnect.SIMCONNECT_UNUSED); _simConnect.RegisterDataDefineStruct <StringVal64>(simVar.Def); } else { _simConnect.AddToDataDefinition(simVar.Def, simVar.SimVarName, simVar.Unit, SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED); _simConnect.RegisterDataDefineStruct <double>(simVar.Def); } return(true); } return(false); }
private void RegisterPlaneStatusDefinition() { simconnect.AddToDataDefinition(DEFINITIONS.PlaneStatus, "LIGHT BEACON", "bool", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.PlaneStatus, "LIGHT LANDING", "bool", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.PlaneStatus, "LIGHT TAXI", "bool", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.PlaneStatus, "LIGHT NAV", "bool", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.PlaneStatus, "LIGHT STROBE", "bool", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.PlaneStatus, "GENERAL ENG MASTER ALTERNATOR:1", "Bool", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.PlaneStatus, "ELECTRICAL MASTER BATTERY", "Bool", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.AddToDataDefinition(DEFINITIONS.PlaneStatus, "AVIONICS MASTER SWITCH", "Bool", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.RegisterDataDefineStruct <PlaneStatusStruct>(DEFINITIONS.PlaneStatus); }
static void Main(string[] args) { try { //Création d'une instance pour acceder à la librairie simconnect //m_scConnection = new Microsoft.FlightSimulator.SimConnect.SimConnect("FFSTracker", base.Handle, WM_USER_SIMCONNECT, null, 0); m_scConnection = new SimConnect("FSXML", IntPtr.Zero, WM_USER_SIMCONNECT, null, 0); Console.WriteLine("La connexion au simulateur a réussie"); } catch { Console.WriteLine("La connexion à FS à échouée."); return; } // On map les event avec notre enumérateur foreach (EventEnum item in Enum.GetValues(typeof(EventEnum))) { m_scConnection.MapClientEventToSimEvent(item, item.ToString()); } //On map les variables avec notre structure m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Title", "", SIMCONNECT_DATATYPE.STRING256, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Plane Latitude", "degrees latitude", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Plane Longitude", "degrees longitude", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Plane Altitude", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Airspeed Indicated", "knots", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Plane Heading Degrees Magnetic", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Plane Heading Degrees True", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Com Active Frequency:1", "MHz", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Com Active Frequency:2", "MHz", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Com Standby Frequency:1", "MHz", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Com Standby Frequency:2", "MHz", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Nav Active Frequency:1", "MHz", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Nav Active Frequency:2", "MHz", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Nav Standby Frequency:1", "MHz", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Nav Standby Frequency:2", "MHz", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Autopilot Master", "", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Autopilot Approach Hold", "", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Autopilot Heading Lock", "", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Autopilot Heading Lock Dir", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Autopilot Altitude Lock", "", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Autopilot Altitude Lock Var", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Autopilot Vertical Hold Var", "feet/minute", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Autopilot Throttle Arm", "", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Autopilot Airspeed Hold", "", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Autopilot Airspeed Hold Var", "knots", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Autopilot Nav1 Lock", "", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Gps Drives Nav1", "", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Number Of Engines", "", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "General Eng Throttle Lever Position:1", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "General Eng Throttle Lever Position:2", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "General Eng Throttle Lever Position:3", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "General Eng Throttle Lever Position:4", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Flaps Handle Percent", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Gear Handle Position", "", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Spoilers Armed", "", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Spoilers Handle Position", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Brake Left Position", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "Brake Right Position", "", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "APU GENERATOR SWITCH", "", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "APU_GENERATOR_ACTIVE", "", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED); m_scConnection.AddToDataDefinition(DEFINITIONS.PERIODIQUE, "TOGGLE_MASTER_BATTERY", "", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED); // On associe notre structure à la définition simconnect m_scConnection.RegisterDataDefineStruct<DonneesAvion>(DEFINITIONS.PERIODIQUE); m_scConnection.OnRecvException += new SimConnect.RecvExceptionEventHandler(OnRecvException); m_scConnection.OnRecvQuit += new SimConnect.RecvQuitEventHandler(OnRecvQuit); m_scConnection.OnRecvSimobjectData += new SimConnect.RecvSimobjectDataEventHandler(OnRecvSimobjectData); //On programme la requete cyclique pour l'obtention des données de l'avion m_scConnection.RequestDataOnSimObject(DATA_REQUESTS.REQUEST_1, DEFINITIONS.PERIODIQUE, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD.SECOND, 0, 0, 0, 0); Timer timer = new Timer(); timer.Interval = 1000; timer.AutoReset = true; timer.Elapsed += new ElapsedEventHandler(OnTimer); timer.Start(); listener = new HttpListener(); listener.Prefixes.Add("http://+:8000/"); Console.WriteLine("Listening.."); listener.Start(); while (!quit) { // Note: The GetContext method blocks while waiting for a request. HttpListenerContext context = listener.GetContext(); HttpListenerRequest request = context.Request; // Obtain a response object. HttpListenerResponse response = context.Response; // Construct a response. if ((request.RawUrl == "/cmd") && (request.HttpMethod == "POST") && request.HasEntityBody && request.ContentType == "application/json") { var sr = new System.IO.StreamReader(request.InputStream, request.ContentEncoding); var code = sr.ReadToEnd(); Console.WriteLine(code); var deserializer = new JavaScriptSerializer(); var json = deserializer.Deserialize<commande>(code); Console.WriteLine(json.cmd + " : " + json.param); json.cmd = json.cmd.ToUpper(); Byte[] Bytes = BitConverter.GetBytes(Convert.ToInt32(json.param)); UInt32 Param = BitConverter.ToUInt32(Bytes, 0); try { m_scConnection.TransmitClientEvent(0, (EventEnum)Enum.Parse(typeof(EventEnum), json.cmd), Param, GROUP.GROUP1, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY); } catch (Exception e) { Console.WriteLine("La requete simconnect a échouée :" + e.Message); } response.Close(); } else if (request.RawUrl == "/getall") { response.ContentType = "application/json"; var serializer = new JavaScriptSerializer(); string json = serializer.Serialize(Donnees); byte[] buffer = System.Text.Encoding.UTF8.GetBytes(json); var output = response.OutputStream; output.Write(buffer, 0, buffer.Length); output.Close(); response.Close(); } else { response.StatusCode = 404; response.StatusDescription = "Not Found"; response.Close(); } } listener.Stop(); }