• 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.

FSX AI TRAFFIC STATE only answers INIT (Simconnect)

Messages
17
Country
spain
I am trying to know the status of the airplane that is under ATC control with the var AI TRAFFIC STATE .
I only get the value "init" as a result. After three days, just "init" "init"....
I need help. Or on the contrary my poor brain will burn.

struct StructAITRAFFICSTATE
{
char AIState[256];
};
hr = SimConnect_AddToDataDefinition(SIMGetRh, DEFINITION_AiTrafic, "AI TRAFFIC STATE", "",
SIMCONNECT_DATATYPE_STRING256, 0, AI_TRAFFIC_STATE);
case REQUEST_AITRAFIC:
{

(int)pObjData->dwDefineCount;
StructAITRAFFICSTATE *ps = (StructAITRAFFICSTATE*)&pObjData->dwData;
PPP = (char*)&pObjData->dwData;
printf("\n REQUEST_AITRAFIC %s \n", KKK.c_str());

break; }
OUTPUT:

REQUEST_AITRAFIC init

REQUEST_AITRAFIC init

REQUEST_AITRAFIC init

Thank you for your answers
 
You have provided so little actual code that I don't think anyone could provide insight, to be honest.
 
Thank you for your comment .. WarpD
I'm sorry..🥺
I provide more code, will it be enough?
HANDLE SIMGetRh = NULL;

struct StructAITRAFFICSTATE
{
char AIState[256];
};

static enum DATA_DEFINE_ID {
DEFINITION_AiTrafic,
};

static enum DATA_REQUEST_ID {
REQUEST_AITRAFIC,
};

static enum DATA_NAMES {
AI_TRAFFIC_STATE,
};
//---------------------------------------------------------------------------

void SimuGetVar::ini()
{
HRESULT hr;
if (SUCCEEDED(SimConnect_Open(&SIMGetRh, "SimuGetVar", NULL, 0, 0, 0)))
{
conexStat = 1;

hr = SimConnect_AddToDataDefinition(SIMGetRh, DEFINITION_AiTrafic, "AI TRAFFIC STATE", "",
SIMCONNECT_DATATYPE_STRING256, 0, AI_TRAFFIC_STATE);

hr = SimConnect_RequestDataOnSimObject(SIMGetRh, REQUEST_AITRAFIC, DEFINITION_AiTrafic,
SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_SECOND);

}
}

//--------------------------------------------------------------------------
SimuGetVar::job()
{
std::string PPP;
SIMCONNECT_RECV* pData;
DWORD cbData;
HRESULT hr;

hr = SimConnect_GetNextDispatch(SIMGetRh, &pData, &cbData);
if (SUCCEEDED(hr))
{
switch (pData->dwID)
{
case SIMCONNECT_RECV_ID_EXCEPTION:
printf("\ <<<<<<<<<<<<<<<<<<<<<SIMCONNECT_RECV_ID_EXCEPTION = <<<<<<<<<<<<<<<<<<<<");
break;
case SIMCONNECT_RECV_ID_EVENT:
printf("\nSIMCONNECT_RECV_ID_EVENT = > %d <");
break;
case SIMCONNECT_RECV_ID_EVENT_FILENAME:
printf("\n SIMCONNECT_RECV_ID_EVENT_FILENAME \n");
break;
case SIMCONNECT_RECV_ID_SIMOBJECT_DATA:
{
SIMCONNECT_RECV_SIMOBJECT_DATA *pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA*)pData;
switch (pObjData->dwRequestID)
{
case REQUEST_AITRAFIC:
{
(int)pObjData->dwDefineCount;
StructAITRAFFICSTATE *ps = (StructAITRAFFICSTATE*)&pObjData->dwData;
PPP = (char*)&pObjData->dwData;
printf("\n REQUEST_AITRAFIC %s \n", PPP.c_str());
break;
}
default:
printf("\nGET ID: %d\n", pS->datum[count].id);
break;
}
}
}
}
}
 
