I'm programming a Windows Form C# to read and write some parameters into the new MSFS2020. Im trying to read the frequencies from the simulator with the help of SimConnect, but I can't get any number that makes sense... (At least not for the frequencies and the Transponder code, literally all that is coded in BCD16 and BCO16)
I already looked at some examples but I wasn't able to understand them. One of them said, that removing
would fix that problem, but every time I try to remove that line the code gives out an error...
Is there another way of making sense of the numbers I'm receiving?
I already looked at some examples but I wasn't able to understand them. One of them said, that removing
Code:
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x100)]
Is there another way of making sense of the numbers I'm receiving?
Code:
private void initDataRequest()
{
try
{
my_simconnect.OnRecvOpen += new SimConnect.RecvOpenEventHandler(simconnect_OnRecvOpen);
my_simconnect.OnRecvQuit += new SimConnect.RecvQuitEventHandler(simconnect_OnRecvQuit);
my_simconnect.OnRecvException += new SimConnect.RecvExceptionEventHandler(simconnect_OnRecvException);
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Title", null, SIMCONNECT_DATATYPE.STRING256, 0.0f, SimConnect.SIMCONNECT_UNUSED);
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Latitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Longitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Heading Degrees True", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Ground Altitude", "meters", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "NUMBER OF ENGINES", "number", SIMCONNECT_DATATYPE.INT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "COM ACTIVE FREQUENCY:1", "MHz", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "TRANSPONDER CODE:1", "MHz", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "AUTOPILOT MASTER", null, SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
my_simconnect.RegisterDataDefineStruct<Struct1>(DEFINITIONS.Struct1);
my_simconnect.OnRecvSimobjectDataBytype += new SimConnect.RecvSimobjectDataBytypeEventHandler(simconnect_OnRecvSimobjectDataBytype);
}
catch (COMException op)
{
MessageBox.Show(op.Message, "ERR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct Struct1
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x100)]
public string title;
public double latitude;
public double longitude;
public double trueheading;
public double altitude;
public int numberofengs;
public double COM1frq;
public double COM2frq;
public double COM1stby;
public double COM2stby;
public double NAV1frq;
public double NAV2frq;
public double NAV1stby;
public double NAV2stby;
public int Transpcode;
public double DME1dist;
public double DME2dist;
public bool COM1sound;
public bool COM2sound;
public int AP;
}
/// /// Converts from binary coded decimal to integer /// /// ///
//public static uint Bcd2Dec(uint num) { return HornerScheme(num, 0x10, 10); }
private Microsoft.FlightSimulator.SimConnect.SimConnect my_simconnect;
private string output;
private int response;
const int WM_USER_SIMCONNECT = 0x402;
private void simconnect_OnRecvSimobjectDataBytype(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE data)
{
if (data.dwRequestID == 0)
{
Struct1 struct1 = (Struct1)data.dwData[0];
lblcom1frq.Text = struct1.COM1frq.ToString();
lblcom2sound.Text = struct1.AP.ToString();
lbltranspcode.Text = struct1.latitude.ToString();
//NoOfEngs.Text = struct1.numberofengs.ToString();
}
}