/// <summary> /// Will stop the Message Handler from running, thereby ignoring all events from SimConnect /// </summary> public static void Disconnect() { WriteLog("Start Disconnect()"); StopMessagePump(); // Raise event to notify client we've disconnected SimConnect_OnRecvQuit(simConnect, null); simConnect?.Dispose(); // May have already been disposed or not even been created, e.g. Disconnect called before Connect simConnect = null; WriteLog("End Disconnect()"); }
private void CloseSimConnect() { if (_simConnectThread != null) { try { _simConnectThread.Abort(); } catch { } _simConnectThread = null; } if (_simconnect != null) { _simconnect.Dispose(); _simconnect = null; } }
public void DisconnectSim() { if (simconnect != null) { OnFSConnectionStatusChanged(false); if (!simExited) { simconnect.UnsubscribeFromSystemEvent(EVENTS.SIM_START); simconnect.UnsubscribeFromSystemEvent(EVENTS.SIM_STOP); simconnect.UnsubscribeFromSystemEvent(EVENTS.FLIGHTPLAN_LOADED); simconnect.UnsubscribeFromSystemEvent(EVENTS.FLIGHTPLAN_DIACTIVATED); } simconnect.Dispose(); simconnect = null; } SimConnected = false; }
public void Disconnect(String message = "Disconnected from SimConnect", bool isUnexpected = false) { simConnect?.Dispose(); simConnect = null; flightData.ClearData(); OnConnectionStatusChange(this, new SimConnectEventArgs(isUnexpected ? ConnectionEventType.Abnormal_Disconnect : ConnectionEventType.Neutral, message)); if (isUnexpected) { waitUntil = DateTime.Now.AddMilliseconds(500); Connect(handlePtr); } else { simConnectPoller.Stop(); handlePtr = IntPtr.Zero; } }
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; } } }
public void Disconnect() { logger.LogInformation("Cleaning up SimConnect client..."); // Destroy client if (api != null) { // Try cleaning up before disposing client try { api.ClearDataDefinition(DATA_DEFINITON_ID.UserPosition); logger.LogDebug("Cleaned up client data definitions."); } catch { logger.LogWarning("Unable to clean up data definitions. Skipping to client disposal."); } // Dispose client api.Dispose(); api = null; } logger.LogInformation("SimConnect client cleaned up."); }
public void Disconnect() { Console.WriteLine("Disconnect"); _timer.Stop(); OddTick = false; if (_simConnect != null) { /// Dispose serves the same purpose as SimConnect_Close() _simConnect.Dispose(); _simConnect = null; } ConnectButtonLabel = "Connect"; Connected = false; // Set all requests as pending SimVarsViewModel.ResetAllRequests(); }
static void Main(string[] args) { try { SimConnect simulation_connection = new SimConnect("Managed Change Vehicle", IntPtr.Zero, 0, null, 0); // Sending the title of the Vehicle simulation_connection.ChangeVehicle("Mooney Bravo Retro"); simulation_connection.Dispose(); simulation_connection = null; } catch (Exception ex) { // We were unable to connect so let the user know why. System.Console.WriteLine("Sim Connect unable to connect to Prepar3D!\n\n{0}\n\n{1}", ex.Message, ex.StackTrace); } }
public void CloseConnection() { try { cts?.Cancel(); cts = null; } catch (Exception) { } try { if (simconnect != null) { simconnect.Dispose(); simconnect = null; } } catch (Exception) { } }
private void Disconnect() { ClientData clientData = new ClientData() { IsConnected = false }; _wsConnector.Clients.All.SendAsync("ReceiveData", clientData); if (simconnect == null) { return; } cancellationToken.Cancel(); simconnect.Dispose(); simconnect = null; _logger.LogInformation("SimConnect was disconnected from the flight sim."); }
private void Disconnect() { if (m_oSimConnect != null) { Console.WriteLine("Disconnected"); cmdToggleContent = "Disconnected"; // Dispose serves the same purpose as SimConnect_Close() m_oSimConnect.Dispose(); m_oSimConnect = null; } //sConnectButtonLabel = "Connect"; //bConnected = false; //// Set all requests as pending //foreach (SimvarRequest oSimvarRequest in lSimvarRequests) //{ // oSimvarRequest.bPending = true; // oSimvarRequest.bStillPending = true; //} }
public void CloseConnection() { try { logger.LogDebug("Trying to cancel request loop"); cts?.Cancel(); cts = null; } catch (Exception ex) { logger.LogWarning(ex, $"Cannot cancel request loop! Error: {ex.Message}"); } try { // Dispose serves the same purpose as SimConnect_Close() simconnect?.Dispose(); simconnect = null; } catch (Exception ex) { logger.LogWarning(ex, $"Cannot unsubscribe events! Error: {ex.Message}"); } }
public void Disconnect() { Console.WriteLine("Disconnect"); bOddTick = false; if (m_oSimConnect != null) { /// Dispose serves the same purpose as SimConnect_Close() m_oSimConnect.Dispose(); m_oSimConnect = null; } sConnectButtonLabel = "Connect"; bConnected = false; // Set all requests as pending foreach (SimvarRequest oSimvarRequest in lSimvarRequests) { oSimvarRequest.bPending = true; oSimvarRequest.bStillPending = true; } }
private void btnClose_Click(object sender, RoutedEventArgs e) { try { // Save position Properties.Settings.Default.WindowTop = Top; Properties.Settings.Default.WindowLeft = Left; Properties.Settings.Default.Save(); // Stop _timer.Stop(); _connectTimer.Stop(); if (_simConnectionStatus) { _simClient.Dispose(); } _listener.UnHookKeyboard(); } catch (Exception) { } Close(); }