# This Python file uses the following encoding: utf-8 from time import sleep from math import degrees import sys import pyuipc P3Dv4 = 12 XPL11 = 0 VERSIONS = [P3Dv4, XPL11] def open_file(): try: fh = open("bar.html", "w") except: print("Cannot open file for writing!") else: return fh def write_data(file, hdg, alt, fpm, gs, gf, aoa): data = "" data += "" data += "" data += "" data += "" data += "" data += "
" data += "
" + str(hdg) + "
" data += "
" + str(alt) + "
" data += "
" + str(fpm) + "
" data += "
" + str(gs) + "
" data += "
" + str(aoa) + "
" data += "
" + str(gf) + "
" data += "" try: file.write(data) file.close() except: print("Error writing to file!") file.close() while True: try: pyuipc.open(XPL11) while True: try: l = list() t0 = (0x0580, 'u') # heading t1 = (0x0570, 'l') # alt t2 = (0x02b4, 'd') # ground speed t3 = (0x02a0, 'h') # magvar t4 = (0x1140, 'f') # G-force t5 = (0x030c, 'd') # vspeed at touchdown t6 = (0x2ed0, 'f') # AOA l = [t0, t1, t2, t3, t4, t5, t6] res = pyuipc.read(l) hdg = res[0]*360/(65535*65535) magvar = int(res[3] * 360 / 65536) mag = hdg - magvar if mag < 0: mag = 360 + mag if mag == 0: mag = 360 mag = str(mag) if len(mag) == 1: mag = "00" + mag elif len(mag) == 2: mag = "0" + mag alt = int(res[1]*3.28084/(65536*65536)) gs = res[2]*3600/65536/1852 gf = str(res[4]) if len(gf) > 3: if gf[0] == "-": gf = gf[0:5] else: gf = gf[0:4] tdvspeed = int(res[5]*60*3.28084/256) aoa = str(degrees(res[6])) if aoa[0] == "-": aoa = aoa[0:5] else: aoa = aoa[0:4] print("Hdg: " + str(mag)) print("Alt: " + str(alt) + " ft") print("Gs: " + str(gs) + " kts") print("G-force: " + str(gf)) print("T/D VSpeed: " + str(tdvspeed)) print("AOA: " + str(aoa)) print("---") fh = open_file() write_data(fh, mag, alt, tdvspeed, gs, gf, aoa) sleep(2) except: print("Error") print(sys.exc_info()[0]) try: pyuipc.close() except: pass break except pyuipc.FSUIPCException as e: print("Exception") print(str(e.errorCode) + " " + e.errorString) sleep(10) except: print("Probably incorrect FSUIPC version or simulator is not started. Timeout 10 sec.") sleep(10)