Sign in to follow this  
mfrantz

Using FSUIPC from within a gauge

Recommended Posts

I tried to use FSUIPC from within a gauge as described in the FSUIPC 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; } }

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

I use FSUIPC_Open() with gauges not .._Open2(). Works fine.Arne Bartels

Share this post


Link to post
Share on other sites

Thanks for the reply Arne.According to the FSUIPC SDK the use of FSUIPC_Open() is not recommended - see extract below.Anyway, there was an obvious error in my code that probably caused parts of the programme to be overwritten. FsuipcMem is declared as a single byte while in FSUIPC_Open2 the size is 64 bytes - the declaration should have been BYTE FsuipcMem[64].MichaelFrom the FSUIPC SDK:IMPORTANT NOTE FOR FS GAUGE AND MODULE WRITERS==============================================If you are wanting to access FSUIPC's facilities from INSIDE FS, rather than from an external application, please PLEASE note that using the external users library is most definitely NOT recommended. It is VERY inefficient. You are inside the FS process, so why use complex inter-process communications? (IPC == Inter-Process Communication!).Also, if you do use this slow method, you may get failures on Open which will recover, eventually, on retries. This is because, ollowing Adam Szofran's original method, the "unique" ID string, used to identify the mapped memory, is generated using the Process ID. This ID is unique for all separate Processes, but obviously it is the same for ALL gauges and modules running inside FS.FSUIPC deliberately provides an entry for Gauges and Modules to use. It is very efficient, it uses a simple message with no memory mapping. YOU, the user, have to provide the memory for the data, but there are simple rules for calculating how much. The code is almost identical to using the external library -- only the Open call is changed to provide the memory pointer and size!Please see the "C library for FS Internal Access" ZIP.

Share this post


Link to post
Share on other sites

I use FSUIPC_Open2 with no problems. Did making fsuipcMem an array fix the problem?Matt

Share this post


Link to post
Share on other sites

Yes it did.>I use FSUIPC_Open2 with no problems. Did making fsuipcMem an>array fix the problem?>>Matt

Share this post


Link to post
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
Sign in to follow this