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

MSFS Simconnect BCD16 and BCO16

Messages
11
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
Code:
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x100)]
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?

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();
            }
        }
 
Messages
1,243
Country
canada
Just a shot in the dark. Have you seen this thread?


The SDK is wrong re BCD BCO
 
Messages
11
Just a shot in the dark. Have you seen this thread?


The SDK is wrong re BCD BCO
Yes I have

But I havent been able to understand where and how to add those lines of code...
Code:
 char[] xpdrS;
            string.Format(xpdrS, "%d%d%d%d",
            (xpdr >> 12) & 0x000f,
            (xpdr >> 8) & 0x000f,
            (xpdr >> 4) & 0x000f,
            xpdr & 0x000f);

            int xpndrI = int.Parse(xpdrS);

I don't even know if that's C# at all...
 
Messages
1,243
Country
canada
Are you getting any number at all? What is it. Maybe you are getting a correct number, but decoding in incorrectly. I notice a return HornerScheme(num, 0x10, 10) in your code - and N4GIX says in that thread it would not be correct.

It's a bunch of bit shifting.
 
Messages
1,243
Country
canada
So I compiled the simvars program in the SDK samples. I can give you the transponder code. If I set it as bco16 a code like 0007 is 7. If i set it to 7777 I get 30583. If I set the units to enum. I actually get the number on the transponder. setting it to 7777 I get 7777 as the result.


now 30583 is 111011101110111 in bits - see the octal 7 => 111. I get four 1110's

Now your code has units for Transponder as Mhz. It's not a frequency it's just a number. So try enum instead of Mhz as the units.

1603243657561.png


1603243701694.png


EDIT: I think it is also important that the lit of struct variables matches the AddtoDataDefinitions list. I see you are missing
public double COM2frq;
public double COM1stby;
public double COM2stby;
public double NAV1frq;
public double NAV2frq;
public double NAV1stby;
public double NAV2stby;

before the transponder request
 
Last edited:
Messages
11
I managed to get the correct Transponder code.
Code:
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "TRANSPONDER CODE:1", "enum", SIMCONNECT_DATATYPE.INT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

I'm now trying to make sense of the COM readings I'm getting
Code:
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "COM ACTIVE FREQUENCY:1", "Frequency BCD16", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "COM STANDBY FREQUENCY:1", "Frequency BCD16", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "COM ACTIVE FREQUENCY:2", "Frequency BCD16", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "COM STANDBY FREQUENCY:2", "Frequency BCD16", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

for 118.000 I receive 6144
for 136.900 I receive 13968

Although on the NAV frequencies it seems to be working xD
Code:
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "NAV ACTIVE FREQUENCY:1", "MHz", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "NAV STANDBY FREQUENCY:1", "MHz", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "NAV ACTIVE FREQUENCY:2", "MHz", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "NAV STANDBY FREQUENCY:2", "MHz", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
 
Messages
1,243
Country
canada
your 6144 is 1800 hex so prefix with a 1 and you get 118.00

similarly 13968 is 3690 hex and prefix with a 1 and get 136.90

1603322884241.png



for me 9349 is 2485 hex prefix with 1 and get 124.85

6464 is 1940 prefix with 1 is 119.40 for the BCD16 ones but the Megahertz are the real numbers
 
Messages
6
Country
portugal
Try this:

Code:
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "COM ACTIVE FREQUENCY:1", "MHz", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "COM STANDBY FREQUENCY:1", "MHz", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "COM ACTIVE FREQUENCY:2", "MHz", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "COM STANDBY FREQUENCY:2", "MHz", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

More here.
 
Messages
11
I've managed to solve the problem with the frequencies by reading them as KHz and then multiplying that value by 0.001 to get MHz

But now I've run into another problem:
As soon as I try to read more than 27 variables, the value of those extra vars doesn't change. Even if I set them to be a value I know should work, nothing changes...
Can the cause may be, that the Struct is to small to handle that many vars or is it something else?

I've tried to make multiple Structs but as soon as I connect to MSFS2020 an error on this line (Struct2)
C#:
Struct1 struct1 = (Struct1)data.dwData[0];
Struct2 struct2 = (Struct2)data.dwData[0];
comes up, saying "System.InvalidCastException: Specified cast is not valid"
 
Messages
11
Huh??? The sim can return them as Mhz which eliminates the extra step. Why would you NOT do that?
I swear the last time I tried i got a jumbled mess of numbers, but now I've tried again( with MHz) and it worked xD

But anyway can someone help me with my other problem or is there already a thread explaining how to deal with that issue?
 
Messages
497
Country
unitedstates
Ever wondered why Aviation Equipment like Transponders, only have numbers 0-7 ?? ( and not 0-9)
ie 3 bits per digit * 4 digits = 3 x 4 = 12 + 1 to identify if Transponder code or Altitude... + 4 digit identifier so only needs to transmit a 16 bit code, and the electronics are a LOT simpler than if the Codes were 0000 - 9999

Remember, back in day when Transponders were 1st invented & used, there was no modern digital electronic chips ....
 
Last edited:
Top