How to read SimVar of type STRING

I’m having some trouble when dealing with some SimVars with SimConnect. Not sure if it has to do with the fact that the variables are string, because other variables seem to be working fine (so far not discovered issues).

Examples of variables I’m dealing with:

  • TITLE
  • ATC FLIGHT NUMBER
  • Category
  • COM ACTIVE FREQ TYPE:1

I seem not to be able to register them using the SimConnect AddToDataDefinition (I’m using the C# wrapper).

m_SimConnect.AddToDataDefinition(
    (SIMCONNECT_DEFINITION_ID)v.uDefineID,
    v.sVarName,            // Example: "TITLE"
    v.sUnit,               // Example: "STRING"
    v.scDataType,          // Example: SIMCONNECT_DATATYPE.STRING256
    0.0f,
    SimConnect.SIMCONNECT_UNUSED);

This results in a call to the SimConnect RecvExceptionEventHandler with the data SIMCONNECT_EXCEPTION.NAME_UNRECOGNIZED.

But if I use my WASM Module and use execute_calculator_code(pVar->Name, nullptr, nullptr, &ps), where the Name is “(A:TITLE,string)”, then the string variable referenced by ps is returning the value “Airbus A320 Neo FlyByWire”. So it looks like the variable exists!

If I’m using the same concepts with variables such as “AUTOPILOT ALTITUDE LOCK VAR:3”, “KOHLSMAN SETTING HG:1” or “LIGHT POTENTIOMETER:84”, then this works perfect with AddToDataDifinition. So no problem with my code. But these are variables with units feet, inHg and percent respectively, and not string.

Anybody here that has a clue, or the same experience?

I found the solution myself. Coincidently, I read the below in the Prepare3D documentation (for some reason, the Microsoft SimConnect SDK documentation website behaves very weird).

When the units are listed as a structure or as a string, enter the empty string, or simply NULL , in the units parameter of this function call.

I simply changed my code as below, and now it works as a charm!

m_SimConnect.AddToDataDefinition(
    (SIMCONNECT_DEFINITION_ID)v.uDefineID,
    v.sVarName,
    v.sUnit == "STRING" ? "" : v.sUnit,
    v.scDataType,
    0.0f,
    SimConnect.SIMCONNECT_UNUSED);
3 Likes