Data bus

From Sim Innovations Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Instruments are all about displaying data. This data comes from the simulator software. Of course you do not want to have all of the data that is available, that would be too much, so that is why you need to 'subscribe' to a certain type of data. This data type is called a 'Dataref' in case of X-Plane and a 'Variable' in case of FSX and Prepar3D. Lets see how that works for each sim.

This page is part of the Instrument Creation Tutorial.

X-Plane datarefs

X-Plane uses so called datarefs, which are all displayed in a huge list here. I will describe all the labels for you below.

Name

The first column is Name, this is the dataref name which you will have to use to subscribe. Let's use an example: If you search for indicated airspeed, you will find a dataref named sim/cockpit2/gauges/indicators/airspeed_kts_pilot.

Type

The second column is called Type, this is the datatype. Don't worry if you don't understand the difference between FLOAT, INT, etc... we will cover that later. In this case the dataref is a FLOAT.

Writable

The third column is called Writable, this tells you if you can also write data to this dataref. In this case it says 'n', which means no. This means you are not able to change the speed by writing data to this dataref. This can be important when you are using buttons, switches or dials, if not: forget this.

Units

The fourth column is called Units, this (sometimes) shows the unit of the dataref. In this case the unit is knots. You will see all sorts of units, also strange ones like ENUM and BOOL(EAN), don't worry about these for now.

Description

The fifth and last column is called Description, no mystery about this one. It will give you a short explanation about the dataref.

Subscribing to a dataref

Now we know all about the dataref, lets subscribe to it. The X-Plane dataref subscribe function is as follows: xpl_dataref_subscribe(dataref,data_type,callback_function)
We know the name, so we'll fill it in between quotes:

xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/airspeed_kts_pilot",data_type,callback_function)

Next up is the type, we'll fill that in, also between quotes:

xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/airspeed_kts_pilot","FLOAT",callback_function)

Last runner up is the callback_function. This is the name of the function that is being 'called' when data comes in trough this dataref. The subscribe function will send it's data to the function you have created, the function in turn will do something with that data, like rotating the needle of the airspeed indicator. More about this functions later on. You can make up your own name for this callback_function, in this example I will call it callback_speed.

xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/airspeed_kts_pilot","FLOAT",callback_speed)

That is all there is to it to get your desired data from X-Plane. In the next lessons you will learn how to do something with this data.

FSX / Prepar3D

FSX and Prepar3D use so called (simulation) variables, which are all displayed in a huge list here. I will describe all the labels for you below.

Simulation Variable

The first column is called Simulation Variable, this is the variable name which you will have to use to subscribe. Let's use an example: If you search for indicated airspeed, you will find 'AIRSPEED INDICATED'.

Description

The second column is called Description, this one is obvious. It will give you a short explanation about the variable.

Units

The third column is called Units, this shows the unit of the variable. In this case the unit is knots. You will see all sorts of units, also strange ones like ENUM and BOOL(EAN), don't worry about these for now. FSX and Prepar3D, unlike X-Plane, have the possibility to select a different unit. On the bottom of the page you will find a list of different units you can use. You can get the speed in units like knots, mach, kph, etc...

Settable

The fourth column is called Settable, this tells you if you can also write data to this variable. In this case it says 'Y', which means yes. This means you are able to change the speed by writing data to this variable. This can be important when you are using buttons, switches or dials, if not: forget this.

Multiplayer

You can forget about this one.

Subscribing to a variable

Now we know all about the variables, lets subscribe to it. The FSX / Prepar3D variable subscribe function is as follows: fsx_variable_subscribe(variable,unit,callback_function)
We know the name of the simulation variable, so we'll fill it in between quotes:

fsx_variable_subscribe("AIRSPEED INDICATED",unit,callback_function)

Next one is the unit, you are probably looking for knots here, so we fill in knots between quotes:

fsx_variable_subscribe("AIRSPEED INDICATED","Knots",callback_function)

Last runner up is the callback_function. This is the name of the function that is being 'called' when data comes in trough this variable. The subscribe function will send it's data to the function you have created, the function in turn will do something with that data, like rotating the needle of the airspeed indicator. More about this functions later on. You can make up your own name for this callback_function, in this example I will call it callback_speed.

fsx_variable_subscribe("AIRSPEED INDICATED","Knots",callback_speed)

That's how easy it is. In the next tutorial we will do something with this data.