source: xplra/test/basictest.py@ 64:29a745311929

Last change on this file since 64:29a745311929 was 40:ec5dde8a6ff6, checked in by István Váradi <ivaradi@…>, 12 years ago

Implemented the client support for the new commands and updated the basic test programs with tests showing messages

File size: 6.2 KB
Line 
1# Basic test program for the Python client library
2
3#------------------------------------------------------------------------------
4
5import time
6
7#------------------------------------------------------------------------------
8
9if __name__ == "__main__":
10 from xplra import XPlane, ProtocolException
11
12 xplane = XPlane()
13
14 try:
15 print "Connecting to X-Plane..."
16 xplane.connect()
17 print "Connected to X-Plane."
18 print
19
20 print "Showing a message..."
21 xplane.showMessage("[basictest] Starting tests", 5.0)
22 print
23
24 print "Querying the versions..."
25 (xplaneVersion, xplmVersion, xplraVersion) = xplane.getVersions()
26 print "X-Plane version: %d, XPLM: %d, XPLRA: %03d" % \
27 (xplaneVersion, xplmVersion, xplraVersion)
28 print
29
30 print "Querying the number of the engines..."
31 numEngines = xplane.getInt("sim/aircraft/engine/acf_num_engines")
32 print "The number of engines:", numEngines
33 print
34
35 try:
36 print "Querying an invalid dataref..."
37 xplane.getInt("sim/aircraft/engine/num_engines")
38 print
39 print ">>>>>>>>>>>> Succeeded!!!!!!!!!!!!!!!!!!!!!!"
40 except ProtocolException as e:
41 print "Exception caugth:", str(e)
42 print
43
44 print "Querying the spool time of a jet engine..."
45 spoolTime = xplane.getFloat("sim/aircraft/engine/acf_spooltime_jet")
46 print "The spool time:", spoolTime
47 print
48
49 print "Querying the spool time of a propeller..."
50 spoolTime = xplane.getFloat("sim/aircraft/engine/acf_spooltime_prop")
51 print "The spool time:", spoolTime
52 print
53
54 print "Querying the coordinates..."
55 latitude = xplane.getDouble("sim/flightmodel/position/latitude")
56 longitude = xplane.getDouble("sim/flightmodel/position/longitude")
57 print "The coordinates: " + `latitude` + ", " + `longitude`
58 print
59
60 print "Querying the aircraft's description..."
61 result = xplane.getByteArray("sim/aircraft/view/acf_descrip")
62 print "The description:", result
63 print
64
65 print "Querying the aircraft's description as a string, with an offset of 3..."
66 result2 = xplane.getString("sim/aircraft/view/acf_descrip", offset = 3);
67 print "Got: '" + result2 + "' (" + `len(result2)` + ")"
68 print result2=="h 8 Q400"
69 print
70
71 print "Querying the aircraft's engine types..."
72 result3 = xplane.getIntArray("sim/aircraft/prop/acf_en_type")
73 print "Got:", result3
74 print
75
76 print "Querying the aircraft's propeller directions..."
77 result5 = xplane.getFloatArray("sim/aircraft/prop/acf_prop_dir")
78 print "Got:", result5
79 print
80
81 print "Setting the number of the engines to", numEngines + 1
82 xplane.setInt("sim/aircraft/engine/acf_num_engines", numEngines + 1)
83 numEngines = xplane.getInt("sim/aircraft/engine/acf_num_engines")
84 print "The new number of engines:", numEngines
85 print
86
87 acfElevUp = xplane.getFloat("sim/aircraft/controls/acf_elev_up")
88 print "Setting the aircraft elevator up control from %f to %f..." % \
89 (acfElevUp, acfElevUp + 15.0)
90 xplane.setFloat("sim/aircraft/controls/acf_elev_up", acfElevUp + 15.0)
91 acfElevUp = xplane.getFloat("sim/aircraft/controls/acf_elev_up")
92 print "The aircraft elevator up control set to", acfElevUp
93 print
94
95 localX = xplane.getDouble("sim/flightmodel/position/local_x")
96 print "Setting the aircraft's local X-coordinate from %f to %f..." % \
97 (localX, localX + 15.0)
98 xplane.setDouble("sim/flightmodel/position/local_x", localX + 15.0)
99 localX = xplane.getDouble("sim/flightmodel/position/local_x")
100 print "The aircraft's local X-coordinate set to", localX
101 print
102
103 numBlades = xplane.getFloatArray("sim/aircraft/prop/acf_num_blades")
104 print "Setting the number of blades"
105 print " from:", numBlades
106 numBlades = [n+2.5 for n in numBlades]
107 print " to:", numBlades
108 xplane.setFloatArray("sim/aircraft/prop/acf_num_blades", numBlades)
109
110 numBlades = xplane.getFloatArray("sim/aircraft/prop/acf_num_blades")
111 print "The result:", numBlades
112 print
113
114 batteryArrayOn = xplane.getIntArray("sim/cockpit/electrical/battery_array_on")
115 print "Setting the batteries"
116 print " from:", batteryArrayOn
117 batteryArrayOn = [1 if b==0 else 0 for b in batteryArrayOn]
118 print " to:", batteryArrayOn
119 xplane.setIntArray("sim/cockpit/electrical/battery_array_on", batteryArrayOn)
120 batteryArrayOn = xplane.getIntArray("sim/cockpit/electrical/battery_array_on")
121 print "The result:", batteryArrayOn
122 print
123
124 tailNum = [0] * 40
125 tailNum[0] = ord('H')
126 tailNum[1] = ord('A')
127 tailNum[2] = ord('-')
128 tailNum[3] = ord('V')
129 tailNum[4] = ord('A')
130 tailNum[5] = ord('I')
131
132 print "Setting the tail number to %s as a byte array..." % (tailNum,)
133 xplane.setByteArray("sim/aircraft/view/acf_tailnum", tailNum)
134 print "The tail number is:", xplane.getString("sim/aircraft/view/acf_tailnum")
135 print
136
137 tailNum1 = "VAIS"
138 print "Setting the tail number to " + tailNum1 + " as a string..."
139 xplane.setString("sim/aircraft/view/acf_tailnum", tailNum1, 40)
140 print "The tail number is:", xplane.getString("sim/aircraft/view/acf_tailnum")
141 print
142
143 print "Preparing for the message tests, sleeping for 5 seconds..."
144 time.sleep(5.0)
145
146 print "Showing a message for 10 seconds..."
147 xplane.showMessage("[basictest] this message appears for 10 seconds", 10.0)
148
149 print "Sleeping for 3 seconds..."
150 time.sleep(3.0)
151
152 print "Showing another message interrupting the previous one for 3 seconds"
153 xplane.showMessage("[basictest] but this message interrupts it, and is displayed for 3 seconds", 3.0)
154
155 print "Sleeping for 5 seconds..."
156 time.sleep(5.0)
157 xplane.showMessage("[basictest] and the tests come to an end!", 5.0)
158
159 except Exception as e:
160 print ">>>>>>>>>>>>>>>>>>>>>> Exception caught:", str(e)
161 finally:
162 xplane.disconnect()
Note: See TracBrowser for help on using the repository browser.