Jump to content
The simFlight Network Forums

Using FSUIPC from within a gauge


Recommended Posts

I tried to use FSUIPC from within a gauge as described in the SDK.

The gauge I created works fine but most times when I change from an aircraft with this gauge installed to another aircraft (without this gauge) FS2K2 crashes.

This seems to be related to FSUIPC because if take out from the gauge code the parts that have to do with FSUIPC the problem does not exist.

I am not experienced in C so it is very likely that I may have overlooked/misunderstood something. The part of the gauge code that interfaces FSUIPC follows (sorry I cannot make the identation show correctly). If you have any ideas pls let me know.

Thanks,

Michael

BYTE FsuipcMem;

BOOL FsuipcOK = FALSE;

BYTE OnState = 1; // 0=off, 1=active, 2=no spd hld, 3=Fsuipc error

SHORT FsuipcLev;

....................

/////////////////////////////////////////////////////////////////////////////

// Gauge update callback function

/////////////////////////////////////////////////////////////////////////////

void FSAPI syncthrottle_update (PGAUGEHDR pgauge, int service_id, UINT32 extra_data)

{

DWORD dwResult;

switch(service_id)

{

case PANEL_SERVICE_PRE_UPDATE:

{

.............

if (FsuipcOK)

//FSUIPC is already connected

{

if ( !FSUIPC_Read(0x332E, 2, &FsuipcLev, &dwResult) || !FSUIPC_Process(&dwResult) )

{

OnState=3;

}

else

{

OnState=1;

}

}

else

// FSUIPC is not connected yet: connect now, indication will be updated in next cycle

{

FsuipcOK=FSUIPC_Open2(SIM_ANY, &dwResult, &FsuipcMem, 64);

FsuipcLev=-16193;

}

........

break;

}

case PANEL_SERVICE_PRE_KILL:

{

FSUIPC_Close();

FsuipcOK = FALSE;

}

break;

}

}

Link to comment
Share on other sites

I tried to use FSUIPC from within a gauge as described in the SDK.

The gauge I created works fine but most times when I change from an aircraft with this gauge installed to another aircraft (without this gauge) FS2K2 crashes.

This seems to be related to FSUIPC because if take out from the gauge code the parts that have to do with FSUIPC the problem does not exist.

I am not experienced in C so it is very likely that I may have overlooked/misunderstood something. The part of the gauge code that interfaces FSUIPC follows (sorry I cannot make the identation show correctly). If you have any ideas pls let me know.

Thanks,

Michael

BYTE FsuipcMem;

BOOL FsuipcOK = FALSE;

BYTE OnState = 1; // 0=off, 1=active, 2=no spd hld, 3=Fsuipc error

SHORT FsuipcLev;

....................

/////////////////////////////////////////////////////////////////////////////

// Gauge update callback function

/////////////////////////////////////////////////////////////////////////////

void FSAPI syncthrottle_update (PGAUGEHDR pgauge, int service_id, UINT32 extra_data)

{

DWORD dwResult;

switch(service_id)

{

case PANEL_SERVICE_PRE_UPDATE:

{

.............

if (FsuipcOK)

//FSUIPC is already connected

{

if ( !FSUIPC_Read(0x332E, 2, &FsuipcLev, &dwResult) || !FSUIPC_Process(&dwResult) )

{

OnState=3;

}

else

{

OnState=1;

}

}

else

// FSUIPC is not connected yet: connect now, indication will be updated in next cycle

{

FsuipcOK=FSUIPC_Open2(SIM_ANY, &dwResult, &FsuipcMem, 64);

FsuipcLev=-16193;

}

........

break;

}

case PANEL_SERVICE_PRE_KILL:

{

FSUIPC_Close();

FsuipcOK = FALSE;

}

break;

}

}

Link to comment
Share on other sites

Look at this:

BYTE FsuipcMem;

and this:

FsuipcOK=FSUIPC_Open2(SIM_ANY, &dwResult, &FsuipcMem, 64);

You have declared FsuipcMem as a single byte (8 bits only!), yet told FSUIPC in the Open2 call that there are 64 bytes there! You will be getting parts of the program overwritten!

Your FsuipcMem should be decalred thus:

BYTE FsuipcMem[64];

if it is to be 64 bytes long. The C compiler couldn't possibly guess that you want 64 bytes. You have to tell it!

Pete

Link to comment
Share on other sites

Look at this:

BYTE FsuipcMem;

and this:

FsuipcOK=FSUIPC_Open2(SIM_ANY, &dwResult, &FsuipcMem, 64);

You have declared FsuipcMem as a single byte (8 bits only!), yet told FSUIPC in the Open2 call that there are 64 bytes there! You will be getting parts of the program overwritten!

Your FsuipcMem should be decalred thus:

BYTE FsuipcMem[64];

if it is to be 64 bytes long. The C compiler couldn't possibly guess that you want 64 bytes. You have to tell it!

Pete

Link to comment
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
×
×
  • 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.