Add this to your Cargo.toml
toml
[dependencies]
simconnect = "0.1.3"
Note: This crate is in its early stages and API breaking changes can be pushed at any moment. In this case, it's recommended to use the exact version "0.X.X".
The SimConnect binaries are included within this repository, but they may not be up to date.
cargo build
use simconnect
Note: You must have SimConnect.dll in your current working directory or in the exe directory to be able to successfully use SimConnect ```rust use simconnect; use std::time::Duration; use std::thread::sleep; use std::mem::transmute_copy;
struct DataStruct { lat: f64, lon: f64, alt: f64, }
let mut conn = simconnect::SimConnector::new(); conn.connect("Simple Program"); // Intialize connection with SimConnect conn.adddatadefinition(0, "PLANE LATITUDE", "Degrees", simconnect::SIMCONNECTDATATYPESIMCONNECTDATATYPEFLOAT64, u32::MAX); // Assign a sim variable to a client defined id conn.adddatadefinition(0, "PLANE LONGITUDE", "Degrees", simconnect::SIMCONNECTDATATYPESIMCONNECTDATATYPEFLOAT64, u32::MAX); conn.adddatadefinition(0, "PLANE ALTITUDE", "Feet", simconnect::SIMCONNECTDATATYPESIMCONNECTDATATYPEFLOAT64, u32::MAX); //defineid, units, datatype, datumid conn.requestdataonsimobject(0, 0, 0, simconnect::SIMCONNECTPERIODSIMCONNECTPERIODSIMFRAME, 0, 0, 0, 0); //requestid, defineid, object_id (user), period, falgs, origin, interval, limit - tells simconnect to send data for the defined id and on the user aircraft
loop { match conn.getnextmessage() { Ok(simconnect::DispatchResult::SimobjectData(data)) => { unsafe { match data.dwDefineID { 0 => { let simdata: DataStruct = transmutecopy(&data.dwData); println!("{:?} {:?} {:?}", simdata.lat, simdata.lon, sim_data.alt); }, _ => () } } }, _ => () }
sleep(Duration::frommillis(16)); // Will use up lots of CPU if this is not included, as getnext_message() is non-blocking } ```
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.