• 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 How to set COM Active Frequency with SimConnect

Messages
2
Country
china
Hi,
I am developing a tool with SimConnect and C#. I want to set the frequency in my tool and it will help me to set COM1 frequency in fsx, but I got a SIMCONNECT_EXCEPTION_DATA_ERROR during the action. So anyone knows how to fix this? Thanks a lot.

Here is related code:
Code:
//Data Definition
SimConnect.AddToDataDefinition(Definitions.SetComFrequency, "COM ACTIVE FREQUENCY:1", "Frequency BCD16", SIMCONNECT_DATATYPE.INT32, 0f, SimConnect.SIMCONNECT_UNUSED);
            SimConnect.RegisterDataDefineStruct<ComFrequency>(Definitions.SetComFrequency);

// ComFrequency Class
[StructLayout(LayoutKind.Sequential, Pack = 1)]
    public class ComFrequency
    {
        public uint Frequency;
    }

// Convert to BCD16
public static uint ToBcd16(uint n)
        {
            uint result = 0;
            var remainder = n%0x10;
            var quotient = n/0x10;
            if (!(quotient == 0 && remainder == 0))
                result += ToBcd16(quotient)*10 + remainder;
            return result;
        }

// Set the frequency
            var radioData = new ComFrequency();
            double freq;
            if (double.TryParse(tbCOM1Frequency.Text, out freq) && (freq >= 117.975) && (freq <= 136f))
            {
                radioData.Frequency = ToBcd16((uint) (freq%100*100 + 0.5));
                SimConnect?.SetDataOnSimObject(Definitions.SetComFrequency, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT,
                radioData);
            }
 
If the aircraft uses a standby com assigned in the aircraft cfg I don't think you can set active direct. I may be wrong though.
 
If the aircraft uses a standby com assigned in the aircraft cfg I don't think you can set active direct. I may be wrong though.

Thanks for your reply. I did notice that SimConnect document marks COM Active Frequency:Index as NOT SETTABLE, but the radio panel in FSInn can set the frequency and FSInn connect to FS via SimConnect too.
 
They might be using events rather than SetDataOnSimObject
 
If the aircraft uses a standby com assigned in the aircraft cfg I don't think you can set active direct. I may be wrong though.
You are not wrong. The only way to set active com or nav frequencies is to configure the standby to 0 in the aircraft.cfg file. At that point using the standby set events will in fact set the active frequencies.

It's rather a pain the arse to be frank, but it is what it is! :eek:
 
I've got an example off the net that appears to do it a bit differently. It sets the Standby, then Swaps the Standby and Active frequency. The Standby in the aircraft.cfg does not seem to be set to 0.
I have never had any reason to use the code, but it does appear to work, so unless I've missed something, it may be a better solution.

fsx_simconnect.MapClientEventToSimEvent(EVENT_ID.EVENT_COM1Swap, "COM_STBY_RADIO_SWAP")
fsx_simconnect.MapClientEventToSimEvent(EVENT_ID.EVENT_COM1SBset, "COM_STBY_RADIO_SET")

fsx_simconnect.TransmitClientEvent(DEFINITIONS.Struct1, EVENT_ID.EVENT_COM1SBset, "&H12645", hSimconnect.group1, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY)
fsx_simconnect.TransmitClientEvent(DEFINITIONS.Struct1, EVENT_ID.EVENT_COM1Swap, 0, hSimconnect.group1, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY)
 
Back
Top