Skip to content

sendDREF

Jason Watkins edited this page May 8, 2015 · 3 revisions

Sets the specified dataref to the specified value.

Syntax

Language Signature
C int sendDREF(XPCSocket sock, const char* dref, float values[], int size)
MATLAB sendDREF( dref, values, socket )
Java void sendDREF(String dref, float[] values)
Python sendDREF(dref, values)
Parameters

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

dref: The name of the dataref to set.

values: An array of values representing the data to set.

size (C): The number of items in value.

Return value

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

Remarks

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 Error ValueError The length of dref is greater than 255 characters
-2 Error ValueError There are more than 255 items in value
-3 IOException OSError The client is unable to send the command

Examples

C
#include "xplaneConnect.h"

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

// Set the status of the gear handle
char* dref = "sim/cockpit/switches/gear_handle_status";
float value = 0.0F;
sendDREF(sock, dref, &value, 1);

closeUDP(sock);

MATLAB

import XPlaneConnect.*

dref = {'sim/cockpit/switches/gear_handle_status'};
value = [0.0];

sendDREF(dref, value);
Java
import gov.nasa.xpc.XPlaneConnect;

try(XPlaneConnect xpc = new XPlaneConnect())
{
    String dref = "sim/cockpit/switches/gear_handle_status";
    float[] value = {0.0F};
    xpc.sendDREF(dref, value);
}

Python

import xpc

with xpc.XPlaneConnect() as client:
    dref = "sim/cockpit/switches/gear_handle_status"
    value = [0.0F]
    client.sendDREF(dref, value)