Python wrapper for Microsoft FlightSimulator 2020 SimConnect SDK
Project description
The pysimconnect
package provides a simple, efficient wrapper for FlightSimulator 2020's
SimConnect SDK,
inspired by Python-SimConnect.
If you're looking to build external instrument displays,
connect custom controllers to FS2020,
or just explore how the simulation works in more detail
then pysimconnect
is for you.
You might also be interested in G3,
a flexible Javascript framework for building steam gauge instrument panels.
The package contains a python module called simconnect
which exposes a simple pythonic interface
to read simulator variables,
set editable variables,
subscribe to variable changes,
and trigger simulator events.
It also exposes all of the low-level SDK methods,
constants and enumerations from the SimConnect.h
SDK API based on a simple automated translation
from the C++ definitions to Python equivalents.
The package also offers a simconnect
command-line tool
which lets you search for
variables, events and measurement units from the SDK documentation;
inspect, change or watch variables over time;
and send simulator events,
all without writing any code.
Quick start
Making sure you're using python 3.6+ and install the package:
pip install pysimconnect
To use the simconnect
command-line tool,
install Powershell7 and
set your default terminal
to Windows Terminal rather than Windows Console Host.
Start Powershell7 and install TAB auto-completion support by typing
simconnect --install-completion powershell
then restart your terminal as instructed:
Now start a flight in FS2020, perhaps with the AI pilot flying.
Let's experiment with reading and modifying the altitude.
First let's find some relevant variables with search
:
Nice! We get a list of results from the SDK documentation ranked by relevance. Result categories are distinguished by different colors and symbols, e.g. variables 🧭, events ⚙️ and units 📐, with a ✏️ marking variables which we can change.
Now let's read the value of the PLANE ALTITUDE
variable using the get
command.
Start typing simconnect get PLA<TAB>
, hitting the TAB key part way through the variable name
to see contextual auto-complete options:
Select the desired PLANE_ALTITUDE
option and hit ENTER:
Note that although the underlying SDK variables are space-separated and events are underscore-separated, the command-line tool recognizes either version. Normally using underscore-separated everywhere will be easier for auto-completion and avoids quoting in the terminal.
We can read multiple variables by just appending them in a list.
We can also monitor multiple variables over time using watch
:
By default we'll see an update once every second,
highlighting the variables that change during each update.
Some commands support additional options,
for example simconnect watch --help
will show us how to change the
monitoring interval time.
For general help, try simconnect --help
.
Now let's change the plane's altitude during flight(!) using the set
command.
Here we'll add the --units
option to specify that our value is measured in meters
rather
than the default feet
:
Lastly, let's send an event to FS2020. A simple example is to bump the altimeter adjustment knob, like so. If you send this event a few times, you'll see the indicated altitude adjust in response.
This simple event needs no data, but with others you also need to provide a value.
Working with python
The command-line tool is just a lightweight
wrapper for some features of the simconnect
python package.
This means that you can write simple python code to do anything
the command-line tool does, and much more besides.
The best way to get started is to browse some examples
which show both low-level interaction with the SDK,
and some of the simplified sugar the package offers.
With so many moving parts, debugging errors can sometimes be tricky.
One useful tool is to set the LOGLEVEL
environment variable
to DEBUG
before running your code, rather than the default INFO
:
set LOGLEVEL=DEBUG
Also, be warned that the official
SDK documentation
has various errors (copy/paste gone wrong?)
which can make it difficult to understand some details.
Where possible refer directly to the SimConnect.h
header file definitions and comments
as a more authoritative source.
What's what?
Find the full source on github at https://github.com/patricksurry/pysimconnect.
The simconnect
folder contains the package itself.
The main interface is defined in sc.py
which wraps the raw
definitions from the auto-generated scdefs.py
,
providing access to both the low-level
SDK functions as well as some pythonic sugar.
The command line tool is implemented by cli.py
.
The package requires a copy of SimConnect.dll
to work.
This normally ships with FS2020 but a recent copy is also included here.
You can point to your own version by specifying the dll_path
argument
when initializing SimConnect(...)
.
The scvars.json
file lists all the simulation variables (SimVars),
events and dimensional units, which were scraped from the SDK documentation pages
using scripts/scrapevars.json
. This is useful for finding content
you want to interact with, inferring missing units and data-types
when querying simulation variables, and sanity-checking variable names.
The examples
folder contains various illustrations of how to use
the package, showing both low-level SDK access and the pythonic wrappers.
See the README.md
there for more details.
The scripts
folder includes several scripts used to generate
parts of the package.
The genscdefs.py
script creates scdefs.py
from a post-processed
version of the SimConnect.h
C++ header that ships with the SDK
(which can be installed via the Options > General > Developer tools help menu).
This generates a python translation of all the SDK function declarations, data structures
and enumerated constants. The automated translation is quite fragile:
it assumes the header is formatted in a particular way, and has been
pre-processed with cpp
to SimConnect_cpp.h
from the raw header.
This approach makes it easy to tweak the rules for mapping from C++
to Python, as long as header format doesn't change significantly.
Packaging and distribution
Bump version in setup.cfg
then following https://packaging.python.org/en/latest/tutorials/packaging-projects/
python3 -m build
git commit -am ...
git push origin
git tag v0.1.1
git push origin --tags
python3 -m twine upload dist/*0.1.1* # login with __token__ / pypi...
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pysimconnect-0.2.1.tar.gz
.
File metadata
- Download URL: pysimconnect-0.2.1.tar.gz
- Upload date:
- Size: 184.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.6.4 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86a8e24d5d7e7da074553ef8f3049448124ab289c237e2a2fb06cec72fd8d368 |
|
MD5 | 36aa5cd553d4c4b028758768b84d8754 |
|
BLAKE2b-256 | ed33c36b0c11031d9356c0a56c316b35a5e1be731a98a1cb3681ac81bbd05241 |
File details
Details for the file pysimconnect-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: pysimconnect-0.2.1-py3-none-any.whl
- Upload date:
- Size: 165.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.6.4 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c43b9c41b09386865271be274412eb3b423650979b8a721f1f9307c152e57c13 |
|
MD5 | 98679caec623f68a5e195626231cc7b2 |
|
BLAKE2b-256 | e62db69b3fbc31ec1b4a6d074a585eb3f557b447bacbfc25fae4e61040c6d135 |