source: xplra/test/basictest.py@ 35:9451e75788ea

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

Implemented support for multi-dataref setting

File size: 5.2 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
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 + "' (" + `len(result2)` + ")"
54 print result2=="h 8 Q400"
55 print
56
57 print "Querying the aircraft's engine types..."
58 result3 = xplane.getIntArray("sim/aircraft/prop/acf_en_type")
59 print "Got:", result3
60 print
61
62 print "Querying the aircraft's propeller directions..."
63 result5 = xplane.getFloatArray("sim/aircraft/prop/acf_prop_dir")
64 print "Got:", result5
65 print
66
67 print "Setting the number of the engines to", numEngines + 1
68 xplane.setInt("sim/aircraft/engine/acf_num_engines", numEngines + 1)
69 numEngines = xplane.getInt("sim/aircraft/engine/acf_num_engines")
70 print "The new number of engines:", numEngines
71 print
72
73 acfElevUp = xplane.getFloat("sim/aircraft/controls/acf_elev_up")
74 print "Setting the aircraft elevator up control from %f to %f..." % \
75 (acfElevUp, acfElevUp + 15.0)
76 xplane.setFloat("sim/aircraft/controls/acf_elev_up", acfElevUp + 15.0)
77 acfElevUp = xplane.getFloat("sim/aircraft/controls/acf_elev_up")
78 print "The aircraft elevator up control set to", acfElevUp
79 print
80
81 localX = xplane.getDouble("sim/flightmodel/position/local_x")
82 print "Setting the aircraft's local X-coordinate from %f to %f..." % \
83 (localX, localX + 15.0)
84 xplane.setDouble("sim/flightmodel/position/local_x", localX + 15.0)
85 localX = xplane.getDouble("sim/flightmodel/position/local_x")
86 print "The aircraft's local X-coordinate set to", localX
87 print
88
89 numBlades = xplane.getFloatArray("sim/aircraft/prop/acf_num_blades")
90 print "Setting the number of blades"
91 print " from:", numBlades
92 numBlades = [n+2.5 for n in numBlades]
93 print " to:", numBlades
94 xplane.setFloatArray("sim/aircraft/prop/acf_num_blades", numBlades)
95
96 numBlades = xplane.getFloatArray("sim/aircraft/prop/acf_num_blades")
97 print "The result:", numBlades
98 print
99
100 batteryArrayOn = xplane.getIntArray("sim/cockpit/electrical/battery_array_on")
101 print "Setting the batteries"
102 print " from:", batteryArrayOn
103 batteryArrayOn = [1 if b==0 else 0 for b in batteryArrayOn]
104 print " to:", batteryArrayOn
105 xplane.setIntArray("sim/cockpit/electrical/battery_array_on", batteryArrayOn)
106 batteryArrayOn = xplane.getIntArray("sim/cockpit/electrical/battery_array_on")
107 print "The result:", batteryArrayOn
108 print
109
110 tailNum = [0] * 40
111 tailNum[0] = ord('H')
112 tailNum[1] = ord('A')
113 tailNum[2] = ord('-')
114 tailNum[3] = ord('V')
115 tailNum[4] = ord('A')
116 tailNum[5] = ord('I')
117
118 print "Setting the tail number to %s as a byte array..." % (tailNum,)
119 xplane.setByteArray("sim/aircraft/view/acf_tailnum", tailNum)
120 print "The tail number is:", xplane.getString("sim/aircraft/view/acf_tailnum")
121 print
122
123 tailNum1 = "VAIS"
124 print "Setting the tail number to " + tailNum1 + " as a string..."
125 xplane.setString("sim/aircraft/view/acf_tailnum", tailNum1, 40)
126 print "The tail number is:", xplane.getString("sim/aircraft/view/acf_tailnum")
127 print
128
129
130 except Exception as e:
131 print ">>>>>>>>>>>>>>>>>>>>>> Exception caught:", str(e)
132 finally:
133 xplane.disconnect()
Note: See TracBrowser for help on using the repository browser.