• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Constantly update console using c++ (msfs2020 SimConnect)

Messages
27
Country
unitedstates
I'm trying to constantly update the console number related to altitude. At the moment its a static number, and does not update while the plane is gaining, or loosing altitude. There is a comment near the bottom of the text referring to the prinf() that im using to send it to console(not sure what all was needed to be seen so I sent it all).
simc.PNG

Code:
#include <iostream>
#include <Windows.h>
#include "SimConnect.h"
#include <string>
#include <sstream>
using namespace std;




HANDLE hSimConnect = NULL;




enum DATA_DEFINE_ID
{
    DEFINITION_ID_AP,
};

enum DATA_REQUEST_ID
{
    REQUEST_AP_SETTINGS,
};

enum EVENT_ID
{
    EVENT_SET_AP_ALTITUDE,
};



struct DataRefs
{
    double altitude;
    double knots;
};



int main() {
    

        HRESULT hr;
        SIMCONNECT_RECV* pData = NULL;
        DWORD cbData = 0;
        bool bRequestProcessed = false;
        int SelectedAltitude = 0;
        SIMCONNECT_RECV_SIMOBJECT_DATA* pObjData = NULL;
        DataRefs* pDataRefs = NULL;


        if (SUCCEEDED(SimConnect_Open(&hSimConnect, "Client Event", NULL, NULL, NULL, NULL))) {
            printf("Connected to MSFS2020!\n");
        }
        else {



            /* string str = "42";

             int num2 = stoi(str);

             cout << num2;

             */

            printf("Failed to Connect to MSFS2020\n");

        }
        //simVars
        hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ID_AP, "PLANE ALTITUDE", "Feet");
        //hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ID_AP, "AIRSPEED TRUE", "Knots");

        // Check simVars
        hr = SimConnect_RequestDataOnSimObject(hSimConnect, REQUEST_AP_SETTINGS, DEFINITION_ID_AP, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_ONCE);
        if (FAILED(hr))
        {
            printf("RequestDataOnSimObject for AutopilotData structure - error\n");
        }
        bRequestProcessed = false;
        while (!bRequestProcessed)
        {
            hr = SimConnect_GetNextDispatch(hSimConnect, &pData, &cbData);
            if (SUCCEEDED(hr))
            {

                pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA*)pData;
                pDataRefs = (DataRefs*)&pObjData->dwData;

                /* int altint;



                 altint = stoi (pDataRefs->altitude);



                 string str = "42";

                 int num2 = stoi(str);

                 cout << num2;
                 */


                 /*
                     printf("\rCurrent plane altitude: %.f feet", pDataRefs->altitude);
                     fflush(stdout);
                     */
                //This line of code is what im referring to
                printf("\rCurrent  altitude: %.f feet", pDataRefs->altitude);

                //printf("\rCurrent speed: %.f knots", pDataRefs->knots);
            }
        }

        // Close
        hr = SimConnect_Close(hSimConnect);

    return 0;
}
 
You requested to receive only once "SIMCONNECT_PERIOD_ONCE".
Look at SimConnect_PERIOD enumerator values.
ahh obviously.. Thanks for the help. simply replacing SIMCONNECT_PERIOD_ONCE with SIMCONNECT_PERIOD_SECOND fixed it. Thanks brother!
 
Back
Top