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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

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