[phpwiki]Front Page

jsimconnect


jSimConnect - SimConnect java client library


Introduction

jSimConnect is a java implementation of a simconnect client library. SimConnect is a client/server architecture that enables add-ons developpers to communicate with a running instance of Microsoft Flight Simulator X. The original SimConnect client library included with the deluxe edition of FSX supports only C/C++ and CLI compliant languages. This library is an attempt to provide the same set of functionnalities to Java language developpers. jSimConnect is distributed under the terms of the LGPL License


Architecture

jSimConnect is not a native interface to the original microsoft library, it is a complete reimplementation of the client, partially compliant the version 4 of the SimConnect protocol (corresponding to FSX, SP1 and SP2 features). It is thus totally portable on all architectures supported by JVM (version 5.0). You can use it on the same machine as FSX or another machine through TCP/IP networking.

Roadmap

The following features are actually implemented in jSimConnect :

Some others are not supported or currently in development:

Read more about simconnect internals


Download

Current version : 0.7 release date: Sunday 04 November. Requires J2SDK 5.0. (won't work with older 1.3 or 1.4.x versions)

Warning: be sure to read and understand protocol version emulation feature of the SimConnect class. The default protocol version is now 4 (as of jsimconnect 0.7), which is not compatible with pre-SP2 FSX.


History / Old versions


Example

Here is a program example using jSimConnect and a DispatchTask? thread :

	final int dataDefID = 1;
		final int requestID = 1;
		final int fourSeceventID = 1;
		// connect to simconnect
		SimConnect sc = new SimConnect("AIList", "10.1.0.6", 48447);
		// build data definition
		sc.addToDataDefinition(dataDefID, "STRUCT LATLONALT", null, SimConnectDataType?.LATLONALT);
		sc.addToDataDefinition(dataDefID, "ATC TYPE", null, SimConnectDataType?.STRING32);
		sc.addToDataDefinition(dataDefID, "ATC ID", null, SimConnectDataType?.STRING32);
		// get warned every 4 seconds when in sim mode
		sc.subscribeToSystemEvent(fourSeceventID, "4sec");
		DispatcherTask? dt = new DispatcherTask?(sc);
		// just for esthetic purposes
		dt.addOpenHandler(new OpenHandler?() {
			public void handleOpen(SimConnect sender, RecvOpen? e) {
				System.out.println("Connected to " + e.getApplicationName());
			}});
		// add an event handler to receive events every 4 seconds
		dt.addEventHandler(new EventHandler?() {
			public void handleEvent(SimConnect sender, RecvEvent? e) {
				if (e.getEventID() == fourSeceventID) {
					// request data for all aircrafts in the sim
					try {
						sender.requestDataOnSimObjectType(requestID, dataDefID, 100*1000, SimObjectType?.AIRCRAFT);
					} catch (IOException ioe) {}
				}
			}});
		// handler called when received data requested by the call to
		// requestDataOnSimObjectType
		dt.addSimObjectDataTypeHandler(new SimObjectDataTypeHandler?() {
			public void handleSimObjectType(SimConnect sender, RecvSimObjectDataByType? e) {
				// retrieve data structures from packet
				LatLonAlt? position = e.getLatLonAlt();
				String atcType = e.getDataString32();
				String atcID = e.getDataString32();
				// print to users
				System.out.println("Plane id#" + e.getObjectID() + " no " + e.getEntryNumber() + "/" + e.getOutOf());
				System.out.println("\tPosition: " + position.toString());
				System.out.println("\tType/ID: " + atcType + " " + atcID);
				// line separator
				if (e.getEntryNumber() == e.getOutOf()) System.out.println();
			}});
		// spawn receiver thread
		new Thread(dt).start();