Wrapper for the SimConnect SDK for Microsoft Flight Simulator (Windows 64bit only)
npm install fspm-node-simconnectnpm install fspm-node-simconnect
const simConnect = require('node-simconnect');
open(connectedCallback, simExitedCallback, exceptionCallback, errorCallback)
false if it failed to call open (eg. if sim is not running).
javascript
var success = simConnect.open("MyAppName",
(name, version) => {
console.log("Connected to: " + name + "\nSimConnect version: " + version);
// Safe to start interacting with SimConnect here (request data, etc)
}, () => {
console.log("Simulator exited by user");
}, (exception) => {
console.log("SimConnect exception: " + exception.name + " (" + exception.dwException + ", " + exception.dwSendID + ", " + exception.dwIndex + ", " + exception.cbData + ")");
}, (error) => {
console.log("Undexpected disconnect/error: " + error); // Look up error code in ntstatus.h for details
});
`
$3
requestDataOnSimObject(reqData, callback, objectId, period, dataRequestFlag)
Request one or more Simulation Variables and set a callback function to later handle the received data. See SDK Reference for more details.
Each simulation variable is defined by an array.
Example:
`javascript
[
"Plane Latitude", // Datum name
"degrees", // Units name
simConnect.datatype.FLOAT64, // Datum type (optional, FLOAT64 is default and works for most data types)
0 // Epsilon (optional, 0 is default)
]
`
Full example:
`javascript
simConnect.requestDataOnSimObject([
["Plane Latitude", "degrees"],
["Plane Longitude", "degrees"],
["PLANE ALTITUDE", "feet"]
], (data) => {
// Called when data is received
console.log(
"Latitude: " + data["Plane Latitude"] + "\n" +
"Longitude: " + data["Plane Longitude"] + "\n" +
"Altitude: " + data["PLANE ALTITUDE"] + " feet"
);
},
simConnect.objectId.USER, // User aircraft
simConnect.period.SIM_FRAME, // Get data every sim frame...
simConnect.dataRequestFlag.CHANGED // ...but only if one of the variables have changed
);
`
$3
requestDataOnSimObjectType(reqData, callback, radius, simobjectType)
Similar to requestDataOnSimObject. Used to retrieve information about simulation objects of a given type that are within a specified radius of the user's aircraft. See SDK Reference for more details.
Example:
This will receive info about the user's aircraft. For this, a radius of 0 is used. Notice that when STRINGV is requested, the unit should be null.
`javascript
simConnect.requestDataOnSimObjectType([
["NAV IDENT:1", null, simConnect.datatype.STRINGV],
["NAV NAME:1", null, simConnect.datatype.STRINGV],
["NAV DME:1","Nautical miles"],
], (data) => {
console.log(data);
}, 0 / radius=0 /, simConnect.simobjectType.USER);
`
Example:
This will receive info about all aircraft within a 10 km radius. The callback will run one time for each identified aircraft.
`javascript
simConnect.requestDataOnSimObjectType([
["ATC MODEL",null,simConnect.datatype.STRINGV],
["Plane Latitude", "degrees"],
["Plane Longitude", "degrees"]
], (data) => {
console.log(data);
}, 10000, simConnect.simobjectType.AIRCRAFT);
`
$3
createDataDefinition(reqData)
Used to create a data definition. Returns an id which can be used with requestDataOnSimObjectType in place of the array. This should be used when you have multiple requests for the same data - otherwise the app will crash after receiving too many requests.
Example:
`javascript
var navInfoDefId = simConnect.createDataDefinition([
["NAV DME:1", "Nautical miles"],
["NAV GLIDE SLOPE ERROR:1", "Degrees"],
["NAV RADIAL ERROR:1", "Degrees"],
]);
setInterval(() => {
simConnect.requestDataOnSimObjectType(navInfoDefId, (data) => {
console.log(data)
}, 0, simConnect.simobjectType.USER)
},100)
`
$3
setDataOnSimObject(variableName, unit, value)
Set a single Simulation Variable on user aircraft. First parameter is the datum name, second is the units name and last is the value.
Example:
`javascript
simConnect.setDataOnSimObject("GENERAL ENG THROTTLE LEVER POSITION:1", "Percent", 50);
`
$3
subscribeToSystemEvent(eventName, callback)
Subscribe to a system event. See SDK Reference for available events.
Example:
`javascript
simConnect.subscribeToSystemEvent("Pause", (paused) => {
// Called when the system event occurs
console.log(paused ? "Sim paused" : "Sim un-paused");
});
`
$3
close()
Manually close the connection to SimConnect. Returns false if it fails.
Example:
`javascript
var success = simConnect.close();
`
Manual build 🔨
You might wish to build node-simconnect manually. Due to the licensing of the SimConnect SDK (is this still valid?) the library files are not included in this repository, so you must provide these yourself.
$3
* Node.js (64 bit)
* MS Visual Studio 2019
$3
You must provide your own copy of the SDK files. For FSX:SE, these can be found under C:\MSFS SDK\SimConnect SDK. Follow these steps carefully:
* Copy the SimConnect SDK folder here
* Run $npm run build`