I'm trying to write a function to set altitude and I came across this thread. I've pretty much using vdkeybus's function, but I can't get it to work. After I write the two words, I read them back and print them out. It reads back the correct value for the upper word, but the fractional portion is zero. When I checked the log, it appears to be writing the correct value, but it reads back all zeros. Here's a section of the log file:
24703 WRITE0 0570, 4 bytes: 8F 02 00 00
24703 WRITE0 0574, 4 bytes: D3 00 00 00
24703 READ0 0570, 4 bytes: 00 00 00 00
24703 READ0 0574, 4 bytes: D3 00 00 00
Here's my function:
void setAltitude(DWORD *pdwResult, double Altitude)
{
unsigned int altLowerTemp;
int altUpperTemp;
static struct
{
unsigned lval;
int hval;
} val;
val.hval=(int)floor(Altitude);
val.lval=(unsigned)((Altitude-val.hval)*65536);
printf("decimal value = %f\n", Altitude-val.hval);
printf("alt lower wrote = %d\n", val.lval);
printf("alt upper wrote = %d\n", val.hval);
FSUIPC_Write(0x0570, 4, &val.lval, pdwResult);
FSUIPC_Write(0x0574, 4, &val.hval, pdwResult);
FSUIPC_Process(pdwResult);
FSUIPC_Read(0x0570, 4, &altLowerTemp, pdwResult);
FSUIPC_Read(0x0574, 4, &altUpperTemp, pdwResult);
FSUIPC_Process(pdwResult);
printf("alt lower read = %d\n", altLowerTemp);
printf("alt upper read = %d\n\n", altUpperTemp);
}
Am I missing something simple here? Thanks for your help.
Matt