Defining a device

Devices are defined and created in the same way that rectangles, circles images and text are defined:  first you define the type of the device, then you actually create an instance of that device type.

To define a type of device the syntax is almost the same as for rectangles, circles, etc. except that the syntax is slightly more expressive because devices are slightly more complex.

The main difference is that we need to define the device driver – that is, which driver is used to actually interact with the physical device.


define type of device <your-device-type-name> using the <name-of-driver> driver [without persistence

name = “name that appears in database”

[define variable definitions for this driver]

end device


Then, just like rectangles, circles, etc. you need to actually create an instance of this type of device:


define myDeviceInstance = create <your-device-type-name>


Once the create line runs the device will appear in the “Session devices” tool window on the right-hand side of the application and you can actually see the live values from the device and (for an output device) set the value of the device manually.

Database

When a driver uses persistence, all data coming from the device or writes to the device will be logged in the database’s Events table.  The name defined in the device definition is used as the Event source within the database, which makes it easy to search for and write SQL queries against data from a particular device.