# Multi-dataref query test program for the Python client library #------------------------------------------------------------------------------ if __name__ == "__main__": import sys import time from xplra import XPlane, ProtocolException xplane = XPlane() dontregister = "dontregister" in sys.argv try: print "Connecting to X-Plane..." xplane.connect() print "Connected to X-Plane." print getter = xplane.createMultiGetter() tailnumID = getter.addByteArray("sim/aircraft/view/acf_tailnum", 40) daysID = getter.addInt("sim/time/local_date_days") zuluSecID = getter.addFloat("sim/time/zulu_time_sec") pausedID = getter.addInt("sim/time/paused") latitudeID = getter.addDouble("sim/flightmodel/position/latitude") longitudeID = getter.addDouble("sim/flightmodel/position/longitude") replayID = getter.addInt("sim/operation/prefs/replay_mode") overspeedID = getter.addInt("sim/flightmodel/failures/over_vne") stalledID = getter.addInt("sim/flightmodel/failures/stallwarning") onTheGroundID = getter.addInt("sim/flightmodel/failures/onground_any") emptyWeightID = getter.addFloat("sim/aircraft/weight/acf_m_empty") payloadWeightID = getter.addFloat("sim/flightmodel/weight/m_fixed") grossWeightID = getter.addFloat("sim/flightmodel/weight/m_total") headingID = getter.addFloat("sim/flightmodel/position/psi") pitchID = getter.addFloat("sim/flightmodel/position/theta") bankID = getter.addFloat("sim/flightmodel/position/phi") iasID = getter.addFloat("sim/flightmodel/position/indicated_airspeed2") machID = getter.addFloat("sim/flightmodel/misc/machno") groundSpeedID = getter.addFloat("sim/flightmodel/position/groundspeed") vsID = getter.addFloat("sim/flightmodel/position/vh_ind_fpm2") radioAltitudeID = getter.addFloat("sim/flightmodel/position/y_agl") altitudeID = getter.addFloat("sim/flightmodel/position/elevation") gLoadID = getter.addFloat("sim/flightmodel/forces/g_nrml") flapsControlID = getter.addFloat("sim/flightmodel/controls/flaprqst") flapsLeftID = getter.addFloat("sim/flightmodel/controls/flaprat") flapsRightID = getter.addFloat("sim/flightmodel/controls/flap2rat") navLightsID = getter.addInt("sim/cockpit/electrical/nav_lights_on") beaconLightsID = getter.addInt("sim/cockpit/electrical/beacon_lights_on") strobeLightsID = getter.addInt("sim/cockpit/electrical/strobe_lights_on") landingLightsID = getter.addInt("sim/cockpit/electrical/landing_lights_on") pitotID = getter.addInt("sim/cockpit/switches/pitot_heat_on") parkingID = getter.addFloat("sim/flightmodel/controls/parkbrake") gearControlID = getter.addInt("sim/cockpit2/controls/gear_handle_down") noseGearID = getter.addFloatArray("sim/flightmodel2/gear/deploy_ratio", 1) altimeterID = getter.addFloat("sim/cockpit/misc/barometer_setting") qnhID = getter.addFloat("sim/flightmodel/misc/Qstatic") navTypesID = getter.addIntArray("sim/cockpit/radios/nav_type", 6) busVoltsID = getter.addFloatArray("sim/cockpit2/electrical/bus_volts", 4) if dontregister: getter.finalize() else: print "Registering getter..." getter.register() print "Registered getter." print while True: getter.execute() print "tail number: '%s', days: %d, zuluSec: %f" % \ (getter.getString(tailnumID), getter[daysID], getter[zuluSecID]) print "paused=%d, replay=%d, overspeed=%d, stalled=%d, onTheGround=%d" % \ (getter[pausedID], getter[replayID], getter[overspeedID], getter[stalledID], getter[onTheGroundID]) print "emptyWeight=%f, payloadWeight=%f, grossWeight=%f" % \ (getter[emptyWeightID], getter[payloadWeightID], getter[grossWeightID]) print "latitude=%f, longitude=%f, radioAltitude=%f, altitude=%f, gLoad=%f" % \ (getter[latitudeID], getter[longitudeID], getter[radioAltitudeID]/.3048, getter[altitudeID]/.3048, getter[gLoadID]) print "heading=%f, pitch=%f, bank=%f, ias=%f, mach=%f, groundSpeed=%f, vs=%f" % \ (getter[headingID], getter[pitchID], getter[bankID], getter[iasID], getter[machID], getter[groundSpeedID], getter[vsID]); print "flapsControl=%f, flapsLeft=%f, flapsRight=%f" % \ (getter[flapsControlID], getter[flapsLeftID], getter[flapsRightID]); print "Lights: NAV: %d, beacon: %d, strobe: %d, landing: %d" % \ (getter[navLightsID], getter[beaconLightsID], getter[strobeLightsID], getter[landingLightsID]); print "pitot: %d, parking: %f, gearControl: %d, noseGear: %f" % \ (getter[pitotID], getter[parkingID], getter[gearControlID], getter[noseGearID][0]); print "altimeter: %f, qnh: %f" % \ (getter[altimeterID], getter[qnhID]); print "NAV types:", getter[navTypesID] print "bus voltages:", getter[busVoltsID] print time.sleep(1.0) except Exception as e: print ">>>>>>>>>>>>>>>>>>>>>> Exception caught:", str(e) finally: xplane.disconnect()