Please enable JavaScript to view this site.

DAQFactory User's Guide

Navigation: 15 Extending DAQFactory > 15.2 User Devices

15.2.3 Local Variables

Scroll Prev Top Next More

For user devices, in addition to private variables, which are only visible in a particular I/O type or function, and global variables that are visible everywhere in DAQFactory, there are local variables.  Local variables are kept with each device and accessible through the device.  They are declared using the local keyword:

 

local MyVariable

Once declared, a local variable can be accessed from any of the I/O types or functions in the device by simply specifying its name:

 

MyVariable = 3

Typically you will want to declare and initialize your locals in the OnLoad function of the device.

In pretty much every case, we recommend using local variables in place of global variables in devices.  You can still access these variables from elsewhere, but using them keeps your protocol code self-sufficient and not dependent on outside globals.  To access a local variable from outside the protocol's I/O type and function code, use Device. notation:

 

Device.MyDevice.MyVariable = 3

Doing simply MyVariable = 3 from outside the protocol's code will not work as DAQFactory will look for a global variable (or channel) named MyVariable and not the local variable.  You also cannot declare a local variable from outside the protocol.