Jump to content
The simFlight Network Forums

Recommended Posts

Posted

I want to modify the nav1 stby freq.so I writed the value to 0X311E,but after execute the program,I found the nav1 stby freq didn't changed at all.

void __fastcall TForm1::Timer1Timer(TObject *Sender)

{

DWORD dwResult;

char String[32], chTime[3];

BOOL fTimeOk = TRUE;

unsigned long pdwResult;

if (!dwClosed) {

if (!FSUIPC_Read(0x238, 3, chTime, &dwResult) ||

!FSUIPC_Process(&dwResult))

fTimeOk = FALSE;

char t[32]="1234";

FSUIPC_Write(0x311e, 2, &t, &pdwResult); //modify nav1 freq

// Now display all the knowledge we've accrued:

if (fTimeOk) {

Label2->Caption = "OK";

sprintf(String, "%02d:%02d:%02d", chTime[0], chTime[1], chTime[2]);

Label8->Caption = String;

}

else {

Label2->Caption = "Failed";

}

}

}

Posted
I want to modify the nav1 stby freq.so I writed the value to 0X311E,but after execute the program,I found the nav1 stby freq didn't changed at all.

You have something wrong with your program, then, as that offset is used a lot for writing from drivers for hardware like the PFC Avionics Stacks (I should know, I use them). Have you checked using FSInterrogate? That's why it is provided, so you can do checks outside your own code.

char t[32]="1234";

FSUIPC_Write(0x311e, 2, &t, &pdwResult); //modify nav1 freq

Well, I can see why now. You have two errors there.

1. The value to be written is a 16-bit number, encoding the frequency, minus the leading '1', in BCD (binary coded decimal). A clear example is shown in the documentation. It says "a frequency of 113.45 is represented by 0x1345".

You are trying to write 0x3231 (the hex value of the 1st 16 bits (i.e 2 bytes) of your inapplicable 4-byte character string). That represents the illegal frequency 132.31. It would produce an erroneous display altogether in older versions of FS, and would be rejected altogether in FSX

2. It appears that you may have been trying to write a frequency of 112.34, which is also not a valid frequency for FS. The last digit must be 0, 2, 5, or 7 (representing 00, 25, 50 and 75 respectively).

Regards

Pete

Posted
thanks peter,I know the reason,but I still don't know how to translate the noamal Frequency into hex,For EXAMPLE:115.65=0x ?

Just the same digits, without the leading 1, which is assumed. I thought you'd have noticed that. So:

115.65 --> 0x1565

and the previous examples:

113.45 --> 0x1345 (the one in the documentation)

and your erroneous attempts:

132.31 --> 0x3231 (bad), or

112.34 --> 0x1234 (also bad)

These last two are "bad" because of their invalid last digits, as I explained (and the first is out of range for NAV, of course).

This form of representation has been used in Fs since at least FS4. probably before. it is called "Binary-Coded Decimal" (BCD), because each decimal digit is represented separately in binary -- using 4 bits each (hence 16 bits for 4 digits). The binary values are represented more conveniently in hexadecimal, which is simply a way of grouping binary into 4 bits lumps. Thus

0x1345 = 0001 0011 0100 0101 in binary. Each group of 4 bits is, in BCD, interpreted in decimal, thus 1345.

Pete

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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.