Sign in to follow this  
Guest Fabio Miguez

Running programs outside flight simulator

Recommended Posts

Hi everyone.Im building a very complex calculation and I want to have some of the work done outside of the drawing routine (ie by a seperate exe program) and then share the data by using the extern key word. Ive done a quick search through the windows MFC and I don't know of a function to execute to run another program from inside a gauge. Any ideas?ThanksJon

Share this post


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

CreateProcess() and stuff? This is for running external exes. Or CreateThread() for a seperate thread doing the calculations. BTW the "extern" keyword doesn't give you excess to external data of a gauge/exe/dll. One way to make a communication is to use memory mapping with CreateFileMapping()/MapViewOfFile(), or similar. It might be possible to redirect In/Output with the call to CreateProcess().Arne Bartels

Share this post


Link to post
Share on other sites

Thanks a lot Arne. You seem to always know the answers to my questions. CreateProcess() looks like just what Im looking for. I may try dat files for communication first as that may be simpler but then I have to worry about when something is writing to the file. BTW, that second gauge worked, as it turns out the problem was in my drawing routine; I forgot to change a variable in a loop and the loop ended up being infinite as a result. ThanksJon

Share this post


Link to post
Share on other sites

Hey Jon.Great to know the second GDI+ gauge worked!About this gauge you are building now, can you give us any more info on the complex calculation, or is it still under wraps? ;-).

Share this post


Link to post
Share on other sites

Well the complex calculation is really the FMC. Im going to try my hand at making a realistic one for my 737 panel. Also, Im going to try handling all the systems in that complex calculation so that all the gauges will do is display information from that external program. The only calculation that will be done while drawing is computing points for drawing lines and curves. I don't think I am doing anything revolutionary here but I feel it is necessary to obtain resonable frame rates for a fairly complex panel. Currently I am learning about processes and threads. There is a pretty steep learning curve which I am handling ok but if anyone knows of a book on the subject please tell me! Also, how is your Cirrus going?

Share this post


Link to post
Share on other sites

Hey Jon.Great! If you need any help with the actual programming, let me know. I've been studying the subject a bit since the moving map in the Cirrus is pretty much the most complex one to date. Just have a look at www.avidyne.com and click on the Entegra link, and you will see what I mean.The project is coming along great. We have an amazing group of beta testers (a very big one!), and they are doing a fantastic job. We are packing up what we have so far for our presentations at Oshkosh (Cirrus invited us to demo it in their booth the entire week!!!), so I have been living on coffee by itself lately ;-).I am also starting to learn about processes and threads, but I think your FMS might not benefit all that much from being an external .EXE. This is the way Dreamfleet made theirs (if I remember correctly, Hans Hartmann was the man behind it, and he did a very good job), but PMDG opted for a in-gauge FMS, and from what I hear it works fine.I have done some pretty heavy calculations in-gauge, and my experience so far is that the ammount of them, when made in the background, (say functions called before the drawing function, but in the same gauge) does not impact frame rates. It seems machines nowadays are so fast that as long as you are not calculating the mass of dark matter in the Universe, then you are ok. And even then you might be able to get away with it ;-).What really slows the gauge down is the drawing part. I am using GDI+, and from tests it appears to be faster than the GDI. I had my doubts in the beggining, but now that is pretty much a fact. The only drawback is GDI+ is not hardware-accelerated by its nature, so if you draw way too much (and update way too many times per second), you start to se a drop in frames. But in the case of an FMS you should be absolutelly fine, since all you are doing is updating the guauge display say twice a second, to behave like a real unit. When the update rates are as low as this, then you can draw an immense ammount of vectors and text without any virtual affect on frame rates.I hope this was more helpful than boring ;-).

Share this post


Link to post
Share on other sites

Glad to hear your project is coming along. That is an enourmous task you are taking on and I wish you good luck. I know that drawing is what slows the gauge down but I have other reasons for wanting to do stuff outside of the gauge. First, I want to be able to control when and how often my code gets executed. One of the problems I have now is that sometimes my code isn't executed while the gauge isn't on screen. It seems I am at the mercy of the sim and things would be a lot easier if I could have something running constantly. Second, Im looking to setup things like instructor stations and a copilot station so that 2 may fly the plane at the same time like it is done in real life. The things I am trying to do will become way to complicated to accomplish in gauge so I think if I can master the communication process with an FMC, then I will be able to do the cooler features with ease. Third, I want to make an FMC that can talk on network, kind of like ACARSAnd YES i could use a lot of help! I basically need to find the most effiecent way for two programs to communicate.

Share this post


Link to post
Share on other sites

If you run your code in PANEL_SERVICE_PRE_UPDATE it will be called 18 times per second regardless if drawn or not, framerate independent. If you want a way to let programs communicate on one machine, try memory mapping or suchlike. For network exchange of course use sockets.Arne Bartels

Share this post


Link to post
Share on other sites

>This is the way Dreamfleet made theirs (if I>remember correctly, Hans Hartmann was the man behind it, and>he did a very good job), but PMDG opted for a in-gauge FMS,>and from what I hear it works fine.Nope. Hans Hartmann did not do the FMS, musta been Nick Jacobs or Chris Koegler.Regards,Etienne

Share this post


Link to post
Share on other sites

Hey Etti,Ah, I am wrong once again! (it seems I am wrong about 5 times for each time I am right. Damn the bad luck! :-)). Thanks for the correction Etienne, and welcome back ;-).

Share this post


Link to post
Share on other sites

>Hi everyone.>Im building a very complex calculation and I want to have some>of the work done outside of the drawing routine (ie by a>seperate exe program) and then share the data by using the>extern key word. Ive done a quick search through the windows>MFC and I don't know of a function to execute to run another>program from inside a gauge. Any ideas?>Thanks>Jon Hello Jon,you might like to look at FSUIPC which gives read and write access to FS internal tokens. As an example look at Herve Sors application AFSD to display the flight performance in real time.http://perso.wanadoo.fr/hsors/FS_Soft/afsd.html Ian

Share this post


Link to post
Share on other sites

You can do it by using CreateProcess and comunicate between the gauge and the main program by using sockets. I have done that in FSacars a gauge to interact with user and a main program to do the job and works quite well. The advantage is that sockets are nicer and more standard than pipes or mailslots. I created a server in the gauge and the trasmissions are non blocking I know that should be done in multithread but... it works.Jos

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