Skip to content

UDP

udp

X-Plane access through UDP messages

UDP interface is limited to 1. Asking for dataref values, one at a time, returned as a float number. 2. Setting single dataref value in simulator ("write"). 3. Asking for execution of a command.

Classes:

  • XPUDPAPI

    Get data from XPlane via network.

XPUDPAPI

XPUDPAPI(**kwargs)

              flowchart TD
              xpwebapi.udp.XPUDPAPI[XPUDPAPI]
              xpwebapi.api.API[API]

                              xpwebapi.api.API --> xpwebapi.udp.XPUDPAPI
                


              click xpwebapi.udp.XPUDPAPI href "" "xpwebapi.udp.XPUDPAPI"
              click xpwebapi.api.API href "" "xpwebapi.api.API"
            

Get data from XPlane via network. Use a class to implement RAI Pattern for the UDP socket.

Methods:

  • abort

    Signal the listener before immediately closing its socket.

  • add_callback

    Add callback function to set of callback functions

  • beacon_callback

    Callback waits a little bit before shutting down websocket handler on beacon miss.

  • changed

    If rounding applies, determine if value has changed according to its rounding.

  • close

    Stop monitored datarefs and close the UDP socket.

  • command

    Create Command with current API

  • dataref

    Create Dataref with current API

  • dataref_value

    Returns Dataref value from simulator

  • execute_callbacks

    Execute list of callback functions, all with same arguments passed as keyword arguments

  • execute_command

    Execute command

  • monitor_dataref

    Starts monitoring single dataref.

  • read_monitored_dataref_values

    Do a single read and populate dataref with values.

  • set_network

    Set network and API parameters for connection

  • set_roundings

    Add rounding to simulator variable value.

  • simple_connection_probe

    Exeprimental

  • start

    Start UDP monitoring

  • stop

    Stop UDP monitoring

  • unmonitor_datarefs

    Stops monitoring supplied datarefs.

  • write_dataref

    Write Dataref value to X-Plane if Dataref is writable

Attributes:

connected property

connected: bool

Whether X-Plane API is reachable through this API

rest_url property

rest_url: str

URL for the REST API

status property writable

Connection status

status_str property

status_str: str

Connection status as a string

use_rest property writable

use_rest: bool

Should use REST API for some purpose

abort

abort() -> None

Signal the listener before immediately closing its socket.

add_callback

add_callback(callback: Callable)

Add callback function to set of callback functions

Please note that in the case of UDP, callback is called for each value it received, whether the value has changed or not.

Parameters:

  • callback

    (Callable) –

    Callback function

beacon_callback

beacon_callback(connected: bool, beacon_data: BeaconData, same_host: bool)

Callback waits a little bit before shutting down websocket handler on beacon miss. Starts or make sure it is running on beacon hit.

Parameters:

  • connected

    (bool) –

    Whether beacon is received

  • beacon_data

    (BeaconData) –

    Beacon data

  • same_host

    (bool) –

    Whether beacon is issued from same host as host running the monitor

changed

changed(dataref, value) -> bool

If rounding applies, determine if value has changed according to its rounding.

close

close() -> None

Stop monitored datarefs and close the UDP socket.

command

command(path: str) -> Command

Create Command with current API

Parameters:

  • path

    (str) –

    Command "path"

Returns:

  • Command ( Command ) –

    Created command

dataref

dataref(path: str, auto_save: bool = False) -> Dataref

Create Dataref with current API

Parameters:

  • path

    (str) –

    Dataref "path"

  • auto_save

    (bool, default: False ) –

    Save dataref back to X-Plane if value has changed and writable (default: False)

Returns:

  • Dataref ( Dataref ) –

    Created dataref

dataref_value

dataref_value(
    dataref: Dataref, raw: bool = False, no_decode: bool = False
) -> DatarefReadResult

Returns Dataref value from simulator

Parameters:

  • dataref

    (Dataref) –

    Dataref to get the value from

Returns:

  • DatarefReadResult ( DatarefReadResult ) –

    Value of dataref.

execute_callbacks

execute_callbacks(**kwargs) -> bool

Execute list of callback functions, all with same arguments passed as keyword arguments

returns

bool: Whether error reported during execution

execute_command

execute_command(command: Command, duration: float = 0.0) -> bool

Execute command

Parameters:

  • command

    (Command) –

    Command to execute

  • duration

    (float, default: 0.0 ) –

    Duration of execution for long commands (default: 0.0)

Returns:

  • bool ( bool ) –

    [description]

monitor_dataref

monitor_dataref(dataref: Dataref, frequency_hz: int = 1) -> bool | int

Starts monitoring single dataref.

[description]

Parameters:

  • dataref

    (Dataref) –

    Dataref to monitor

Returns:

  • bool | int

    bool if fails

  • bool | int

    request id if succeeded

read_monitored_dataref_values

read_monitored_dataref_values() -> dict

Do a single read and populate dataref with values.

This function should be called at regular intervals to collect all requested datarefs. (A single read returns about 15 values.)

Returns:

  • dict ( dict ) –

    {path: value} for received datarefs so far.

Raises:

  • XPlaneTimeout

    [description]

set_network

set_network(host: str, port: int, api: str, api_version: str) -> bool

Set network and API parameters for connection

Parameters:

  • host

    (str) –

    Host name or IP address

  • port

    (int) –

    TCP port number for API

  • api

    (str) –

    API root path, starts with /.

  • api_version

    (str) –

    API version string, starts with /, appended to api string to form full path to API.

Returns:

  • bool ( bool ) –

    True if some network parameter has changed

set_roundings

set_roundings(roundings)

Add rounding to simulator variable value. Rounding is applied to value before it is sent to callback function.

simple_connection_probe

simple_connection_probe() -> bool

Exeprimental

Do we receive a UPD message within TIMEOUT seconds?

returns:

(bool) UPD message recieved

start

start(release: bool = True)

Start UDP monitoring

stop

stop(timeout_seconds: float | None = None)

Stop UDP monitoring

unmonitor_datarefs

unmonitor_datarefs(
    datarefs: dict, reason: str | None = None
) -> tuple[int | bool, dict]

Stops monitoring supplied datarefs.

[description]

Parameters:

  • datarefs

    (dict) –

    {path: Dataref} dictionary of datarefs

  • reason

    (str | None, default: None ) –

    Documentation only string to identify call to function.

Returns:

  • tuple[int | bool, dict]

    tuple[int | bool, dict]: [description]

write_dataref

write_dataref(dataref: Dataref) -> bool

Write Dataref value to X-Plane if Dataref is writable

Parameters:

  • dataref

    (Dataref) –

    Dataref to write

Returns:

  • bool ( bool ) –

    Whether write operation was successful or not