Archived

This topic is now archived and is closed to further replies.

Guest coal

execute_calculator_code question

Recommended Posts

Hello,After reading this: http://forums.flightsim.com/fswiki/index.p...les_in_C_Gauges, I decide to make some tests, and saw the easyness to access some FS variables.But in the mentioned link I read:"If the XML variable is a string, here is an example: PCSTRINGZ VorIcaoCode; // first declare the string C variableexecute_calculator_code("(C:fs9gps:WaypointICAO,string)",NULL,NULL,&VorIcaoCode);Take note that the string example also shows how we can easily fetch stuff from the GPS system using this technique!"Well, I can write strings using this method using sentences like (using GDI, not GDI+):PCSTRINGZ title;execute_calculator_code("(A:TITLE, string)", NULL, NULL, &title);TextOut(hdc, 10*dx, 40*dy, (LPCSTR)title, strlen(title));but if I try:PCSTRINGZ flp_title;execute_calculator_code("(C:fs9gps:FlightPlanTitle, string)", NULL, NULL, &flp_title);TextOut(hdc, 10*dx, 80*dy, (LPCSTR)flp_title, strlen(flp_title));or,SINT32 na_number;execute_calculator_code("(C:fs9gps:NearestAirportItemsNumber, number)", NULL, &na_number, NULL);sprintf(num_str_HSI, "%d", na_number);TextOut(hdc, 10*dx, 100*dy, num_str_HSI, strlen(num_str_HSI));The only thing I get is 0. or 0. Same thing happen if I use a GPS parameter:PCSTRINGZ gps_next;execute_calculator_code("(A:GPS WP_NEXT ID, string)", NULL, NULL, &gps_next);TextOut(hdc, 10*dx, 100*dy, (LPCSTR)gps_next, strlen(gps_next));Is there anything to do before access GPS variables using C:fs9gps:? Thanks for your help.Daniel

Share this post


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

Daniel, C:fs9gps:NearestAirportItemsNumber can be retrieved once ---Current AC position is entered(A:GPS POSITION LAT, Radians) (>@c:NearestAirportCurrentLatitude, Radians) (A:GPS POSITION LON, Radians) (>@c:NearestAirportCurrentLongitude, Radians)Max distance to search is inputted100 (>@c:NearestAirportMaximumDistance, NMiles)Max number of airports to find250 (>@c:NearestAirportMaximumItems)Now you can get (@c:NearestAirportItemsNumber), from that you can find the index then data about that airport(>@c:NearestAirportCurrentLine) (@c:NearestAirportCurrentICAO) (>@c:WaypointAirportICAO)INFO on COMM freq.1 (>@c:WaypointAirportCurrentFrequency) or diff number for diff comm (@c:WaypointAirportFrequencyValue,Mhz)Roman

Share this post


Link to post
Share on other sites

Thanks Roman. I understand what you say, but why doesn't work something easier like:PCSTRINGZ flp_title;execute_calculator_code("(C:fs9gps:FlightPlanTitle, string)", NULL, NULL, &flp_title);TextOut(hdc, 10*dx, 80*dy, (LPCSTR)flp_title, strlen(flp_title));Daniel

Share this post


Link to post
Share on other sites

Hi,Do not use units when retrieving gps data with this function:execute_calculator_code("(C:fs9gps:FlightPlanTitle)", NULL, NULL, &flp_title);Gps.dll will directly return the default unit (string in this case).Tom

Share this post


Link to post
Share on other sites

Thanks Tom, for this reply and for your all contribution to FS forums you do.Unfortunately I cannot make that work.I put all that code in PANEL_SERVICE_PRE_DRAW.Is that the only thing to do?Nor can't retrieve any other gps data, numeric or string. Even using variables as in:PCSTRINGZ gps_next;execute_calculator_code("(A:GPS WP_NEXT ID, string)", NULL, NULL, &gps_next);Daniel

Share this post


Link to post
Share on other sites

Daniel, did you check whether gps.dll is present in main FS folder?I cannot think of other causes when you say other variables return correct values (?)Tom

Share this post


Link to post
Share on other sites

I'm testing with FS9 so gps.dll is in the modules folder. Anyway I copy it to main FS9 folder and nothing change.As I'm sure that the method works for other people I wonder what could be wrong.Thanks again.Daniel

Share this post


Link to post
Share on other sites

You should not be doing data lookup in the PRE_DRAW service.

Share this post


Link to post
Share on other sites

Here is a working example. Note that the units ARE specified after the A:variable:case PANEL_SERVICE_PRE_UPDATE: execute_calculator_code("(A:ATC ID,string)",NULL,NULL,&n_number);break;Note also that the lookup is done in the PRE_UPDATE case.When trying to request data from the fs9gps.dll you need to first tell it where you are, 'cause it doesn't know!

Share this post


Link to post
Share on other sites

Bill, you're right there! the GPS.dll can run separate threads i believe.. If you try to recieve something that the GPS itself created IT MIGHT NOT WORK since the GPS disposed of the inputs already and created something else etc...Learned that one the hard way.. Do it yourself or not at all :-) RomanProud "TEAM AVSIM" RTW race member.

Share this post


Link to post
Share on other sites

Thanks everybody for helping. I've been out and continued trying when back.I was sick trying to print a string, using for testing:PCSTRINGZ gps_next;execute_calculator_code("(A:GPS WP_NEXT ID, string)", NULL, NULL, &gps_next);TextOut(hdc, 10*dx, 100*dy, (LPCSTR)gps_next, strlen(gps_next));because in FS SDK they wrote GPS WP_NEXT ID and the right name of the variable is GPS WP NEXT ID (without the low dash).The above sentences work in PANEL_SERVICE_PRE_DRAW writing nothing in PANEL_SERVICE_PRE_UPDATE.Now the problem I have is that I cannot access GPS variables (strings or numbers) using execute_calculator_code, no mater if I try in PANEL_SERVICE_PRE_UPDATE or PANEL_SERVICE_PRE_DRAW.Could anyone of you give a complete working example for a GPS variable, let's say FlightPlanDepartureAirportIdent for example?This is what I tried in PANEL_SERVICE_PRE_DRAW (without success):PCSTRINGZ apt_ident;execute_calculator_code("(C:fs9gps:FlightPlanDepartureAirportIdent, string)", NULL, NULL, &apt_ident);TextOut(hdc, 10*dx, 100*dy, (LPCSTR)apt_ident, strlen(apt_ident));What should I lookup in the PRE_UPDATE case, if anything?Daniel

Share this post


Link to post
Share on other sites