Sign in to follow this  
kiek

How to get the active NAV1 frequency in C++?

Recommended Posts

Hi,I'm having a difficulty in C++ obtaining the NAV1 active frequency (in a native Win32 application). In my panel the frequency reads 107.20I call a SimConnect_AddToDataDefinition with the following parameters "Nav active frequency:1", "MHz" and SIMCONNECT_DATATYPE_FLOAT64 When the value returns I try to interpret pObjData->dwData as double, but I do not know how to convert that to integer?????If I convert to int (to get the whole value) I get a strange result.Note that if I use SIMCONNECT_DATATYPE_INT32 and I interpret the pObjData->dwData as int, I get the correct whole value 107, but then I miss the decimal part .20Any help would be appreciated.Nicohttp://www.nicokaan.nl

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

>I call a SimConnect_AddToDataDefinition with the following>parameters "Nav active frequency:1", "MHz" and>SIMCONNECT_DATATYPE_FLOAT64I've always found it best to read it as "frequency BCD16", not MHz, with type INT32. This is the native format in FS. You'll get 0x0720 for a frequency of 107.20. The inital 1 is assumed (it is always 1).>When the value returns I try to interpret pObjData->dwData as>double, but I do not know how to convert that to integer?A DOWRD value is only 4 bytes in any case. The double is 8 bytes. If you've definitely read the 8 bytes just read is using a cast:double dFrequency = *((double *) &pObjData->dwData);RegardsPete

Share this post


Link to post
Share on other sites

Hi Pete,Thank you for your help. Your cast works perfectly! I was under the impression that a DWORD was 8 bytes too, but you have opened my eyes.I also did not know that we have the freedom to choose BCD16 instead of MHz; the Simconnect documentation is not very eleborate on that. But good to know.Thanks again.Nicohttp://www.nicokaan.nl

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this