Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

# SimConnect Bindings for Rust

Send and receive information through SimConnect, for Microsoft Flight Simulator (2020).

Documentation can be found at: [MSFS 2020 SDK](https://docs.flightsimulator.com/html/Programming_Tools/SimConnect/SimConnect_SDK.htm)


## Requirements

- [CLang](https://clang.llvm.org/get_started.html) (See the [Rust Bindgen Documentation](https://rust-lang.github.io/rust-bindgen/requirements.html))
- MSVC x64 Rust build (`x86_64-pc-windows-msvc`, see [The rustup book](https://rust-lang.github.io/rustup/installation/windows.html))
- [Rust](https://rust-lang.org/learn/get-started)
- [LLVM/Clang](https://clang.llvm.org/get_started.html)

See the [Rust Bindgen Documentation](https://rust-lang.github.io/rust-bindgen/introduction.html)


## Using

Expand All @@ -16,29 +24,32 @@ Add this to your `Cargo.toml`
simconnect = "0.4"
```

_You must have SimConnect.dll in the same directory as your executable._


## Building

_The SimConnect binaries are included within this repository, but they may not be up-to-date._

1. run `cargo build`
2. Add `use simconnect` at the top of your file
1. Run `cargo build`
2. Add import `use simconnect` at the top of your file


## Example
## Examples

Read float position data

```
cargo run --example aircraft_updates
```

Requests tagged data with thresholds from SimConnect and reads floats/strings
Requests tagged data with thresholds from SimConnect, and reads floats/strings

```
cargo run --example aircraft_updates_on_change
```

_You must have SimConnect.dll in the same directory as the compiled exe for it to run (e.g. in )_

### Remarks
## Remarks

I have not tested every single function from the api. If you find an error, feel free to make an issue or a pull request.
I have not tested every function of the API. If you find an error, feel free to make an issue or pull request.
Binary file modified SimConnect.dll
Binary file not shown.
8 changes: 4 additions & 4 deletions examples/aircraft_updates/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::thread::sleep;
use std::time::Duration;

use simconnect::DispatchResult;

struct DataStruct {
lat: f64,
lon: f64,
alt: f64,
}

fn main() {
let mut conn = simconnect::SimConnector::new();
conn.connect("Simple Program"); // Intialize connection with SimConnect
conn.connect("Simple Program"); // Initialize connection with SimConnect
conn.add_data_definition(
0,
"PLANE LATITUDE",
Expand All @@ -34,7 +34,7 @@ fn main() {
simconnect::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64,
u32::MAX,
1.0,
); //define_id, units, data_type, datum_id, epsilon (update threshold)
); // define_id, units, data_type, datum_id, epsilon (update threshold)
conn.request_data_on_sim_object(
0,
0,
Expand All @@ -44,7 +44,7 @@ fn main() {
0,
0,
0,
); //request_id, define_id, object_id (user), period, falgs, origin, interval, limit - tells simconnect to send data for the defined id and on the user aircraft
); // request_id, define_id, object_id (user), period, flags, origin, interval, limit - tells simconnect to send data for the defined id and on the user aircraft

loop {
match conn.get_next_message() {
Expand Down
10 changes: 5 additions & 5 deletions examples/aircraft_updates_on_change/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use simconnect::{DispatchResult, DWORD};
use std::ptr::read_unaligned;
use std::thread::sleep;
use std::time::Duration;
use simconnect::{DispatchResult, DWORD};

// To allign the memory we have to set a fixed max size to the returned variables from the game
// To align the memory we have to set a fixed max size to the returned variables from the game
const MAX_RETURNED_ITEMS: usize = 255;

// Rust will add padding to the inner parts of a struct if it isn't marked as packed
Expand Down Expand Up @@ -54,7 +54,7 @@ fn main() {
simconnect::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64,
3,
100.0,
); //define_id, units, data_type, datum_id, epsilon (update threshold)
); // define_id, units, data_type, datum_id, epsilon (update threshold)

// Here we define all our variabes that get returned as Strings
// Notice how the define_id differs from the float values
Expand Down Expand Up @@ -82,7 +82,7 @@ fn main() {
0,
0,
0,
); //request_id, define_id, object_id (user), period, falgs, origin, interval, limit - tells simconnect to send data for the defined id and on the user aircraft
); // request_id, define_id, object_id (user), period, flags, origin, interval, limit - tells simconnect to send data for the defined id and on the user aircraft
// Request the data from our define_id 1 (strings)
// The request_id has to differ from the float request. Or else it will overwrite the previous request
conn.request_data_on_sim_object(
Expand All @@ -95,7 +95,7 @@ fn main() {
0,
0,
0,
); //request_id, define_id, object_id (user), period, falgs, origin, interval, limit - tells simconnect to send data for the defined id and on the user aircraft
); // request_id, define_id, object_id (user), period, flags, origin, interval, limit - tells simconnect to send data for the defined id and on the user aircraft

loop {
match conn.get_next_message() {
Expand Down