How to read out COM Frequencies (by Sim Variables, in python)


i am trying to read out Com1 Active and Standby by using Sim Variables “COM_ACTIVE_FREQUENCY:1” and “COM_STANDBY_FREQUENCY:1”.
The result i should get would be in “Frequency BCD16” Format but i don’t really understand how to convert this into a Decimal Value.
The numbers i get by using print() just don’t make any sense, can somebody help me out?

I am using python and the following code:

It gives me:
“6144.0” for “118.000” in COM1 Active, and
“13824.0” for “136.000” in COM1 Standby.

Why does it spit out a float value?
Shouldn’t i get a “4-digit” value or something similar to this “0x0970”?

1 Like

I tried this conversion and it seemed accurate:

// Converts from binary coded decimal to integer
public static uint Bcd2Dec(uint num) { return HornerScheme(num, 0x10, 10); } 
/// Converts from integer to binary coded decimal
public static uint Dec2Bcd(uint num) { return HornerScheme(num, 10, 0x10); } 

static private uint HornerScheme(uint Num, uint Divider, uint Factor) 
     uint Remainder = 0, Quotient = 0, Result = 0; 
     Remainder = Num % Divider; Quotient = Num / Divider; 
     if (!(Quotient == 0 && Remainder == 0)) 
         Result += HornerScheme(Quotient, Divider, Factor) * Factor + Remainder; return Result; 

With COM1 set to 120.95 in the sim, I got 8341.00. After decoding the value using BCD2DEC() function above, I got 2095. Convert to double, divide by 100, add 100.00 and you’ll have the 120.95.


Thanks for confirming that its correct, was able to find a python function to convert to and from BCD.

I did the same in C++. The problem is that frequencies have 3 decimal digits. Indeed, 8341 in BCD is 120.95 (or 120.950), but how is the 120.955 frequency coded in BCD?
What I found using SimConnect is that 127.900 and 127.905 both give the same value in BCD, which is 10128. So the last digit is missing… How can I get it for proper display?

Any idea is welcome.

In my case it turned out that i don’t need to convert if i just like to get the Frequency by SimVar “COM ACTIVE FREQUENCY: index”.

By odwdinc’s Python interface i use "aq.get(“COM_ACTIVE_FREQUENCY:1” and receive Active COM1 without any conversion required. Not sure if the SDK documentation is wrong or i am missing something about the Python Interface i am using but since i change frequencies now by Decrementing and Incrementing Events i don’t need to do any BCD conversions.

However there is your issue discussed here which might help in C++ as well.