Welcome to pyXPUDPServer’s documentation!¶
Contents:
-
class
pyxpudpserver.
XPlaneUDPServer
¶ Constructor, do not call directly, when importing the module, an instance of the class is created called pyXPUDPServer.
-
disableRedirectUDPtoXP
()¶ Disables the redirection of traffic received by the class to XPlane
-
enableForwardXPpackets
(forwardAddresses)¶ Enables the forwarding of data received from XPLane to a list of IP addresses
Parameters: forwardAddresses – a list of addresses to forward to, in the format [(IP1,port1),(IP2,port2), … ]
-
enableRedirectUDPtoXP
(myAddress, XPAddress)¶ Enables the redirection of traffic received by the class to XPlane
Parameters: - myAddress – The address the class is listening for traffic on. Format: (IP,port)
- XPAddress – The XP address we will be forwarding the packets to. Format: (IP, port)
-
getData
(dataReference)¶ Returns data last received from XPlane for the key, index provided.
Parameters: dataReference – This can be either a tuple if requesting data set up in the Data Input&Output screen in XPlane, or a string if requesting data from a dataref. The method will automatically request XP to send the dataref if it has not been done previously. Returns: value of the dataref (float) or 0.0 by default if no data Received - Example::
- getData(“sim/cockpit2/radios/actuators/transponder_mode[0]”)
-
initialiseUDP
(Address, XPAddress, XPComputerName)¶ Initialise the UDP sockets to communicate with XPlane
Parameters: - Address – tuple of IP address (str), UDP port (int) we are listening on
- XPAddress – tuple of IP address (str), UDP port (int) for XPlane
- XPComputerName (string) – Network name of the computer XPlane is running on
-
initialiseUDPXMLConfig
(XMLConfigFile)¶ Initialise the UDP sockets to communicate with XPlane via XML configuration file
Parameters: XMLConfigFile (string) – relative path to XML config file
-
printData
(dataReference)¶ Prints data to the console for the key, index provided.
Parameters: dataReference – This can be either a tuple if requesting data set up in the Data Input&Output screen in XPlane, or a string if requesting data from a dataref. The method will automatically request XP to send the dataref if it has not been done previously.
-
quit
()¶ Call to stop the thread and close the UDP sockets
-
registerXPCmdCallback
(callback)¶ Registers a callback function to be called if the class receives a sendXPCmd() call
Parameters: callback – The callback function, it will be given the command string as parameter so your callback must handle the command string Type: function
-
requestXPDref
(dataref)¶ Request Dataref from XPlane - note calling getData(‘somedataref’) will achieve the same effect and is easier (will call this function in the background)
Parameters: dataref (string) – dataref requested from XPlane - refer to the XPlane doc for a list of available datarefs
-
restart
(Address, XPAddress, XPComputerName)¶ Restart the UDP sockets to communicate with XPlane
Parameters: - Address – tuple of IP address (str), UDP port we are listening on (int)
- XPAddress – tuple of IP address (str), UDP port for XPlane (int)
- XPComputerName (string) – Network name of the computer XPlane is running on
-
run
()¶ Internal thread loop - Do not call - use the start() method to start the thread, which will call run() Infinite loop listening for data from XPlane. When data is received, it is parsed and stored/updated in the private dataList attribute If the instance has been configured to forward XPlane packets, it will loop through the forward addresses to do so If the instance has been configured to re direct traffic to XPlane, it will forward any packets received to XP
-
sendXPCmd
(command, sendContinuous=False)¶ Send command to XPlane
Parameters: - command (string) – command to be sent to XPlane - refer to the XPlane doc for a list of available commands
- sendContinuous (bool) – default False, command will only be sent once. If True, the command will be sent continuously until a call to stopSendingXPCmd is made
-
sendXPDref
(dataref, index=0, value=0.0)¶ Sets the value of a dataref in XPlane
Parameters: - dataref (string) – Dataref to be set in XPlane - refer to the XPlane doc for a list of available datarefs
- index (int) – the index of the dataref to set, for datarefs that have multiple values. Default is 0
- value (float) – the value to set the dataref to
-
stopSendingXPCmd
(command)¶ Stop sending command to XPlane, where a call to sendXPCmd for this command has been made with sendContinuous set to True
Parameters: command (string) – command to stop sending to XPlane - refer to the XPlane doc for a list of available commands
-