- Messages
- 639
- Country

When one creates structs for data requests to SimConnect one most create entries in DEFINITIONS and DATA_REQUESTS enumerations (I am using managed code, C#). In managed code one must also decorate the struct with InteropServices.StructLayout and some parameters to indicate it is sequential.
In registering the request one must also use AddToDataDefinition() prior to RegisterDefinition(). I know that the order of the data definition additions must match the order of the fields defined in the struct.
However, it is unclear to me how the definition of the member variables (private, internal, public, protected) actually affect whether they are taken into consideration or not. I also don't know if there is a way to skip some fields or properties, for example when one has a computed property that converts a raw value to something else.
In the above struct, only the first member variable should be used, that is GaugeStatus declared as int which is an Int32 in SimConnect. I don't know if putting the SimConnect private instance before it will skip it from the definition or will use that instead of my intended member variable.
Also, with the above definition the value which is an enum of 0..2 always gives me a SIMCONNECT_EXCEPTION_INVALID_DATA_SIZE.
In registering the request one must also use AddToDataDefinition() prior to RegisterDefinition(). I know that the order of the data definition additions must match the order of the fields defined in the struct.
However, it is unclear to me how the definition of the member variables (private, internal, public, protected) actually affect whether they are taken into consideration or not. I also don't know if there is a way to skip some fields or properties, for example when one has a computed property that converts a raw value to something else.
Code:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
struct TestDR
{
internal int GaugeStatus; // THIS member should correspond to the AddToDataDefinition item 1
internal GaugeStateMode TestGaugeStatus
{
get { return (GaugeStateMode)GaugeStatus; }
set { GaugeStatus = (int)value; }
}
private SimConnect simconnect;
public TestDR(SimConnect simConnect) : this()
{
this.simconnect = simConnect;
this.TestGaugeStatus = GaugeStateMode.OK;
}
public void Register()
{
this.simconnect.AddToDataDefinition(DEFINITIONS.TestDR, "PARTIAL PANEL HEADING:0", SimUnits.ENUM, SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
this.simconnect.RegisterDataDefineStruct<TestDR>(DEFINITIONS.TestDR);
}
public void RequestData()
{
this.simconnect.RequestDataOnSimObject(DATA_REQUESTS.TestRequest, DEFINITIONS.TestDR, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD.ONCE, SIMCONNECT_DATA_REQUEST_FLAG.DEFAULT, 0, 1, 1);
}
public void Receive(TestDR receivedData)
{
this.TestGaugeStatus = receivedData.TestGaugeStatus;
}
public void SendData()
{
this.simconnect.SetDataOnSimObject(DEFINITIONS.TestDR, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, this);
}
}
In the above struct, only the first member variable should be used, that is GaugeStatus declared as int which is an Int32 in SimConnect. I don't know if putting the SimConnect private instance before it will skip it from the definition or will use that instead of my intended member variable.
Also, with the above definition the value which is an enum of 0..2 always gives me a SIMCONNECT_EXCEPTION_INVALID_DATA_SIZE.