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

Get XPNDR Code in External App

Messages
34
Country
unitedkingdom
im currently writing an external application to FS, i have been told it is easily possible to retrieve the Transponder Code Directly from FS9 and not via FSUIPC?

i have been told its the variable: "7C4h"?

im currently writing this app in C#
 
im currently writing an external application to FS, i have been told it is easily possible to retrieve the Transponder Code Directly from FS9 and not via FSUIPC?

SimConnect will allow you to do so without FSUIPC, however, it is only available for FSX. While it is possible in C++ to do so without either, you would need intimate knowledge of FS9, and very advanced programming skills (like Peter).


i have been told its the variable: "7C4h"?

This is a reference to the variable in FSUIPC's table (although I did not look it up, so I can't say if it is correct).

Patrick
 
ok, then thanks, in that case then, does anyone know how to convert BCD back into a c# String?

its just im trying to get the transponder code out i have managed to get the BCD value but im unsure of how to read that as its normal value?
 
ok, then thanks, in that case then, does anyone know how to convert BCD back into a c# String?

its just im trying to get the transponder code out i have managed to get the BCD value but im unsure of how to read that as its normal value?

The transponder isn't in BCD, but rather is returned in hexidecimal. The following is a simple method in C to translate the hex into decimal:

Code:
	FLOAT64 high_units_right = 0;	//XPDR active fractions
	FLOAT64 high_units_left = 0;		
	FLOAT64 low_units_right = 0;	
	FLOAT64 low_units_left = 0;
	FLOAT64 xpdr = 0;


/* XPNDR Hex Conversion */
			//Clear out the previous displayed transponder code

			high_units_left = 0;	//Thou
			high_units_right = 0;	//Hun
			low_units_left = 0;	//Ten
			low_units_right = 0;	//Unit

			//Get the current code

			lookup_var(&trans);
			
			xpdr = trans.var_value.d; 		
	
			//Run a continous loop to break down the return into decimal figures

			while (xpdr > 4095)
			{
				high_units_left = high_units_left + 1;
				xpdr = xpdr - 4096;
			}
			while (xpdr > 255)
			{
				high_units_right = high_units_right + 1;
				xpdr = xpdr - 256;
			}
			while (xpdr > 15)
			{
				low_units_left = low_units_left + 1;
				xpdr = xpdr - 16;
			}
			low_units_right = xpdr;
			//At this point we have the new transponder code so go and display it
}

Alternatively, you can do the same thing in a string conversion:

Code:
	VAR32 xpdr = 0;

	lookup_var(&trans);
	xpdr = trans.var_value.d; 

	char xpdrS[10]; 
	wsprintf(xpdrS, "%d%d%d%d", (xpdr >>12) & 0x000f, (xpdr >>8) & 0x000f, 
		(xpdr >>4) & 0x000f, xpdr & 0x000f);
 
Last edited:
The transponder isn't in BCD, but rather is returned in hexidecimal.

Are you sure? i know the its been mentioned on the Simflight forums that its returned as Hex etc but in the FSUIPC SDK it says:
Transponder setting, 4 digits in BCD format: 0x1200 means 1200 on the dials.

i already have used C# to get The Transponder code but for a code of 0010, its returning a result of 16?
 
Are you sure? i know the its been mentioned on the Simflight forums that its returned as Hex etc but in the FSUIPC SDK it says:


i already have used C# to get The Transponder code but for a code of 0010, its returning a result of 16?

The returns for both the ADF and the transponder, despite the comment in the SDK that the transponder return is in octal, are actually in hex so that "octal" may have been a reference to the real-world.

The FSX SDK document describing the variables states that the transponder is in BCO16 (Binary Coded Octal 16) format, but it is not...

The FSX SDK document on "token variables" states:

TRANSPONDER_CODE Binary coded octal Specifies octal transponder code (0000–7777).

But, that is -well- simply incorrect! If you treat it as though it is a BCD return by applying the "Horner scheme" you will without fail get a wrong answer! :eek:
 
The returns for both the ADF and the transponder, despite the comment in the SDK that the transponder return is in octal, are actually in hex so that "octal" may have been a reference to the real-world.

im not 100% sure if im following you here, am i right in thinking that if what you say is true that the value 16 being returned by the code: 0010 is split 6-ADF and the 10-transponder?

if so how the hell do i got about splitting the 2?
 
im not 100% sure if im following you here, am i right in thinking that if what you say is true that the value 16 being returned by the code: 0010 is split 6-ADF and the 10-transponder?

if so how the hell do i got about splitting the 2?

No... You are getting a return of 00 10...

Hex is "backwards" so the return (after translation) is 16 00

I've provided two methods for the "translation." Pick one.
 
i have tried to find a way to modify your solutions to work with C# to no luck, are you able to rewrite it in C#?
 
Something like this should convert the XPndr value in an int var(xpndr) into a string(xpndrS):

string xpndrS = xpndr.ToString("x4");
 
my code so far:

Code:
unchecked
            {
                short DResult = 0;

                result = fsuipc.FSUIPC_Read(0x0354, 2, ref token, ref dwResult);
                result = fsuipc.FSUIPC_Process(ref dwResult);
                result = fsuipc.FSUIPC_Get(ref token, ref DResult);
                int getxpndr = DResult;
               
                pilid.Text = Convert.ToString(getxpndr);
                

                //if (xpndr == "7700")
                //{
                //}
            }
 
Something like this should convert the XPndr value in an int var(xpndr) into a string(xpndrS):

string xpndrS = xpndr.ToString("x4");

Well, that's certainly a nice, short function... ;)

Thanks, Tim. I was getting so deep the water was above my nose... :rotfl:
 
It just prints it as a 4 digit hex string (I hope I got the format correct, I didn't actually try that out in real code :-> ). The same sort of thing should have worked in regular C++ (something like

sprintf (str, "%04x", xpndr);

). That's the easiest way to convert a BCD/BCO value to a string, converting it to a normal int is a little more work though:

(((xpndr & 0xf000) >> 12) * 1000) +
(((xpndr & 0x0f00) >> 8) * 100) +
(((xpndr & 0x00f0) >> 4) * 10) +
(xpndr & 0x000f)

That should work in C++ or C# :->
 
Last edited:
). That's the easiest way to convert a BCD/BCO value to a string, converting it to a normal int is a little more work though:

(((xpndr & 0xf000) >> 12) * 1000) +
(((xpndr & 0x0f00) >> 8) * 100) +
(((xpndr & 0x00f0) >> 4) * 10) +
(xpndr & 0x000f)

That should work in C++ or C# :->

Well, that's nearly the same as what I posted earlier:

char xpdrS[10];
wsprintf(xpdrS, "%d%d%d%d",
(xpdr >>12) & 0x000f,
(xpdr >>8) & 0x000f,
(xpdr >>4) & 0x000f,
xpdr & 0x000f);

int xpndrI = atoi(xpdrS) ;
 
Back
Top