Jump to content
The simFlight Network Forums


Recommended Posts


I just started to play around a bit with Mark Burton's FSUIPC API for java. compiling and running the test script runs fine, i get the good values. However when I put the thing in a loop it begins acting strangely. The first reading is ok but when he reads the loop for a second time all values are zero :-\.

import com.flightsim.fsuipc.*;

public class Test
public static void main(String s[]) 
	   int i = 1 ;
       while(i == 1)
        System.out.println("Running tests");
	int ret = fsuipc_wrapper.Open(fsuipc_wrapper.SIM_ANY);
	System.out.println("ret =" + ret);
	if(ret == 0 )
		System.out.println("Flight sim not found");


	static void TestADF()
	System.out.println("Testing ADF");
	FSADF adf = new FSADF();
	System.out.println("freq " + adf.Freq());
	System.out.println("freq as string " + adf.FreqAsString());
	System.out.println("ID " +adf.Identity());
	System.out.println("Name " + adf.Name());

	static void TestNav1()
	FSNav1 nav = new FSNav1();
	System.out.println("freq " + nav.Freq());
	System.out.println("freq as string " + nav.FreqAsString());
	System.out.println("ID " +nav.Identity());
	System.out.println("Name " + nav.Name());
	System.out.println("loc " +nav.LocaliserNeedle());
	System.out.println("glide " + nav.GlideSlope());

	static void TestAircraft()
	FSAircraft air = new FSAircraft();
	System.out.println("latitude " + air.Latitude());
	System.out.println("longtitude " + air.Longitude());
	System.out.println("VOR1 lat " + air.VOR1LocLatitude());
	System.out.println("VOR1 long " + air.VOR1LocLongitude());

	int hi = air.Heading();
	System.out.println("heading " + hi);
	double h = 360.0*hi/(65536.0*65536.0);
	System.out.println("h " + h);

	int mi = air.Magnetic();
	System.out.println("magnetic " + mi);
	double m = 360.0*mi/(65536.0*65536.0);
	System.out.println("m " + m);

	double p = air.Pitch();
	System.out.println("pitch " + p);

	double b = air.Bank();
	System.out.println("bank " + b);

	System.out.println("IAS " + air.IAS());
	System.out.println("VS " + air.VerticalSpeed());
	System.out.println("alt " + air.Altitude());
	System.out.println("locerr " + air.LocaliserError());
	System.out.println("loc " + air.Localiser());
	System.out.println("engine " + air.NumberOfEngines());
	System.out.println("engine type " +air.EngineType());


	static void TestEngine1()
	FSEngine1 eng = new FSEngine1();

	System.out.println("comb " + eng.Combustion());

	static void TestEngine2()
	FSEngine2 eng = new FSEngine2();

	System.out.println("comb " + eng.Combustion());

	static void TestGear()
	FSGear gear = new FSGear();
	System.out.println("nose" + gear.NoseGearState());
	System.out.println("left " + gear.LeftGearState());
	System.out.println("right " + gear.RightGearState());


	static void TestFlightSim()
	FSFlightSim sim = new FSFlightSim();
	System.out.println("name " + sim.StartSituationName());


Does anyone what am I'm doing wrong, or has an idea to approach this in a differen way?

PS: I know this is a real dumb script but it's just for me to get acquainted with the API

Link to comment
Share on other sites

The first reading is ok but when he reads the loop for a second time all values are zero :-\.

You set i = 1 and when it is 1 you create a connection to FSUIPC.

So, when do you change i? I don't see a place where it is changed. You keep trying to create a new connection to FSUIPC every loop. The second and subsequent ones will be, er, problematic.

You should open your connection to FSUIPC just once, at the start of the program, and close it at the end, not continually reopen it all the time, nor opening and closing it (not that you appear to have thought of closing it).



Link to comment
Share on other sites

the i incerement was just a copy-paste error :P. But the problem was indeed that i tried to reopen the connection with fsuipc in the loop. I opened the connection outside the loop and now i get nice values. Thanks a lot.

Btw, mister Dowson I think you are doing a really great job with the fsuipc. Without you're developement the Flight Sim community wouldn't be as advanced as it is today. Thanks for that!

Link to comment
Share on other sites

I've got another question concerning this topic. What is the best way to enhance the java SDK with new methods? Can i just change for example FSAircraft.java -> compile it -> update the class file in FSUIPC.jar ?

I hope someone else picks this up. I'm afraid I know nothing at all about Java.


Link to comment
Share on other sites

  • 2 years later...

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.