Ok... I think you're using SimConnect_RequestDataOnSimObject incorrectly. Here's the info regarding the ObjectID variable that is passed to this function:
Code:
ObjectID
  [in]  Specifies the ID of the Flight Simulator object that the data should be about. This ID can be SIMCONNECT_OBJECT_ID_USER (to specify the user's aircraft) or obtained 
        from a SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE structure after a call to SimConnect_RequestDataOnSimObjectType.

I believe to get AI traffic info, you must first make a call to SimConnect_RequestDataOnSimObjectType to get a list of sim object ID values that represent sim objects around the user aircraft. Right now, it appears in your code you're requesting AI TRAFFIC STATE on own user's vehicle.
 
Thank you for your comment .. @WarpD
There is very little information on this topic, I have searched and searched but with little result.
SIMCONNECT_OBJECT_ID_USER (to specify the user's aircraft)
From the explanation I deduce, with SimConnect_RequestDataOnSimObjectType we force the sim to initialize the data for AI TRAFFIC STATE.
I created this for testing.
At initialization, SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE REQUEST_TEST_Object data appears for several aircraft, including number 1 in the INIT state.
After by SIMCONNECT_RECV_ID_SIMOBJECT_DATA: data appears every second only from plane 1 in INIT.
Any ideas to guide me... or am I blind?:cool:

Code created for testing:
C++:
HANDLE SIMGetTESTRh = NULL;

struct StructOneDatum_TEST {
    int id;
    float value;
};

#define maxReturnedItems 1

struct StructDatum_TEST {
    StructOneDatum_TEST datum[maxReturnedItems];
};

struct StructAITRAFFICSTATE_TEST
{
    char AIState_TEST[256];
};

static enum DATA_DEFINE_ID_TEST {
    DEFINITION_TEST_AiTrafic,

};

static enum DATA_REQUEST_ID_TEST {
    REQUEST_TEST_Object,
    REQUEST_TEST_AITRAFIC,
};

static enum DATA_NAMES_TEST {
    AI_TRAFFIC_STATE,
};

SimuGetTEST::SimuGetTEST()
{}


void SimuGetTEST::ini()
{
    HRESULT hr;
    if (SUCCEEDED(SimConnect_Open(&SIMGetTESTRh, "SimuGetVar", NULL, 0, 0, 0)))
    {
        conexStat = 1;

        hr = SimConnect_AddToDataDefinition(SIMGetTESTRh, DEFINITION_TEST_AiTrafic, "AI TRAFFIC STATE", "",
            SIMCONNECT_DATATYPE_STRING256, 0, AI_TRAFFIC_STATE);

        hr = SimConnect_RequestDataOnSimObjectType(SIMGetTESTRh, REQUEST_TEST_Object, DEFINITION_TEST_AiTrafic, 50000, SIMCONNECT_SIMOBJECT_TYPE_AIRCRAFT);

        hr = SimConnect_RequestDataOnSimObject(SIMGetTESTRh, REQUEST_TEST_Object, DEFINITION_TEST_AiTrafic, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_SECOND);

    }
}

void SimuGetTEST::job()
{
    std::string PPP;
    SIMCONNECT_RECV* pData;
    DWORD cbData;
    HRESULT hr;

    hr = SimConnect_GetNextDispatch(SIMGetTESTRh, &pData, &cbData);
    if (SUCCEEDED(hr))
    {
        switch (pData->dwID)
        {
        case SIMCONNECT_RECV_ID_EXCEPTION:
        {printf("\ <<<<<<<<<<<<<<<<<<<<<SIMCONNECT_RECV_ID_EXCEPTION = <<<<<<<<<<<<<<<<<<<<");
        SIMCONNECT_RECV_EXCEPTION *except = (SIMCONNECT_RECV_EXCEPTION*)pData;
        printf("\n\n***** EXCEPTION=%d SendID=%d Index=%d cbData=%d\n", except->dwException, except->dwSendID, except->dwIndex, cbData); }
        break;

        case SIMCONNECT_RECV_ID_EVENT:
            printf("\nSIMCONNECT_RECV_ID_EVENT = > %d <");
            break;

        case SIMCONNECT_RECV_ID_EVENT_FILENAME:
            printf("\n SIMCONNECT_RECV_ID_EVENT_FILENAME \n");
            break;

        case SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE:
        {
            printf("\n SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE ");

            SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE *pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE*)pData;
            switch (pObjData->dwRequestID)
            {
            case REQUEST_TEST_Object:
            {DWORD ObjectID = pObjData->dwObjectID;
            StructAITRAFFICSTATE_TEST *pS = (StructAITRAFFICSTATE_TEST*)&pObjData->dwData;
            printf(" REQUEST_Object ObjectID=%d Data= %s Count = %d\n ", ObjectID, pS->AIState_TEST, pObjData->dwDefineCount); } // while (count < (int)pObjData->dwDefineCount)
            break;
            default:
                printf("\nGET DEFAULT_A %d\n", pObjData->dwRequestID);
                break;
            }
        }
        break; //-----------------

        case SIMCONNECT_RECV_ID_SIMOBJECT_DATA:
        { printf("\n SIMCONNECT_RECV_ID_SIMOBJECT_DATA: ");
        {SIMCONNECT_RECV_SIMOBJECT_DATA *pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA*)pData;
        switch (pObjData->dwRequestID)
        {
        case REQUEST_TEST_AITRAFIC:
        {
            (int)pObjData->dwDefineCount;
            StructAITRAFFICSTATE_TEST *ps = (StructAITRAFFICSTATE_TEST*)&pObjData->dwData;
            PPP = (char*)&pObjData->dwData;
            printf("\n REQUEST_AITRAFIC %s \n", PPP.c_str());
            break;
        }
        case REQUEST_TEST_Object:
        {DWORD ObjectID = pObjData->dwObjectID;
        StructAITRAFFICSTATE_TEST *pS = (StructAITRAFFICSTATE_TEST*)&pObjData->dwData;
        printf(" REQUEST_Object ObjectID=%d Data= %s Count = %d\n ", ObjectID, pS->AIState_TEST, pObjData->dwDefineCount);
        }
        break;

        default:
            printf("\nGET DEFAULT_B %d \n", pObjData->dwRequestID);
            break;
        }
        }

        }

        }
    }
}

