Skip to content
leleopard edited this page Feb 4, 2018 · 7 revisions

Welcome to the pyXPUDPServer wiki!

Description

This module allows you to exchange data with XPlane over UDP. You can read or set the value of any dataref in Xplane,and send commands to XPlane. Your python application only needs to import this module and initialise it. Your app can be running on either on the same PC running XPlane, or on any computer on your local network.

Installation

This module requires python 3. The easiest way to install it is to run 'pip install pyxpudpserver'

Documentation

Visit https://leleopard.github.io/pyXPUDPServer/ for the documentation of the module functions.

Simple Example:

import pyxpudpserver as XPUDP

XPUDP.pyXPUDPServer.initialiseUDP(('127.0.0.1',49008), ('192.168.1.1',49000), 'MYPC')
# where ('127.0.0.1',49008) is the IP and port this class is listening on (configure in the Net connections in XPlane)
# and ('192.168.1.1',49000) is the IP and port of XPlane
# 'MYPC' is the name of the computer XPlane is running on

# You can also initialise from an XML configuration file:
XPUDP.pyXPUDPServer.initialiseUDPXMLConfig('UDPSettings.xml')

XPUDP.pyXPUDPServer.start() # start the server which will run an infinite loop

while True: # infinite loop - for a real application plan for a 'proper' way to exit the programme and break this loop
    value = XPUDP.pyXPUDPServer.getData((17,3)) # read the value sent by XPlane for datagroup 17, position 4 (mag heading)
    transp_mode = XPUDP.pyXPUDPServer.getData("sim/cockpit2/radios/actuators/transponder_mode[0]") # gets the value of this dataref in XPlane
    XPUDP.pyXPUDPServer.sendXPCmd('sim/engines/engage_starters') # send command to XPlane to engage the engine starters
    XPUDP.pyXPUDPServer.sendXPDref("sim/flightmodel/controls/flaprqst", 0, value = 0.5) # set the requested flap deployment to 0.5 - bear in mind the flap will then deploy and take some time to do so - monitor its actual position if needed

XPUDP.pyXPUDPServer.quit() # exit the server thread and close the sockets

Change log

v1.1 - 4 Feb 2018

fixed issue when RREFs are not available if the module is started before XPlane

v1.0 - Initial release