SIMCONNECT SAMPLES

Bundled along with the SDK are a number of sample projects that can be used as reference material for using the SimConnect SDK. These samples can be found from the following SDK folder:

<SDK ROOT>\Samples\VisualStudio\SimConnectSamples\

To use the samples, follow these simple instructions:

  • Start Microsoft Flight Simulator.
  • Open the *.sln file for the sample you want to look at in Visual Studio.
  • Build the solution.
  • Perform any actions required for preparation in Microsoft Flight Simulator, for example start a free flight in the appropriate airport.
  • Run the project in Visual Studio.
  • Follow the instructions for the sample.

 

Below you can find full details of what each sample contains.

 

 

AI Objects and Waypoints

This sample is used to create a number of non-ATC SimObjects at a specific airport. The objects created are:

  • 1 DA62
  • 1 Pitts Special S2S
  • 1 Giraffe
  • 1 Fire Truck

When using this sample, you need to start a free flight from KSEA - Runway 34R. Once at the airport, you can use the following keys:

  • Press z to create the objects
  • Press x to load them with their waypoint lists
  • Press c to remove the generated objects

 

Important Functions Highlighted Structures and/or Enumerations

SimConnect_SetDataOnSimObject

SimConnect_AICreateSimulatedObject

SimConnect_AICreateNonATCAircraft

SIMCONNECT_DATA_INITPOSITION

SIMCONNECT_DATA_WAYPOINT

SIMCONNECT_RECV_ASSIGNED_OBJECT_ID

 

 

AI Traffic

Creates a number of aircraft at McAllister Airport (KYKM) - known for the Yakima Air Terminal - and provides them with a flight plan to Spokane Intl. (KGEG). Note that it will also try to create a Boeing 747, which will fail because it is too large for the airport. The sample also sets up two parked aircraft, and a key press initiates them with the same flight plan.

 

To use the sample, first start a flight at McAllister Airport (KYKM), then go off the runway (or use the developer camera) to see what's going on. Alternatively, from the world view, you can load the Yakima to Spokane flight plan used by the AI aircraft, however this will require that you move the included file - IFR Yakima Air Term Mcallister to Spokane Intl.PLN - into the AppData folder.

 

When running the sample you can use thew following keys:

  • Press the Z key to add 3 AI aircrafts
  • Press the X key to give the parked aircraft the McAllister to Spokane flight plan

NOTE: Each key can only be used once.

 

Important Functions Highlighted Structures and/or Enumerations

SimConnect_AISetAircraftFlightPlan

SimConnect_AICreateEnrouteATCAircraft

SimConnect_AICreateParkedATCAircraft

SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE

SIMCONNECT_RECV_ASSIGNED_OBJECT_ID

 

 

Facility Data Definition

This sample simply shows how to receive and define facility data about an airport, in this case Charles DeGaulle in France (ICAO code LFPG). To use the sample, start the simulation, then build and run the sample once you are on the world map. This will open a new window showing information about what you have retrieved and what you have added to the data definition.

 

Important Functions Highlighted Structures and/or Enumerations

SimConnect_AddToFacilityDefinition

SimConnect_RequestFacilityData

SIMCONNECT_RECV_FACILITIES_LIST

SIMCONNECT_RECV_FACILITY_DATA

SIMCONNECT_RECV_FACILITY_DATA_END

SIMCONNECT_DATA_FACILITY_AIRPORT

 

 

Facility Data Definition 2

This sample shows how to retrieve a massive amount of facility data from the entire world. To use the sample, start the simulation, then build the sample and run it. A new console window will pop up and - after a short length of time - will show some data and also give you some options:

The Facilities Data 2 Sample Terminal WindowNOTE: If you see any "Request Failed" messages at this point, then they are miss-configured NavData within the simulation.

Each option permits you to retrieve data about a specific NavData item, by simply selecting the number then giving the required key/ID/Name. For example, the first option "Request Waypoint by Key" permits you to give the waypoint identity key to get data about that waypoint, where the key has the format TYPE-IDENT-REGION, eg: WP-BOMBI-ED.

Example Of A Waypoint Retrieved Using The Facilities 2 Sample

 

Important Functions Highlighted Structures and/or Enumerations

SimConnect_RequestFacilityData_EX1

SIMCONNECT_RECV_FACILITY_DATA

SIMCONNECT_RECV_FACILITY_DATA_END

SIMCONNECT_DATA_FACILITY_AIRPORT

SIMCONNECT_DATA_FACILITY_NDB

SIMCONNECT_DATA_FACILITY_VOR

SIMCONNECT_DATA_FACILITY_WAYPOINT

 

 

Input Event

This sample project shows off how to take an input event and map it to something in the simulation. In this case it takes input from the z key, and maps it to the aircraft brakes. To test the sample, start a flight, then - while taxiing on the runway - press z.

 

Important Functions Highlighted Structures and/or Enumerations

SimConnect_MapInputEventToClientEvent

SimConnect_SetInputGroupState

SIMCONNECT_RECV_EVENT

 

 

Joystick Input

This sample shows how to generate the input events from a joystick. It generates data from the X and Y axis position, the Z axis rotation, the hat switch, and and a slider.

 

To test the sample, start a free flight, then press the z key on the keyboard to switch between the different input events.

 

