### SimConnect CLI Examples Source: https://context7.com/patricksurry/pysimconnect/llms.txt Illustrates various commands for the `simconnect` command-line interface, including installing tab completion, searching for variables/events/units, getting and watching variable values, setting variable values, and sending events. ```bash # Install tab completion (PowerShell) simconnect --install-completion powershell # Search for variables, events, and units simconnect search altitude simconnect search --kind variable altitude simconnect search --kind event autopilot simconnect search --kind unit feet # Get variable values simconnect get PLANE_ALTITUDE simconnect get INDICATED_ALTITUDE --units meters simconnect get PLANE_LATITUDE PLANE_LONGITUDE # Watch variables over time simconnect watch INDICATED_ALTITUDE AIRSPEED_INDICATED simconnect watch PLANE_ALTITUDE --interval 2 # Set variable values simconnect set INDICATED_ALTITUDE 5000 simconnect set INDICATED_ALTITUDE 1500 --units meters # Send events simconnect send KOHLSMAN_INC simconnect send AP_MASTER simconnect send HEADING_BUG_SET 270 # Get help simconnect --help simconnect get --help ``` -------------------------------- ### Install pysimconnect Source: https://context7.com/patricksurry/pysimconnect/llms.txt Install the package using pip. ```bash pip install pysimconnect ``` -------------------------------- ### Send Event Example Source: https://github.com/patricksurry/pysimconnect/blob/master/examples/README.md A simple example demonstrating how to send an event using the simconnect package. ```python from pysimconnect import SimConnect, Event if __name__ == "__main__": with SimConnect() as sm: sm.open("My App") sm.send_event(Event.GEAR_UP) sm.send_event(Event.GEAR_DOWN) sm.close() ``` -------------------------------- ### Demo All Major Features Source: https://github.com/patricksurry/pysimconnect/blob/master/examples/README.md This example illustrates all major features of the simconnect package. It serves as a comprehensive demonstration. ```python from pysimconnect import SimConnect, Pegasus, Event def my_callback(simconnect_data): print(simconnect_data) if __name__ == "__main__": with SimConnect() as sm: sm.open("My App", my_callback) sm.set_datum(Pegasus.SIMVARS.BRAKE_ALL, 0.5) sm.send_event(Event.GEAR_UP) sm.send_event(Event.GEAR_DOWN) sm.subscribe_vars(Pegasus.SIMVARS.TITLE, Pegasus.SIMVARS.AIRSPEED_INDICATED, Pegasus.SIMVARS.PLANE_LATITUDE, Pegasus.SIMVARS.PLANE_LONGITUDE, Pegasus.SIMVARS.PLANE_ALTITUDE, Pegasus.SIMVARS.PLANE_HEADING_DEGREES_TRUE, Pegasus.SIMVARS.PLANE_PITCH_DEGREES, Pegasus.SIMVARS.PLANE_BANK_DEGREES, Pegasus.SIMVARS.MARKER_TEXT, Pegasus.SIMVARS.CAMERA_STATE) sm.request_data_by_period(Pegasus.SIMVARS.TITLE, Pegasus.SIMVARS.TITLE, 1000) sm.request_data_by_period(Pegasus.SIMVARS.AIRSPEED_INDICATED, Pegasus.SIMVARS.AIRSPEED_INDICATED, 1000) sm.request_data_by_period(Pegasus.SIMVARS.PLANE_LATITUDE, Pegasus.SIMVARS.PLANE_LATITUDE, 1000) sm.request_data_by_period(Pegasus.SIMVARS.PLANE_LONGITUDE, Pegasus.SIMVARS.PLANE_LONGITUDE, 1000) sm.request_data_by_period(Pegasus.SIMVARS.PLANE_ALTITUDE, Pegasus.SIMVARS.PLANE_ALTITUDE, 1000) sm.request_data_by_period(Pegasus.SIMVARS.PLANE_HEADING_DEGREES_TRUE, Pegasus.SIMVARS.PLANE_HEADING_DEGREES_TRUE, 1000) sm.request_data_by_period(Pegasus.SIMVARS.PLANE_PITCH_DEGREES, Pegasus.SIMVARS.PLANE_PITCH_DEGREES, 1000) sm.request_data_by_period(Pegasus.SIMVARS.PLANE_BANK_DEGREES, Pegasus.SIMVARS.PLANE_BANK_DEGREES, 1000) sm.request_data_by_period(Pegasus.SIMVARS.MARKER_TEXT, Pegasus.SIMVARS.MARKER_TEXT, 1000) sm.request_data_by_period(Pegasus.SIMVARS.CAMERA_STATE, Pegasus.SIMVARS.CAMERA_STATE, 1000) sm.call_dispatch() sm.close() ``` -------------------------------- ### Show SimConnect Version Source: https://github.com/patricksurry/pysimconnect/blob/master/examples/README.md A trivial low-level example demonstrating how to retrieve the result of the SDK Open() call. ```python from pysimconnect import SimConnect if __name__ == "__main__": with SimConnect() as sm: print(f"SimConnect SDK version: {sm.version()}") ``` -------------------------------- ### Set Datum Example Source: https://github.com/patricksurry/pysimconnect/blob/master/examples/README.md A simple example demonstrating how to set a datum value using the simconnect package. ```python from pysimconnect import SimConnect, Pegasus if __name__ == "__main__": with SimConnect() as sm: sm.open("My App") sm.set_datum(Pegasus.SIMVARS.BRAKE_ALL, 0.5) sm.close() ``` -------------------------------- ### Low-Level SDK Access Example Source: https://context7.com/patricksurry/pysimconnect/llms.txt Provides an example of direct access to SimConnect SDK functions for advanced use cases. This snippet shows how to define a data group, request data on the user's aircraft, and poll for results using GetNextDispatch. ```python from simconnect import ( SimConnect, ReceiverInstance, RECV_P, OBJECT_ID_USER, PERIOD_SECOND, DATA_REQUEST_FLAG_CHANGED, DATA_REQUEST_FLAG_TAGGED, DATATYPE_FLOAT64, RECV_SIMOBJECT_DATA ) from ctypes import byref, sizeof, cast, POINTER, c_double from ctypes.wintypes import DWORD from time import sleep with SimConnect(name='LowLevelExample') as sc: # Define a data group def_id = 0x1234 simvars = [ ("Kohlsman setting hg", "inHg"), ("Indicated Altitude", "feet"), ("Plane Latitude", "degrees"), ("Plane Longitude", "degrees"), ] # Add variables to data definition for i, (simvar, unit) in enumerate(simvars): sc.AddToDataDefinition(def_id, simvar, unit, DATATYPE_FLOAT64, 0, i) # Request data on the user's aircraft req_id = 0xFEED sc.RequestDataOnSimObject( req_id, def_id, OBJECT_ID_USER, PERIOD_SECOND, DATA_REQUEST_FLAG_CHANGED | DATA_REQUEST_FLAG_TAGGED, 0, # Skip periods 1, # Interval 0, # Repeat count (0 = forever) ) # Poll for results using GetNextDispatch pRecv = RECV_P() nSize = DWORD() while True: try: sc.GetNextDispatch(byref(pRecv), byref(nSize)) recv = ReceiverInstance.cast_recv(pRecv) if isinstance(recv, RECV_SIMOBJECT_DATA) and recv.dwRequestID == req_id: offset = RECV_SIMOBJECT_DATA.dwData.offset for _ in range(recv.dwDefineCount): idx = cast(byref(recv, offset), POINTER(DWORD))[0] offset += sizeof(DWORD) val = cast(byref(recv, offset), POINTER(c_double))[0] offset += sizeof(c_double) print(f"{simvars[idx][0]}: {val}") except OSError: sleep(0.5) # No message ready, wait and retry ``` -------------------------------- ### Monitor Simulation Metrics Source: https://github.com/patricksurry/pysimconnect/blob/master/examples/README.md Example of several low-level SDK calls to retrieve a group of simulation variables. ```python from pysimconnect import SimConnect, Pegasus if __name__ == "__main__": with SimConnect() as sm: sm.open("My App") sm.request_data_by_period(Pegasus.SIMVARS.TITLE, Pegasus.SIMVARS.TITLE, 1000) sm.request_data_by_period(Pegasus.SIMVARS.AIRSPEED_INDICATED, Pegasus.SIMVARS.AIRSPEED_INDICATED, 1000) sm.request_data_by_period(Pegasus.SIMVARS.PLANE_LATITUDE, Pegasus.SIMVARS.PLANE_LATITUDE, 1000) sm.request_data_by_period(Pegasus.SIMVARS.PLANE_LONGITUDE, Pegasus.SIMVARS.PLANE_LONGITUDE, 1000) sm.request_data_by_period(Pegasus.SIMVARS.PLANE_ALTITUDE, Pegasus.SIMVARS.PLANE_ALTITUDE, 1000) sm.request_data_by_period(Pegasus.SIMVARS.PLANE_HEADING_DEGREES_TRUE, Pegasus.SIMVARS.PLANE_HEADING_DEGREES_TRUE, 1000) sm.request_data_by_period(Pegasus.SIMVARS.PLANE_PITCH_DEGREES, Pegasus.SIMVARS.PLANE_PITCH_DEGREES, 1000) sm.request_data_by_period(Pegasus.SIMVARS.PLANE_BANK_DEGREES, Pegasus.SIMVARS.PLANE_BANK_DEGREES, 1000) sm.request_data_by_period(Pegasus.SIMVARS.MARKER_TEXT, Pegasus.SIMVARS.MARKER_TEXT, 1000) sm.request_data_by_period(Pegasus.SIMVARS.CAMERA_STATE, Pegasus.SIMVARS.CAMERA_STATE, 1000) sm.call_dispatch() sm.close() ``` -------------------------------- ### Subscribe to Variables Example Source: https://github.com/patricksurry/pysimconnect/blob/master/examples/README.md Demonstrates the pythonic wrapper for watching one or more variables over time. This is a higher-level abstraction compared to low-level implementations like monitor_metrics.py. ```python from pysimconnect import SimConnect, Pegasus def my_callback(simconnect_data): print(simconnect_data) if __name__ == "__main__": with SimConnect() as sm: sm.open("My App", my_callback) sm.subscribe_vars(Pegasus.SIMVARS.TITLE, Pegasus.SIMVARS.AIRSPEED_INDICATED, Pegasus.SIMVARS.PLANE_LATITUDE, Pegasus.SIMVARS.PLANE_LONGITUDE, Pegasus.SIMVARS.PLANE_ALTITUDE, Pegasus.SIMVARS.PLANE_HEADING_DEGREES_TRUE, Pegasus.SIMVARS.PLANE_PITCH_DEGREES, Pegasus.SIMVARS.PLANE_BANK_DEGREES, Pegasus.SIMVARS.MARKER_TEXT, Pegasus.SIMVARS.CAMERA_STATE) sm.call_dispatch() sm.close() ``` -------------------------------- ### Accessing SimVars, Events, and Units Constants Source: https://context7.com/patricksurry/pysimconnect/llms.txt Shows how to use the `SIMVARS`, `EVENTS`, `UNITS`, and `DIMENSIONS` dictionaries from the `simconnect` library to look up valid simulator variables, events, and measurement units. Includes examples of browsing and checking specific entries. ```python from simconnect import SIMVARS, EVENTS, UNITS, DIMENSIONS # Browse available simulator variables print(f"Total SimVars: {len(SIMVARS)}") for name, info in list(SIMVARS.items())[:5]: print(f" {name}: {info.get('description', '')[:60]}...") print(f" Units: {info.get('units', 'N/A')}, Settable: {info.get('settable', False)}") # Check if a variable exists and is settable var_name = "INDICATED ALTITUDE" if var_name in SIMVARS: var = SIMVARS[var_name] print(f"{var_name}: settable={var.get('settable')}, indexed={var.get('indexed')}") # Browse available events print(f"\nTotal Events: {len(EVENTS)}") for name in list(EVENTS.keys())[:5]: print(f" {name}") ``` -------------------------------- ### Call Dispatch with Callback Source: https://github.com/patricksurry/pysimconnect/blob/master/examples/README.md Example of how to poll for results with a callback function, which is only called when a message is available. ```python from pysimconnect import SimConnect, Event, Pegasus def my_callback(simconnect_data): print(simconnect_data) if __name__ == "__main__": with SimConnect() as sm: sm.call_dispatch(my_callback) sm.add_event_handler(Event.SIM_START, my_callback) sm.add_event_handler(Pegasus.PLANE_LOADED, my_callback) sm.open("My App", my_callback, 1) sm.call_dispatch() sm.close() ``` -------------------------------- ### Flight Monitor Application Example Source: https://context7.com/patricksurry/pysimconnect/llms.txt Monitors flight data and logs changes to a JSON file. Requires SimConnect, PERIOD_SECOND, and time.sleep. Logs altitude, speed, vertical speed, heading, latitude, longitude, and fuel quantity. ```python from simconnect import SimConnect, PERIOD_SECOND from time import sleep import json def flight_monitor(): """Monitor flight data and log changes to file""" flight_vars = [ dict(name="ATC ID"), dict(name="Indicated Altitude", units="feet", epsilon=10), dict(name="AIRSPEED INDICATED", units="knots", epsilon=1), dict(name="VERTICAL SPEED", units="feet per minute", epsilon=50), dict(name="PLANE HEADING DEGREES TRUE", units="degrees"), dict(name="Plane Latitude", units="degrees"), dict(name="Plane Longitude", units="degrees"), dict(name="FUEL TOTAL QUANTITY", units="gallons"), ] log_entries = [] def on_update(simdata): entry = { "altitude": simdata.get("Indicated Altitude", 0), "speed": simdata.get("AIRSPEED INDICATED", 0), "vspeed": simdata.get("VERTICAL SPEED", 0), "heading": simdata.get("PLANE HEADING DEGREES TRUE", 0), "lat": simdata.get("Plane Latitude", 0), "lon": simdata.get("Plane Longitude", 0), "fuel": simdata.get("FUEL TOTAL QUANTITY", 0), } log_entries.append(entry) print(f"Alt: {entry['altitude']:.0f}ft | " f"Spd: {entry['speed']:.0f}kts | " f"VS: {entry['vspeed']:+.0f}fpm | " f"Hdg: {entry['heading']:.0f}deg | " f"Fuel: {entry['fuel']:.1f}gal") with SimConnect(name='FlightMonitor') as sc: # Get initial aircraft identification aircraft_id = sc.get_simdatum("ATC ID") print(f"Monitoring aircraft: {aircraft_id}") print("-" * 70) # Subscribe to flight data datadef = sc.subscribe_simdata( flight_vars, period=PERIOD_SECOND, interval=1, callback=on_update ) print(f"Subscribed with units: {datadef.get_units()}") print("-" * 70) # Monitor for specified duration try: for _ in range(60): # Monitor for 60 seconds sc.receive(timeout_seconds=1) except KeyboardInterrupt: print("\nMonitoring stopped by user") # Save flight log with open("flight_log.json", "w") as f: json.dump(log_entries, f, indent=2) print(f"\nSaved {len(log_entries)} log entries to flight_log.json") if __name__ == "__main__": flight_monitor() ``` -------------------------------- ### Initialize SimConnect Class Source: https://context7.com/patricksurry/pysimconnect/llms.txt Create a connection to the SimConnect SDK. Recommended to use as a context manager for automatic connection closing. ```python from simconnect import SimConnect # Basic initialization sc = SimConnect() # With custom name and options sc = SimConnect( name='MyFlightApp', # Connection name shown in FS2020 dll_path='path/to/SimConnect.dll', # Custom DLL path (optional) poll_interval_seconds=0.05 # Polling interval for message queue ) # Using as context manager (recommended) with SimConnect(name='MyApp') as sc: altitude = sc.get_simdatum("Indicated Altitude") print(f"Current altitude: {altitude}") # Connection automatically closed on exit ``` -------------------------------- ### Build PySimConnect Package Source: https://github.com/patricksurry/pysimconnect/blob/master/README.md Commands to build the PySimConnect package for distribution. Ensure version is updated in setup.cfg before building. ```bash python3 -m build ``` -------------------------------- ### Subscribe to SimData with Callback Source: https://context7.com/patricksurry/pysimconnect/llms.txt Subscribe to variables and execute a callback function whenever data changes. Ensure you are continuously receiving messages to trigger the callback. ```python from simconnect import SimConnect, PERIOD_SECOND def on_data_changed(simdata): """Called whenever subscribed data changes""" altitude = simdata.get('Indicated Altitude', 0) speed = simdata.get('AIRSPEED INDICATED', 0) print(f"Altitude: {altitude:.0f} ft, Speed: {speed:.1f} kts") with SimConnect() as sc: # Subscribe with callback datadef = sc.subscribe_simdata( [ "Indicated Altitude", "AIRSPEED INDICATED", "VERTICAL SPEED", ], period=PERIOD_SECOND, interval=1, callback=on_data_changed # Called on each update ) # Keep receiving messages to trigger callbacks while True: sc.receive(timeout_seconds=1) ``` -------------------------------- ### Write Multiple Simulator Variables Source: https://context7.com/patricksurry/pysimconnect/llms.txt Set multiple simulator variables at once. Each variable specification requires a name and value, with optional units. ```python from simconnect import SimConnect with SimConnect() as sc: # Set multiple variables at once sc.set_simdata([ dict(name="Indicated Altitude", value=5000, units="feet"), dict(name="PLANE HEADING DEGREES TRUE", value=180, units="degrees"), dict(name="AIRSPEED INDICATED", value=150, units="knots"), ]) print("Variables updated successfully") ``` -------------------------------- ### Distribute PySimConnect Package Source: https://github.com/patricksurry/pysimconnect/blob/master/README.md Commands to upload the built PySimConnect package to PyPI. This involves tagging the release and using twine for uploading. ```bash git commit -am ... ``` ```bash git push origin ``` ```bash git tag v0.2.6 ``` ```bash git push origin --tags ``` ```bash python3 -m twine upload dist/*0.2.6* ``` ```bash # login with username: __token__ / password: pypi-... ``` -------------------------------- ### get_simdata Source: https://context7.com/patricksurry/pysimconnect/llms.txt Fetches a snapshot of one or more simulator variables at once. ```APIDOC ## GET get_simdata ### Description Fetches a snapshot of one or more simulator variables at once. Returns a ChangeDict that tracks when each variable was last modified. ### Parameters #### Request Body - **simvars** (list) - Required - A list of variable names or dictionaries containing name, units, and epsilon settings. - **timeout_seconds** (float) - Optional - Time to wait for the data before timing out. ### Response #### Success Response (200) - **data** (dict) - A dictionary mapping variable names to their current values. ``` -------------------------------- ### Read Multiple Simulator Variables Source: https://context7.com/patricksurry/pysimconnect/llms.txt Fetch a snapshot of multiple simulator variables simultaneously. Returns a ChangeDict tracking variable modification times. Supports specifying units and epsilon for floating-point comparisons. ```python from simconnect import SimConnect with SimConnect() as sc: # Fetch multiple variables at once simvars = [ "ATC ID", "ATC cleared landing", "Kohlsman setting hg:1", dict(name="Indicated Altitude", units="m", epsilon=0.1), dict(name="Plane Latitude", units='degrees'), dict(name="Plane Longitude", units='degrees'), ] data = sc.get_simdata(simvars, timeout_seconds=2) for name, value in data.items(): print(f"{name}: {value}") # Output: # ATC ID: N12345 # ATC cleared landing: 0 # Kohlsman setting hg:1: 29.92 # Indicated Altitude: 3048.0 # Plane Latitude: 47.4502 # Plane Longitude: -122.3088 ``` -------------------------------- ### Browse Available Units Source: https://context7.com/patricksurry/pysimconnect/llms.txt Prints the total number of units and lists the first 5 altitude units. Useful for exploring available units and their dimensions. ```python print(f"\nTotal Units: {len(UNITS)}") altitude_units = [u for u in UNITS.values() if u.get('dimensions') == 'Length Units'] for unit in altitude_units[:5]: print(f" {unit['name_std']}") # Get units by dimension print(f"\nSpeed units: {DIMENSIONS.get('Speed Units', [])[:5]}") ``` -------------------------------- ### Process Message Queue Source: https://context7.com/patricksurry/pysimconnect/llms.txt Poll the SDK for messages and dispatch them. Essential for processing subscription updates and event responses. Use blocking or non-blocking receive patterns as needed. ```python from simconnect import SimConnect with SimConnect() as sc: datadef = sc.subscribe_simdata(["Indicated Altitude", "AIRSPEED INDICATED"]) # Blocking receive - waits up to timeout_seconds for a message while True: received = sc.receive(timeout_seconds=1.0) if received: print(f"Got update: {datadef.simdata}") else: print("No message received (timeout)") # Non-blocking pattern - drain all pending messages while sc.receive(timeout_seconds=0): pass # Process all waiting messages print(f"Latest data: {datadef.simdata}") ``` -------------------------------- ### Write Single Simulator Variable Source: https://context7.com/patricksurry/pysimconnect/llms.txt Set a single settable simulator variable. Only variables marked as settable in the SDK documentation can be modified. Supports setting values in different units. ```python from simconnect import SimConnect from time import sleep with SimConnect(name='AltitudeChanger') as sc: # Get current altitude altitude = sc.get_simdatum('Indicated Altitude') print(f"Current altitude: {altitude} feet") # Increase altitude by 100 feet sc.set_simdatum('Indicated Altitude', altitude + 100) sleep(0.5) # Set altitude in different units sc.set_simdatum('Indicated Altitude', 3000, units='meters') # Verify the change new_altitude = sc.get_simdatum('Indicated Altitude') print(f"New altitude: {new_altitude} feet") ``` -------------------------------- ### Subscribe to SimData Changes Source: https://context7.com/patricksurry/pysimconnect/llms.txt Efficiently monitor one or more variables over time. Returns a DataDefinition object with access to current data and inferred units. Use this instead of repeated get_simdatum calls. ```python from simconnect import SimConnect, PERIOD_VISUAL_FRAME, PERIOD_SECOND from time import sleep with SimConnect() as sc: # Subscribe to multiple variables with custom update period datadef = sc.subscribe_simdata( [ "Indicated Altitude", dict(name="Kohlsman setting hg", units="hectopascal"), "ELECTRICAL BATTERY BUS VOLTAGE", dict(name="Plane Latitude", units='degrees'), dict(name="Plane Longitude", units='degrees'), ], period=PERIOD_VISUAL_FRAME, # Update every rendered frame interval=10, # Every 10th frame ) # Get inferred units for variables print(f"Units: {datadef.get_units()}") # Track changes over time latest = datadef.simdata.latest() for _ in range(10): sleep(0.5) # Process incoming messages while sc.receive(): pass # Get changed values since last check changed = datadef.simdata.changedsince(latest) if changed: print(f"Changed: {changed}") latest = datadef.simdata.latest() # Access current values altitude = datadef.simdata.get('Indicated Altitude') lat = datadef.simdata.get('Plane Latitude') lon = datadef.simdata.get('Plane Longitude') print(f"Position: {lat}, {lon} at {altitude} ft") ``` -------------------------------- ### Set LOGLEVEL to DEBUG Source: https://github.com/patricksurry/pysimconnect/blob/master/README.md Set the LOGLEVEL environment variable to DEBUG for more detailed logging during development. This is an alternative to the default INFO level. ```bash set LOGLEVEL=DEBUG ``` -------------------------------- ### Add and Remove Custom Message Handlers Source: https://context7.com/patricksurry/pysimconnect/llms.txt Demonstrates how to add custom receiver functions for specific SimConnect response types like SIMOBJECT_DATA and exceptions. Custom receivers should return True if they handle the message. ```python from simconnect import SimConnect, RECV_SIMOBJECT_DATA, RECV_EXCEPTION def my_data_receiver(recv): """Custom handler for SIMOBJECT_DATA responses""" print(f"Received data with {recv.dwDefineCount} elements") print(f"Request ID: {recv.dwRequestID}, Flags: {recv.dwFlags}") return True # Return True if handled def my_exception_receiver(recv): """Custom handler for exceptions""" print(f"Exception {recv.dwException} at index {recv.dwIndex}") return True with SimConnect() as sc: # Add custom receivers sc.add_receiver(RECV_SIMOBJECT_DATA, my_data_receiver) sc.add_receiver(RECV_EXCEPTION, my_exception_receiver) # Subscribe to data - our receiver will be called datadef = sc.subscribe_simdata(["Indicated Altitude"]) # Process messages for _ in range(10): sc.receive(timeout_seconds=0.5) # Remove receiver when done sc.remove_receiver(my_data_receiver) ``` -------------------------------- ### Send Simulator Events Source: https://context7.com/patricksurry/pysimconnect/llms.txt Trigger events in Flight Simulator to control various functions. Events can be simple or include data values for specific actions. ```python from simconnect import SimConnect from time import sleep with SimConnect(name='EventSender') as sc: # Send simple event (no data value needed) for _ in range(5): sc.send_event('KOHLSMAN_INC') # Increase altimeter setting print("Sent KOHLSMAN_INC event") sleep(0.2) # Send event with data value sc.send_event('HEADING_BUG_SET', 270) # Set heading bug to 270 degrees print("Set heading bug to 270") # Autopilot events sc.send_event('AP_MASTER') # Toggle autopilot master sc.send_event('AP_ALT_HOLD') # Toggle altitude hold sc.send_event('AP_HDG_HOLD') # Toggle heading hold # Set autopilot altitude sc.send_event('AP_ALT_VAR_SET_ENGLISH', 10000) # Set to 10,000 feet print("Autopilot altitude set to 10,000 ft") ``` -------------------------------- ### set_simdata Source: https://context7.com/patricksurry/pysimconnect/llms.txt Sets one or more simulator variables at once. ```APIDOC ## POST set_simdata ### Description Sets one or more simulator variables at once. Each variable specification requires a name and value, with optional units. ### Parameters #### Request Body - **data** (list) - Required - A list of dictionaries, each containing name, value, and optional units for the variables to be updated. ``` -------------------------------- ### get_simdatum Source: https://context7.com/patricksurry/pysimconnect/llms.txt Fetches a one-off value of a single simulator variable from the flight simulator. ```APIDOC ## GET get_simdatum ### Description Fetches a one-off value of a single simulator variable. Blocks until the value is received or timeout expires. ### Parameters #### Request Body - **name** (string) - Required - The name of the simulator variable to fetch. - **units** (string) - Optional - The units in which to return the variable value. ### Response #### Success Response (200) - **value** (float/string/int) - The value of the requested simulator variable. ``` -------------------------------- ### set_simdatum Source: https://context7.com/patricksurry/pysimconnect/llms.txt Sets a single settable simulator variable. ```APIDOC ## POST set_simdatum ### Description Sets a single settable simulator variable. Only works with variables marked as settable in the SDK documentation. ### Parameters #### Request Body - **name** (string) - Required - The name of the simulator variable to set. - **value** (float/string/int) - Required - The value to set the variable to. - **units** (string) - Optional - The units of the provided value. ``` -------------------------------- ### Read Single Simulator Variable Source: https://context7.com/patricksurry/pysimconnect/llms.txt Fetch a one-off value of a simulator variable. Blocks until the value is received or a timeout occurs. Supports specifying units and reading indexed variables. ```python from simconnect import SimConnect with SimConnect() as sc: # Get altitude in default units (feet) altitude = sc.get_simdatum("Indicated Altitude") print(f"Altitude: {altitude} feet") # Get altitude in specific units altitude_meters = sc.get_simdatum("Indicated Altitude", units="meters") print(f"Altitude: {altitude_meters} meters") # Get indexed variable (e.g., engine 1) manifold_pressure = sc.get_simdatum("ENG MANIFOLD PRESSURE:1") print(f"Engine 1 manifold pressure: {manifold_pressure}") # Get string variable atc_id = sc.get_simdatum("ATC ID") print(f"ATC ID: {atc_id}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.