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

Working ADF code

Messages
135
Country
us-kentucky
Could someone post some known good code using:

execute_calculator_code("(A:ADF ACTIVE FREQUENCY:1, KHz)", &freq, NULL, NULL);

to get the ADF freq in FS9 (or if you have it in FS X that's ok too).

Can't seem to get it to work in either FS9 or FSX.

Patrick
 
Last edited:
You have to wait until time is moving forward in Sim Land.
Tested in FSX; you can put this code in the aircraft being loaded at startup:

MODULE_VAR elapsed_seconds = {ELAPSED_SECONDS};
double time_then;

case PANEL_SERVICE_PRE_UPDATE:
lookup_var(&elapsed_seconds);
if ( elapsed_seconds.var_value.n != time_then )
{
execute_calculator_code("(A:ADF ACTIVE FREQUENCY:1, KHz)", &freq, NULL, NULL);
}
time_then = elapsed_seconds.var_value.n;
break;

In my default flight, the ADF is set to 284. If you watch for it, you can see the display go from 0 to 284 a frame or two after the panel becomes visible.

Doug
 
Sorry, just realized that execute_calculator_code is a boolean function...
This works:

case PANEL_SERVICE_PRE_UPDATE:
if ( execute_calculator_code("(A:ADF ACTIVE FREQUENCY:1, KHz)", &freq, NULL, NULL))
{}
else freq = -1;
break;

Doug
 
Sorry, just realized that execute_calculator_code is a boolean function...
This works:

case PANEL_SERVICE_PRE_UPDATE:
if ( execute_calculator_code("(A:ADF ACTIVE FREQUENCY:1, KHz)", &freq, NULL, NULL))
{}
else freq = -1;
break;

Doug

Ok... I tried this:

Code:
wstring RadioPage::GetAdf1Active()
{
	FLOAT64	freq;
	WCHAR	freqStr[10] = {0};
	
	if (execute_calculator_code("(A:ADF ACTIVE FREQUENCY:1, KHz)", &freq, NULL, NULL))
	{
		// Freq valid
		swprintf_s(freqStr, 4, L"%04.1f", freq);
		return	freqStr;
	}
	else
	{
		freq = -1;
		return L"000.0";
	}
}

but it still crashes both FS9 and FS X. :mad:

The only reason I'm converting it to a wstring is because I'm using GDI+ to render it.

Patrick
 
Last edited:
How about this:
swprintf_s(freqStr, sizeof("000.0"), L"%04.1f", freq);

I don't think you have enough characters in the buffer.

Doug
 
How about this:
swprintf_s(freqStr, sizeof("000.0"), L"%04.1f", freq);

I don't think you have enough characters in the buffer.

Doug

You are BRILIANT. That did the trick. I'm guessing then that sizeof("000.0") doesn't equal 4. :D

So, maybe it equals 5. I'm going to try and better understand this, but thanks so much.
 
You are BRILIANT. That did the trick. I'm guessing then that sizeof("000.0") doesn't equal 4. :D

So, maybe it equals 5. I'm going to try and better understand this, but thanks so much.

Actually, sizeof("000.0") returns 6. Both the decimal point, and the terminating NULL count...
Glad you're back in business!

Doug
 
Actually, sizeof("000.0") returns 6. Both the decimal point, and the terminating NULL count...
Glad you're back in business!

Doug

Indeed. I just tested and verified that. I was concerned as I'm dealing with WCHAR*, but I guess since it is inside a wide-char function it understands we are talking about a wchar_t.

Those wchar_t 's are driving me crazy... but with Gdi+ you have no choice but to use them.

Thanks again.

Patrick
 
Back
Top