Important Functions Highlighted Structures and/or Enumerations

SimConnect_SetInputGroupState

SimConnect_MapClientEventToSimEvent

SimConnect_AddClientEventToNotificationGroup

SimConnect_MapInputEventToClientEvent

SIMCONNECT_RECV_EVENT

 

 

No Callback

This sample illustrates how to deal with events without using any callbacks. To use the sample you should start a free flight at any airport, then start taxiing down the runway. When the aircraft is moving, use the brakes and you'll see a message displayed in the SimConnect debug window.

 

Important Functions Highlighted Structures and/or Enumerations
SimConnect_GetNextDispatch SIMCONNECT_RECV_EVENT

 

 

Open and Close

This sample project is very simple and just opens and closes a connection with the SimConnect server.

 

Important Functions Highlighted Structures and/or Enumerations

SimConnect_Open

SimConnect_Close

N/A

 

 

Request Data

This simple example requests a small selection of data on the user's aircraft, including latitude, longitude and altitude. To use this sample, simply run the project then start a free flight and you'll see the latitude, longitude, altitude and Kohlsman values in the debug window.

 

Important Functions Highlighted Structures and/or Enumerations

SimConnect_AddToDataDefinition

SIMCONNECT_RECV_EVENT

SIMCONNECT_RECV_SIMOBJECT_DATA

 

 

Send Event A / B / C

The three samples, Send Event A, B and C are designed to be run together. The Send Event A sample will transmit custom events to the two other clients, B and C. The Send Event B sample will receive the custom events from Send Event A, and masks one of the events from Send Event C. The Send Event C sample Receives custom events from Send Event A, at a lower priority than those sent to Send Event B.

 

To use these samples, start a free flight, then run each one of them so you have three SimConnect debug windows open. In the simulation, apply the brakes on the aircraft and you'll see messages propagate to the three samples.

 

Important Functions Highlighted Structures and/or Enumerations

SimConnect_TransmitClientEvent

SimConnect_MapClientEventToSimEvent

SimConnect_AddClientEventToNotificationGroup

SimConnect_SetNotificationGroupPriority

SIMCONNECT_RECV_EVENT

 

 

SetData

This sample shows how to set data within the simulation. To use the sample, you need to start a free flight, anywhere in the world, and then press the z key. This will then move the aircraft to a new location (Washington).

 

Important Functions Highlighted Structures and/or Enumerations

SimConnect_SetDataOnSimObject

SimConnect_AddToDataDefinition

SimConnect_MapClientEventToSimEvent

SimConnect_MapInputEventToClientEvent

SimConnect_SetInputGroupState

SIMCONNECT_DATA_INITPOSITION

 

 

SystemEvent

This sample requests a system event, in this case the "flight load" event. To use this sample, you should go to the main world view in the simulation then run the sample and start a flight. The SimConnect debug window will output the path to the FLT file that is loaded for the flight.

 

Important Functions Highlighted Structures and/or Enumerations
SimConnect_SubscribeToSystemEvent

SIMCONNECT_RECV_EVENT

SIMCONNECT_RECV_EVENT_FILENAME

 

 

TaggedData

This sample illustrates how to deal with tagged data, returning the the vertical speed and pitot heat switch setting of the user aircraft, but only when the data has changed. To use the sample, you need to go to the world view in the simulation, then run the sample project. Once it's running, if you start a flight, you'll see the debug window output the pitot heat switch value and the vertical speed, as they change.

 

Important Functions Highlighted Structures and/or Enumerations

SimConnect_RequestDataOnSimObject

SimConnect_AddToDataDefinition

SIMCONNECT_RECV_SIMOBJECT_DATA

 

 

ThrottleControl

This sample shows how to control the aircraft throttle using SimConnect. To use the sample, you should start a free flight then run the sample project. Once in the flight, you can use the a and z keys to change the aircraft throttle. 

 

Important Functions Highlighted Structures and/or Enumerations

SimConnect_SetDataOnSimObject

SimConnect_AddToDataDefinition

SimConnect_MapClientEventToSimEvent

SimConnect_MapInputEventToClientEvent

SimConnect_SetInputGroupState

N/A

 

 

TrackingErrors

Shows how to use GetLastSendID to record the ID of a request, along with an identification string in order to match the IDs of errors returned and identify which call caused the error. The sample will also generate an error to show how it can be traced.

 

To use the sample, simply run it while in a free flight. You should see an exception and information about it in the debug console. 

 

Important Functions Highlighted Structures and/or Enumerations

SimConnect_GetLastSentPacketID

SimConnect_MapClientEventToSimEvent

SimConnect_AddClientEventToNotificationGroup

SimConnect_SetNotificationGroupPriority

SimConnect_CallDispatch

SIMCONNECT_RECV_EVENT

SIMCONNECT_RECV_EXCEPTION

 

 

WindowsEvents

This sample requests a four second timing event, and implements a Windows Event handler to minimize processing time. To use the sample, simply start the simulation and then run it. You will see the debug window show a timer event every four seconds.

 

Important Functions Highlighted Structures and/or Enumerations

SimConnect_Open

SimConnect_SubscribeToSystemEvent

SIMCONNECT_RECV_EVENT