Creating a Vsystem Database
This chapter discusses the roles played by Vgen, the database-generating utility, and channels in creating a Vsystem database. After learning the concept of "channels," you will create channels for the furnace application from an ASCII file, using Vsystem keywords. You will then use Vsystem commands to convert the ASCII file to an intermediate database file that you can map into memory with the Db_map utility.
Creating a Database With a Standard Text Editor
No conventional programming is required to define a Vsystem database. Instead, you use a standard text editor to create ASCII files. These text files use a keyword syntax and can contain nested files and macro definitions. Once you create an ASCII file, you run Vgen to read the text file and create an intermediate database file. Finally, you use the db_map utility to map the intermediate file into memory.
When creating an ASCII file, you define channels to be used by this application. Channels are the fundamental structural units of the Vsystem database. Channels can be considered the communication path between Vaccess and a particular hardware device or other software.
Various types of hardware require different channels. For example, a simple binary switch uses a channel that carries only one bit of information ("on" or "off"), while a device controlling voltage requires a "real" channel. Vsystem fully supports the following channel data types.
|
BINARY
|
A two-state channel.
|
|
DOUBLE
|
A double-precision floating-point number, single value, or array.
|
|
INTEGER
|
A channel holding 32-bit integer values, a single value, or an array.
|
|
UINTEGER
|
A channel holding 32-bit unsigned integer values, a single value, or an array.
|
|
INT16
|
A channel holding 16-bit signed integer values, a single value, or an array.
|
|
UINT16
|
A channel holding 16-bit unsigned integer values, a single value, or an array.
|
|
INT8
|
A channel holding 8-bit signed integer values, a single value, or an array.
|
|
UINT8
|
A channel holding 8-bit unsigned integer values, a single value, or an array.
|
|
REAL
|
A single-precision floating-point number, single value, or array.
|
|
STRING
|
A channel holding character string information, a single value, or an array.
|
|
TIME
|
A channel storing time information.
|
Channels can also be considered virtual representations of physical input/output points of an I/O system made up of such things as sensors, actuators, servos, and thermocouples. The channel types listed above define the characteristics of these I/O points.
Defining the Furnace Application
This tutorial shows you how to define a furnace application for two rooms, each with a simple open or shut damper. Each room has a thermostat for setting room temperature and a temperature channel for displaying the temperature of the room. You will also define a channel that turns the furnace off and on and a channel that shows the availability status of the furnace.
The furnace database will consist of five output channels:
-
A furnace control channel that turns the furnace on and off.
-
A damper channel that opens and closes a damper for Room 1.
-
A damper channel that opens and closes a damper for Room 2.
-
A thermostat channel that controls the thermostat for Room 1.
-
A thermostat channel that controls the thermostat for Room 2.
The furnace database will also consist of four input channels:
-
A furnace status channel that indicates whether the furnace is available.
-
A temperature channel that displays the temperature of Room 1.
-
A temperature channel that displays the temperature of Room 2.
-
A temperature channel that displays the temperature of the furnace.
Assigning Channels to the Furnace Application
In the text editor of your choice, create a file named furnace.adb.
In the following example, note that the first line of the definition for each channel begins with a dollar ($) character, followed by the channel name. Vsystem references each channel by a unique name. When you define channel names, keep the following in mind:
-
A channel name can be a string of up to 512 characters in length.
-
The dollar ($) character indicates the beginning of the definition of a channel.
The second line of a channel definition declares the data type for the channel. The subsequent lines of the definition vary, depending on the data type declared. Vgen keywords, documented in your Vsystem Vaccess Reference Guide, are underlined here for emphasis.
Creating Binary Channels
The first set of channels you enter defines the binary channels for the database. First, use the binary keyword to declare the channel a binary channel. You will specify the values for the binary zero (b0) and binary one (b1) states. The values for these keywords should be enclosed in double quotation marks (" ").
The value keyword supplies the initial value for the binary channel. The out keyword identifies the channel as an output channel associated with control hardware. The in keyword identifies the channel as an input channel associated with readback hardware.
$furnace_control
binary
b0 "Off"
b1 "On"
value Off
out
$furnace_status
binary
b0 "Unavailable"
b1 "Available"
value Unavailable
in
$room_1_damper
binary
b0 "Closed"
b1 "Open"
value Open
out
$room_2_damper
binary
b0 "Closed"
b1 "Open"
value Open
out
Creating Integer Channels
The next set of channels you enter defines the integer channels for this database. First, use the integer keyword to declare the channel an integer channel. The units keyword enables you to specify the units associated with the external value of the channel. The label keyword adds descriptive information to the channel. The out keyword identifies the channel as an output channel associated with control hardware.
$room_1_thermostat
integer
units "degrees"
label "thermostat setting room 1"
out
$room_2_thermostat
integer
units "degrees"
label "thermostat setting room 2"
out
Creating Real Channels
The final set of channels you enter defines the real channels for this database. First, use the real keyword to declare the channel a real channel. The units keyword enables you to specify the units associated with the external value of the channel. The label keyword adds descriptive information to the channel. The in keyword identifies the channel as an input channel associated with readback hardware.
$room_1_temp
real
units "degrees"
label "temperature setting room 1"
in
$room_2_temp
real
units "degrees"
label "temperature setting room 2"
in
$furnace_temp
real
units "degrees"
label "furnace temperature"
in
Channel definition for the furnace application is now complete. Save the file as furnace.adb and then exit the text editor.
You can find a copy of the furnace.adb file in the Vsystem examples database subdirectory.