Console result:
SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE REQUEST_Object ObjectID=2997 Data= enroute Count = 1
SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE REQUEST_Object ObjectID=2440 Data= enroute Count = 1
SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE REQUEST_Object ObjectID=2801 Data= enroute Count = 1
SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE REQUEST_Object ObjectID=2554 Data= sleep Count = 1
SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE REQUEST_Object ObjectID=2755 Data= enroute Count = 1
SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE REQUEST_Object ObjectID=1 Data= init Count = 1
SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE REQUEST_Object ObjectID=2435 Data= enroute Count = 1
SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE REQUEST_Object ObjectID=2634 Data= enroute Count = 1
SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE REQUEST_Object ObjectID=2837 Data= enroute Count = 1

SIMCONNECT_RECV_ID_SIMOBJECT_DATA: REQUEST_Object ObjectID=1 Data= init Count = 1
SIMCONNECT_RECV_ID_SIMOBJECT_DATA: REQUEST_Object ObjectID=1 Data= init Count = 1
SIMCONNECT_RECV_ID_SIMOBJECT_DATA: REQUEST_Object ObjectID=1 Data= init Count = 1
SIMCONNECT_RECV_ID_SIMOBJECT_DATA: REQUEST_Object ObjectID=1 Data= init Count = 1
SIMCONNECT_RECV_ID_SIMOBJECT_DATA: REQUEST_Object ObjectID=1 Data= init Count = 1
 
Last edited:
First - When you post code... use the "code" format specifier to wrap around your code so that it retains the proper formatting.

As for your results... I see eight AI traffic with states of 'enroute' or 'sleep'. I do not know what ObjectID #1 is (might be own aircraft)... but you already have eight AI traffic results with different states. Also... those ObjectID values are what you must pass to SimConnect_RequestDataOnSimObject instead of SIMCONNECT_OBJECT_ID_USER.
 
Thank you for your comment .. @WarpD

Edited Code. :rolleyes:
Well, now you can see the status of the aircraft: "init" "sleep" "flt plan" "startup" "preflight support" ....
To see the status of my aircraft. According to the SDK:
1.-Giving the value 0 for the radius in SimConnect_RequestDataOnSimObjectType
2.- Giving SimConnect_RequestDataOnSimObject the value
/ Object types
enum SIMCONNECT_SIMOBJECT_TYPE
{ SIMCONNECT_SIMOBJECT_TYPE_USER, .
. .
The latter seems the best option, it is a 0 and would be valid for the MP case.

Situation:
My flight with IFR authorized and with a runway assigned for takeoff.
My joy returns to zero...
my aircraft is always INIT.
What concept is wrong or do I not see?
 
Your aircraft is not AI and I don't know why you would think it should return an AI state. It is not AI.
 
Simply in the return 0/1 that matches the state of the IFR/VFR user's aircraft in the reading of: AI TRAFFIC ISIFR.
I expected to receive by reading: AI TRAFFIC STATE discriminating by the ObjID.
I don't understand why you can't get a detailed status of the aircraft from user.
So where can I get those states or equivalents?
 
Back
Top