Пример #1
0
        private void OnRecvException(SimConnect sender, SIMCONNECT_RECV_EXCEPTION data)
        {
            var exceptionName = Enum.GetName(typeof(SIMCONNECT_EXCEPTION), data.dwException);

            log.Warning($"OnRecvException: {data.dwException} ({exceptionName}) {data.dwSendID} {data.dwIndex}");
            sc.Text(SIMCONNECT_TEXT_TYPE.PRINT_WHITE, 10.0f, Requests.DisplayText, $"{appName} SimConnect Exception: {data.dwException} ({exceptionName})");
        }
Пример #2
0
        void sc_OnRecvOpen(SimConnect sender, SIMCONNECT_RECV_OPEN data)
        {
            log.Info(string.Format("Connected to {0}\r\n    Simulator Version:\t{1}.{2}.{3}.{4}\r\n    SimConnect Version:\t{5}.{6}.{7}.{8}",
                                   data.szApplicationName, data.dwApplicationVersionMajor, data.dwApplicationVersionMinor, data.dwApplicationBuildMajor, data.dwApplicationBuildMinor,
                                   data.dwSimConnectVersionMajor, data.dwSimConnectVersionMinor, data.dwSimConnectBuildMajor, data.dwSimConnectBuildMinor));

            IsConnected = true;

#if DEBUG
            sc.SubscribeToSystemEvent(Events.AddObject, "ObjectAdded");
#endif
            sc.SubscribeToSystemEvent(Events.RemoveObject, "ObjectRemoved");

            sc.Text(SIMCONNECT_TEXT_TYPE.PRINT_WHITE, 5.0f, Requests.DisplayText, appName + " is connected to " + Encoding.UTF8.GetString(Encoding.Default.GetBytes(data.szApplicationName)));

            //sc.RequestDataOnUserSimObject(Requests.UserPosition, SIMCONNECT_PERIOD.SECOND, SIMCONNECT_DATA_REQUEST_FLAG.CHANGED, 0, 10, typeof(LatLon)); // Request user position every 10 seconds
            sc.RequestDataOnUserSimObject(Requests.UserPosition, SIMCONNECT_PERIOD.SECOND, SIMCONNECT_DATA_REQUEST_FLAG.CHANGED, typeof(LatLon));
        }
Пример #3
0
        private void SimConnect_RecvOpenHandler(SimConnect sender, SIMCONNECT_RECV_OPEN data)
        {
            // Show a message in the simulator to show that the connection succeeded
            sender.Text(SIMCONNECT_TEXT_TYPE.PRINT_WHITE, TEXT_DURATION, DummyEnum.Dummy,
                        "Flight Monitor is connected to this simulator instance.");
            LogMessage(SimConnectMessage.MessageStatus.Information,
                       "Received SimConnect open message: displaying notification.");

            // Register all variables with SimConnect
            foreach (ISimVariable v in Variables)
            {
                v.Register(sender);
            }

            // Now that variables are registered, we can start the timer
            timer.Start();
        }
        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);
        }
Пример #5
0
 public void Send(string message)
 {
     simconnect?.Text(SIMCONNECT_TEXT_TYPE.PRINT_BLACK, 3, EVENTS.MESSAGE_RECEIVED, message);
 }
Пример #6
0
 void sc_OnRecvException(SimConnect sender, SIMCONNECT_RECV_EXCEPTION data)
 {
     log.Warning(string.Format("OnRecvException: {0} ({1}) {2} {3}", data.dwException.ToString(), Enum.GetName(typeof(SIMCONNECT_EXCEPTION), data.dwException), data.dwSendID.ToString(), data.dwIndex.ToString()));
     sc.Text(SIMCONNECT_TEXT_TYPE.PRINT_WHITE, 10.0f, Requests.DisplayText, string.Format("{0} SimConnect Exception: {1} ({2})", appName, data.dwException.ToString(), Enum.GetName(typeof(SIMCONNECT_EXCEPTION), data.dwException)));
 }