source: xplra/test/basictest.py@ 31:a37c4ec54e84

Last change on this file since 31:a37c4ec54e84 was 31:a37c4ec54e84, checked in by István Váradi <ivaradi@…>, 11 years ago

Reading of single values works with the Python client

File size: 2.4 KB
Line 
1# Basic test program for the Python client library
2
3#------------------------------------------------------------------------------
4
5if __name__ == "__main__":
6 from xplra import XPlane, ProtocolException
7
8 xplane = XPlane()
9
10 try:
11 print "Connecting to X-Plane..."
12 xplane.connect()
13 print "Connected to X-Plane."
14 print
15
16 print "Querying the number of the engines..."
17 numEngines = xplane.getInt("sim/aircraft/engine/acf_num_engines")
18 print "The number of engines:", numEngines
19 print
20
21 try:
22 print "Querying an invalid dataref..."
23 xplane.getInt("sim/aircraft/engine/num_engines")
24 print
25 print ">>>>>>>>>>>> Succeeded!!!!!!!!!!!!!!!!!!!!!!"
26 except ProtocolException as e:
27 print "Exception caugth:", str(e)
28 print
29
30 print "Querying the spool time of a jet engine..."
31 spoolTime = xplane.getFloat("sim/aircraft/engine/acf_spooltime_jet")
32 print "The spool time:", spoolTime
33 print
34
35 print "Querying the spool time of a propeller..."
36 spoolTime = xplane.getFloat("sim/aircraft/engine/acf_spooltime_prop")
37 print "The spool time:", spoolTime
38 print
39
40 print "Querying the coordinates..."
41 latitude = xplane.getDouble("sim/flightmodel/position/latitude")
42 longitude = xplane.getDouble("sim/flightmodel/position/longitude")
43 print "The coordinates: " + `latitude` + ", " + `longitude`
44 print
45
46 print "Querying the aircraft's description..."
47 result = xplane.getByteArray("sim/aircraft/view/acf_descrip")
48 print "The description:", result.tolist()
49 print
50
51 print "Querying the aircraft's description as a string, with an offset of 3..."
52 result2 = xplane.getString("sim/aircraft/view/acf_descrip", offset = 3);
53 print "Got: '" + result2 + "'"
54 print
55
56 print "Querying the aircraft's engine types..."
57 result3 = xplane.getIntArray("sim/aircraft/prop/acf_en_type")
58 print "Got:", result3.tolist()
59 print
60
61 print "Querying the aircraft's propeller directions..."
62 result5 = xplane.getFloatArray("sim/aircraft/prop/acf_prop_dir")
63 print "Got:", result5.tolist()
64 print
65
66 except Exception as e:
67 print ">>>>>>>>>>>>>>>>>>>>>> Exception caught:", str(e)
68 finally:
69 xplane.disconnect()
Note: See TracBrowser for help on using the repository browser.