Skip to main content

API Python Client for C++ Xplane Server

Project description

XPlane Python Client

This repository contains a Python client to send commands directly to XPlane through the C++ server.

Setup

All that is required is to pip install the package.

pip install XPlaneApi

Then we can import it into a project as follows:

from XPlaneApi import XPlaneClient

Running the Setup

  • Start XPlane and wait until a flight has been resumed and you are in the aircraft
  • Navigate to the folder containing the C++ Server for Xplane
    • Modify the subscriptions.txt to add or remove datarefs that you wish to subscribe to.
    • Execute the libXplane-udp-client.exe when ready
  • Begin the Python Client as required

Python API Documentation

The Python API currently has 3 functions available to use as follows:

Connect to the C++ Server by using the connect function seen below.

connect(self):

Disconnect cleanly from the C++ Server by using the connect function seen below.

disconnect(self):

To receive the value of a dataref, use the getDataRef function to receive the value as a string.

getDataRef(self, dref):

To modify the value of a dataref, use the setDataRef function to alter the value. Note, value must be in string format.

setDataRef(self, dref, value):

To send a command to the cockpit, use the sendCommand, input must be in the string format.

sendCommand(self, dref):

Example Program

This example program comes bundled in the package under examples.

from XPlaneApi import XPlaneClient
import time

# Specify a topic for your program to communicate through
# Specify also as input IP address of pc containing xplane if not local
client = XPlaneClient("Python1")

# Call the connect command
client.connect()

# Modify and read value at same time
for i in range(0, 100, 1):
    if client.setDataRef("sim/cockpit2/engine/actuators/throttle_ratio[0]", str(i/100)) == False:
        print("command did not execute correctly!")

    dataRefVal = client.getDataRef("sim/cockpit2/engine/actuators/throttle_ratio[0]")
    print(f"Value received for dref = {dataRefVal}")
    time.sleep(0.005)

# Disconnect the client cleanly
client.disconnect()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

XPlaneApi-0.0.6.tar.gz (4.7 kB view details)

Uploaded Source

File details

Details for the file XPlaneApi-0.0.6.tar.gz.

File metadata

  • Download URL: XPlaneApi-0.0.6.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.1

File hashes

Hashes for XPlaneApi-0.0.6.tar.gz
Algorithm Hash digest
SHA256 299186437ab564b86e2745f986509d6f7d3fb119370d943f947ade546880f633
MD5 95062597018e257cb78c9ef5b992664f
BLAKE2b-256 44ed3969b491f1f0ccfc8e159c8be1b0aa1e77a2e644dd68db0ef5ea88702076

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page