Skip to content

getDREFs

Jason Watkins edited this page Apr 22, 2015 · 6 revisions

Gets the value of one or more X-Plane datarefs.

Syntax

Language Signature
C int getDREFs(XPCSocket sock, const char* drefs[], float* values[], unsigned char count, int sizes[])
MATLAB result = getDREFs( drefs, socket )
Java float[][] getDREFs(String[] drefs)
Python getDREFs(drefs)
Parameters

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

msg: The string to display on the screen

drefs: The names of the datarefs to get.

values (C): A 2 dimensional array in which to store the result.

sizes (C): The allocated size of each array in values. When getDREFs returns, each item in sizes will be set to the number of items actually written to the respective array in values, which will be less than or equal to the initial value of that item in sizes.

socket (MATLAB): An optional reference to a socket opened with openUDP that should be used to send the command.

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

returns: An array representing the dataref value.

Remarks

Exceptions

C Error Code Java Exception Python Error Description
-1 IOException The client is unable to send the command
-2 IOException 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 and the actual landing gear
char* drefs[2] = {"sim/cockpit/switches/gear_handle_status", "sim/aircraft/parts/acf_gear_deploy"};
float* values[2];
values[0] = (float*)malloc(1 * sizeof(float));
values[1] = (float*)malloc(10 * sizeof(float));
int sizes[2] = { 1, 10 };
if(getDREFs(sock, drefs, &values, 2, &sizes) < 0)
{
    printf("And error occured.");
}
else
{
    printf("The gear handle status is %f.", values[0][0]);
}

closeUDP(sock);

MATLAB

import XPlaneConnect.*

DREFS = {'sim/cockpit/switches/gear_handle_status',...
         'sim/aircraft/parts/acf_gear_deploy'};

result = getDREFs(DREFS);
Java
import gov.nasa.xpc.XPlaneConnect;
try(XPlaneConnect xpc = new XPlaneConnect())
{
    String[] drefs ={"sim/cockpit/switches/gear_handle_status", "sim/aircraft/parts/acf_gear_deploy"};
    float[][] values = xpc.getDREFs(drefs);
    System.out.print("The gear handle status is ");
    System.out.println(values[0][0]);
}