Changeset 40:ec5dde8a6ff6 in xplra for src/client/python
- Timestamp:
- 02/14/13 18:21:47 (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/client/python/xplra.py
r37 r40 30 30 COMMAND_GET_VERSIONS = 0x31 31 31 32 COMMAND_RELOAD_PLUGINS = 0x32 33 34 COMMAND_SHOW_MESSAGE = 0x41 35 32 36 TYPE_INT = 0x01 33 37 … … 57 61 58 62 RESULT_INVALID_ID = 0x07 63 64 RESULT_INVALID_DURATION = 0x08 59 65 60 66 RESULT_OTHER_ERROR = 0xff … … 71 77 RESULT_INVALID_COUNT : "invalid count", 72 78 RESULT_INVALID_ID : "invalid ID", 79 RESULT_INVALID_DURATION : "invalid duration", 73 80 RESULT_OTHER_ERROR : "other error" } 74 81 … … 81 88 return "unknown error code " + `resultCode` 82 89 83 def __init__(self, resultCode): 84 super(ProtocolException, self).__init__("xplra.ProtocolException: " + 85 self.getMessage(resultCode)) 90 def __init__(self, resultCode, parameter = None): 91 message = "xplra.ProtocolException: " + self.getMessage(resultCode) 92 if parameter is not None: 93 if resultCode==RESULT_UNKNOWN_DATAREF: 94 message += " (# %d)" % (parameter,) 95 96 super(ProtocolException, self).__init__(message) 86 97 self.resultCode = resultCode 98 self.parameter = parameter 87 99 88 100 #------------------------------------------------------------------------------- … … 145 157 return (self._readS32(), self._readS32(), self._readS32()) 146 158 159 def reloadPlugins(self): 160 """Reload the plugins in X-Plane. 161 162 After this, this connection becomes invalid.""" 163 self._writeU8(COMMAND_RELOAD_PLUGINS) 164 self._flush() 165 self._checkResult(); 166 147 167 def getInt(self, name): 148 168 """Get the value of the integer dataref with the given name.""" … … 212 232 self.setByteArray(name, value, offset) 213 233 234 def showMessage(self, message, duration): 235 """Show a message in the simulator window for the given duration. 236 237 The duration is a floating-point number denoting seconds.""" 238 self._writeU8(COMMAND_SHOW_MESSAGE) 239 self._writeString(message) 240 self._writeFloat(duration) 241 self._flush() 242 self._checkResult() 243 214 244 def disconnect(self): 215 245 """Disconnect from X-Plane.""" … … 218 248 self._stream = None 219 249 220 def _checkResult(self, resultCode = None ):250 def _checkResult(self, resultCode = None, parameter = None, multi = False): 221 251 """Check the given result code. 222 252 … … 227 257 if resultCode is None: 228 258 resultCode = self._readU8() 259 if multi and resultCode==RESULT_UNKNOWN_DATAREF: 260 parameter = self._readU32() 261 229 262 if resultCode!=RESULT_OK: 230 raise ProtocolException(resultCode )263 raise ProtocolException(resultCode, parameter) 231 264 232 265 def _getSingle(self, name, type, length = None, offset = None): … … 525 558 526 559 self._xplane._flush() 527 self._xplane._checkResult( )560 self._xplane._checkResult(multi = True) 528 561 529 562 def __len__(self): … … 591 624 self._xplane._flush() 592 625 593 self._xplane._checkResult( )626 self._xplane._checkResult(multi = True) 594 627 595 628 self._readValues() … … 623 656 self._xplane._flush() 624 657 625 self._xplane._checkResult( )658 self._xplane._checkResult(multi = True) 626 659 627 660 def _executeUnregistered(self): … … 644 677 645 678 self._xplane._flush() 646 self._xplane._checkResult( )647 648 #------------------------------------------------------------------------------- 679 self._xplane._checkResult(multi = True) 680 681 #-------------------------------------------------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.