|
1 | 1 | [](https://badge.fury.io/py/SimConnect)
|
2 | 2 | # Python-SimConnect
|
3 | 3 |
|
4 |
| -Python interface for MSFS2020 SimConnect.dll |
| 4 | +Python interface for Microsoft Flight Simulator 2020 (MSFS2020) using SimConnect |
| 5 | + |
| 6 | +This library allows Python scripts to read and set variables within MSFS2020 and trigger events within the simulation. |
| 7 | + |
| 8 | +It also includes, as an example, "Cockpit Companion", a flask mini http server which runs locally. It provides a web UI with a moving map and simulation variables. It also provides simulation data in JSON format. Full documentation for this example can be found at [https://msfs2020.cc](https://msfs2020.cc). |
| 9 | + |
| 10 | +## Python interface example |
| 11 | + |
| 12 | +```` |
| 13 | +from SimConnect import * |
| 14 | +
|
| 15 | +# Create SimConnect link |
| 16 | +sm = SimConnect() |
| 17 | +aq = AircraftRequests(sm) |
| 18 | +ae = AircraftEvents(sm) |
| 19 | +
|
| 20 | +# Get the aircraft's current altitude |
| 21 | +altitude = aq.get("PLANE_ALTITUDE") |
| 22 | +altitude = altitude + 1000 |
| 23 | +
|
| 24 | +# Set the aircraft's current altitude |
| 25 | +aq.set("PLANE_ALTITUDE", altitude) |
| 26 | +
|
| 27 | +# Trigger a simple event |
| 28 | +event_to_trigger = ae.find("AP_MASTER") # Toggles autopilot on or off |
| 29 | +event_to_trigger() |
| 30 | +
|
| 31 | +# Trigger an event while passing a variable |
| 32 | +target_altitude = 15000 |
| 33 | +event_to_trigger = ae.find("AP_ALT_VAR_SET_ENGLISH") # Sets AP autopilot hold level |
| 34 | +event_to_trigger(target_altitude) |
| 35 | +```` |
| 36 | + |
| 37 | +## Browser interface example |
| 38 | + |
| 39 | +Run `glass_server.py` using Python 3. |
| 40 | + |
| 41 | +#### http://localhost:5000 |
| 42 | +Method: GET |
| 43 | + |
| 44 | +Variables: None |
| 45 | + |
| 46 | +Output: Web interface with moving map and aircraft information |
| 47 | + |
| 48 | +#### http://localhost:5000/dataset/<dataset_name> |
| 49 | +Method: GET |
| 50 | + |
| 51 | +Arguments to pass: |
| 52 | + |
| 53 | +|Argument|Location|Description| |
| 54 | +|---|---|---| |
| 55 | +|dataset_name|in path|can be navigation, airspeed compass, vertical_speed, fuel, flaps, throttle, gear, trim, autopilot, cabin| |
| 56 | + |
| 57 | +Description: Returns set of variables from simulator in JSON format |
| 58 | + |
| 59 | + |
| 60 | +#### http://localhost:5000/datapoint/<datapoint_name>/get |
| 61 | +Method: GET |
| 62 | + |
| 63 | +Arguments to pass: |
| 64 | + |
| 65 | +|Argument|Location|Description| |
| 66 | +|---|---|---| |
| 67 | +|datapoint_name|in path|any variable name from MS SimConnect documentation| |
| 68 | + |
| 69 | +Description: Returns individual variable from simulator in JSON format |
| 70 | + |
| 71 | + |
| 72 | +#### http://localhost:5000/datapoint/<datapoint_name>/set |
| 73 | +Method: POST |
| 74 | + |
| 75 | +Arguments to pass: |
| 76 | + |
| 77 | +|Argument|Location|Description| |
| 78 | +|---|---|---| |
| 79 | +|datapoint_name|in path|any variable name from MS SimConnect documentation| |
| 80 | +|index (optional)|form or json|the relevant index if required (eg engine number) - if not passed defaults to None| |
| 81 | +|value_to_use (optional)|value to set variable to - if not passed defaults to 0| |
| 82 | + |
| 83 | +Description: Sets datapoint in the simulator |
| 84 | + |
| 85 | + |
| 86 | +#### http://localhost:5000/event/<event_name>/trigger |
| 87 | +Method: POST |
| 88 | + |
| 89 | +Arguments to pass: |
| 90 | + |
| 91 | +|Argument|Location|Description| |
| 92 | +|---|---|---| |
| 93 | +|event_name|in path|any event name from MS SimConnect documentation| |
| 94 | +|value_to_use (optional)|value to pass to the event| |
| 95 | + |
| 96 | +Description: Triggers an event in the simulator |
| 97 | + |
| 98 | +## Events and Variables |
| 99 | + |
| 100 | +Below are links to the Microsoft documentation for events which can be triggered using this |
5 | 101 |
|
6 | 102 | [Event IDs](https://docs.microsoft.com/en-us/previous-versions/microsoft-esp/cc526980(v=msdn.10))
|
7 | 103 |
|
|
0 commit comments