Issue Updating COM1 Frequency in MSFS via Python and SimConnect

I’m trying to use Python and SimConnect to control the COM1 frequency in MSFS 2020. I’ve got some code to allow me to use a VHF radio panel to adjust the frequency in the python script, but I’m having trouble getting it to show up correctly in the simulator.

from SimConnect import SimConnect, AircraftRequests

# Connect to SimConnect
sm = SimConnect()
aq = AircraftRequests(sm, _time=200)

# Initialize COM1 frequency
current_freq = aq.get("COM_ACTIVE_FREQUENCY:1")
print(f"Starting Frequency: {current_freq} MHz")

# Main loop to send commands and update frequency
while True:
    command = input("Enter command: ")
    if command == "R":
        current_freq += 0.005  # Adjust frequency up
        print(f"Turned Right: Increasing frequency. New frequency: {current_freq} MHz")
    elif command == "L":
        current_freq -= 0.005  # Adjust frequency down
        print(f"Turned Left: Decreasing frequency. New frequency: {current_freq} MHz")

    # Send updated frequency to MSFS
    aq.set("COM_ACTIVE_FREQUENCY:1", round(current_freq, 3))  # Update frequency in MSFS
    print(f"Updated Frequency: {current_freq} MHz")

I can adjust the frequency in the Python script, but it doesn’t reflect in MSFS. I’m using SimConnect to send the frequency change, but MSFS isn’t picking it up. Ive read so many different things about sending events, different types of commands to send the sim, but my lack of development experience is starting to hold me back.

Any help on what I might be missing or the right SimConnect commands to use would be appreciated

Hi,

This is probably not the right place to post, no offense meant. The general forums have a SDK/SimConnect category/tag for example, and other sites like FSDeveloper.

Having said that, there are some issues in your code (may not be an exhaustive list, just what stands out to me).

  1. Sim Var names don’t have any underscores. I know they’re listed in the index that way (one of the mysteries of the world), but you need to look at the actual docs.
  2. And looking at those docs more carefully reveals that the variable is not settable.
  3. You also need to specify a Unit type when requesting Sim Vars. I’m not familiar with the Python lib to know the correct syntax, but I don’t see any unit specifier in your aq.get() call. (IIRC you can use [M|K]Hz as the unit for those and skip the BCD conversion on your end.)
  4. To set the frequency you can use a Key Event. For example COM_RADIO_SET_HZ
    • These do have underscores in the names.
    • Note that it expects a whole number, not fractions, so you have to multiply fractional values up to whole Hz.
    • Note there are many other related events including for increment/decrement.

HTH,
-Max

In addition to Max’s good suggestions, VHF COM channel spacing is also not 5 kHz, but 8.33 or 25 kHz, with some somewhat weird rounding to the nearest 5 kHz, all for (IRL) historical reasons. For this reason simply incrementing by 5 kHz will not work correctly, as not all 5 kHz multiples are valid VHF COM channels.

You could use the COM_RADIO_FRACT_INC_CARRY and COM_RADIO_FRACT_DEC_CARRY key events (note that the underscores are needed for key events, contrary to simvars), and substituting COM2/3 if you need those two.

The COM SPACING MODE:index simvar tells you whether 8.33 or 25 kHz spacing is active (thus how the INC/DEC events will increment/decrement). The key event COM_1_SPACING_MODE_SWITCH allows you to toggle between 8.33 and 25 kHz.