# SimvarWatcher The `SimvarWatcher` sample is **Microsoft Visual Studio project** that shows how to connect to Microsoft Flight Simulator 2024 from a C\# application in order to retrieve [simulation variables](../../../programming-apis/simvars/simulation-variables/) (generally known as `SimVars`). You can find this project from the following SDK location: C:\(MSFS 2024 SDK\)Samples\(VisualStudio\)SimvarWatcher This page outlines how to build and use the sample project, and you can study the project in Visual Studio for yourself to see how it works.     ### Loading And Building The Project The supplied sample requires a minimum of Visual Studio 2017 to be installed on your machine (any edition of this product can be used, including the free Community edition). To load the project into Visual STudio, simply double click on the file `Simvars.csproj` in the `SimvarWatcher` sample folder. Once open in VS, go to the **Build** menu and select **Build Solution**: {{< image-center src="images/6_Programming/SimVar/simvarwatcher_buildsolution.png" alt="Build Simvar Watcher Project In Visual Studio" >}}     ### Running The Project Once the project has been built it can be run by clicking the **Start** button in Visual Studio. This will open the Simvar Watcher app: {{< image-center src="images/6_Programming/SimVar/simvarwatcher_running.png" alt="The Simvar Watcher App Running From Visual Studio" >}}   The first thing to do is to connect the app to the simulation, which requires Microsoft Flight Simulator 2024 to be running (if it's not, then start it now before continuing). You should start a mission so that the app can retrieve and set the SimVars that you want, and then in the Simvar Watcher app click on the `Connect` button in the top left of the window. The red indicator should now become a flashing green/blue to indicate that the app has connected correctly to the simulation: {{< image-center src="images/6_Programming/SimVar/simvarwatcher_connected.png" alt="Simvar Watcher Status Light" >}} Note that the light flashes between blue and green based on the **update frequency**, which you can set using the **Frequency** slider beside the Connect/Disconnect button.     ### Simvar Watcher Menus Here we'll give a brief overview of the controls in the Simvar Watcher so you know what they do and can see the code in Visual Studio. To start with we'll explore the menu options at the top of the app:   #### File This menu has the following options:   - **Load File**: Loads a previously saved simvar data file. There are examples of these that can be loaded in the `Simvars` subfolder of the `SimvarWatcher` sample folder. Please note that this does NOT overwrite any exisiting SimVars, and loaded data will be *added* to the currently watched vars. - **Save File**: Saves out any defined simvar watches (SimVar + Units) as a `*.simvar` file. - **Save File With Values**: Saves out any defined simvar watches (SimVar + Units + Values) as a `*.simvar` file. This can be helpful to revise values when the app is disconnected from the simulation. - **Exit**: Exit the Simvar Watcher app.   #### Options This menu has the following options:   - **Use FX Compatibility Configuration**: This option is intended to permit you to use the SimVar Watcher with the *legacy* Microsoft Flight Simulator X (FSX). When checked the SimVar Watcher should be able to connect to this legacy product. - **Show All Units**: For many SimVars, by default, the watcher app will only show the applicable units that can be selected. However, when this option is checked, *all* units will be shown.   #### About This menu has the following options:   - **SimConnect Reference**: This will open the documentation on the [SimConnect API Reference](../../../programming-apis/simconnect/simconnect-api-reference/) page. - **Simulation Variables Reference**: This will open the documentation on the [Simulation Variables](../../../programming-apis/simvars/simulation-variables/) page.     ### Using The SimVar Watcher The SimVar Watcher app is split into the following main sections: {{< image-center src="images/6_Programming/SimVar/simvarwatcher_sections.png" alt="The SimVar Watcher Sections" >}} The general process for using the tool is to select an object that you want top get/set the SimVars for, then select the SimVar itself, paying attention to the units and the index (if no index is specified or required for the SimVar then it should be 0). Once selected you click the `Add request >` button to add it to the SimVar Watches. If you want to *set* the SimVar, then you select it from the SimVar Watches list, place an appropriate value in the "Value" input, and click on the `Try set value >` button.   The sections below explain each item of the app interface in more detail.   #### Sim Object - **SimObject**: Permits you to choose from a subset of `SimObjects` which one to target. - **ObjectId**: shows a list of the available `SimObject` IDs.   #### SimVar Selection - **Simvar Name**: Opens a drop-down list of all the different `Simvar` names so you can choose one to watch or set. Above this option you have an input field that can be used to filter the available SimVars and help you to find the exact one you are looking for. {{< image-center src="images/6_Programming/SimVar/simvarwatcher_filter.png" alt="The SimVar Filter" >}} - **Index**: Used when indexing a `Simvar` that could refer to multiple `SimObjects` (like the the engine SimVars, for example `ENG ANTI ICE`). - **Units**: The unit of measurement to use for the `Simvar` watch. By default this will be filtered - where possible and applicable - to show the units appropriate to the selected SimVar, but this behaviour can be changed from the [Options](#options) menu. You can find an explanation for each of the possible units on the [Simulation Variable Units](../../../programming-apis/simvars/simulation-variable-units/) page. - **Add Request**: Adds the selected `Simvar` to the **watch list** on the right: {{< image-center src="images/6_Programming/SimVar/simvarwatcher_addedwatches.png" alt="Watches in the Simvar Watcher App" >}} - **Is String**: Checking this option tells the SimVar watcher that the return value for the requested SimVar is a string, for example, when using something like `TACAN STATION IDENT`. - **Value**: The new value to set the currently selected `Simvar` to. - **Try Set Value**: Clicking this will take the set value from the input above and try to set the selected `Simvar` to it in the simulation. A large majority of Simvars *cannot* be set, however this is listed as part of the [documentation for each SimVar](../../../programming-apis/simvars/simulation-variables/).   #### Errors Any errors will be shown in this window, for example when you try to set a value on a SimVar that doesn't permit it: {{< image-center src="images/6_Programming/SimVar/simvarwatcher_error.png" alt="SimVar Data Error Message" >}} #### SimVar Watches The SimVar Watches is the part of the app that shows all the different SimVars that you have requested to be added. The SimVars shown will update their values in real time based on what is currently happening in the simulation. You can also click on the different variables listed and then use the `Try set value` button to set the value of the SimVar (if permitted).   You can **right click** on any of the listed SimVars to get the following menu: {{< image-center src="images/6_Programming/SimVar/simvarwatcher_rmb.png" alt="The RMB Menu Options For The Watch List" >}} - **Remove**: This will remove the selected SimVar from the watch list. - **Remove All**: This will clear the watch list, removing *all* SimVars from it. - **Copy Name/Value/Unit**: This option will copy the name/value/unit of the selected SimVar to the clipboard