Skip to content

getDREF

Christopher Teubert edited this page Aug 14, 2018 · 6 revisions

Gets the value of a single X-Plane dataref.

IMPORTANT: If you are looking to request multiple data refs, please use getDREFs. Using getDREF in a loop with multiple DREFs can cause the results to be mixed (i.e., request B could receive the result of request A)

Syntax

Language Signature
C int getDREF(XPCSocket sock, const char* dref, float values[], int* size)
MATLAB N/A
Java float[] getDREF(String dref)
Python getDREF(dref)
Parameters

sock (C): The socket used to send the command.

msg: The string to display on the screen

dref: The name of the dataref to get.

values (C): An array in which to store the result.

size (C): The allocated size of values. When getDREF returns, this parameter will be set to the number of items actually written to values, which will be less than or equal to the initial value of size.

Return value

C: A negative value if an error occurs, otherwise 0.

All others: An array representing the dataref value.

Remarks

The MATLAB client does not have a getDREF command. Instead, getDREFs can be called with a single string value.

Dataref names and their associated data types can be found on the XPSDK wiki. The size of value should match the size given on that page. XPC currently sends all values as floats regardless of the type described on the wiki. This doesn't cause any data loss for most datarefs.

Exceptions

C Error Code Java Exception Python Error Description
-1 IOException OSError The client is unable to send the command
-2 IOException OSError The client is unable to read the response

Examples

C
#include "xplaneConnect.h"

XPCSocket sock = aopenUDP("127.0.0.1", 49007);

// Get the status of the gear handle
char* dref = "sim/cockpit/switches/gear_handle_status";
float value = 0.0F;
int size = 1;
if(getDREF(sock, dref, &value, &size) < 0)
{
    printf("And error occured.");
}
else
{
    printf("The gear handle status is %f.", value);
}

closeUDP(sock);
Java
import gov.nasa.xpc.XPlaneConnect;

try(XPlaneConnect xpc = new XPlaneConnect())
{
    String dref = "sim/cockpit/switches/gear_handle_status";
    float[] value = xpc.getDREF(dref);
    System.out.print("The gear handle status is ");
    System.out.println(value[0]);
}

Python

import xpc

with xpc.XPlaneConnect() as client:
    dref = "sim/cockpit/switches/gear_handle_status"
    value = client.getDREF(dref)
    print "The gear handle status is " + str(value[0])