Skip to content

Commit 6189c8c

Browse files
committed
Updated readme
1 parent 89bc7d5 commit 6189c8c

File tree

2 files changed

+97
-2
lines changed

2 files changed

+97
-2
lines changed

README.md

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,103 @@
11
[![PyPI version](https://badge.fury.io/py/SimConnect.svg)](https://badge.fury.io/py/SimConnect)
22
# Python-SimConnect
33

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
5101

6102
[Event IDs](https://docs.microsoft.com/en-us/previous-versions/microsoft-esp/cc526980(v=msdn.10))
7103

glass_server.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,6 @@ def custom_emergency(emergency_type):
450450
if emergency_type == "random_engine_fire":
451451
# Calculate number of engines
452452
number_of_engines = aq.get("NUMBER_OF_ENGINES")
453-
#print ("Number of engines: " + str(number_of_engines))
454453

455454
if number_of_engines < 0: return "error, no engines found - is sim running?"
456455
engine_to_set_on_fire = random.randint(1,number_of_engines)

0 commit comments

Comments
 (0)