Built-in tables and references
SignalSQL presents the physical world as a set of built-in tables. Loaded
modules populate INPUT and OUTPUT with the signals they expose, and you wire
signals together with references.
References
A reference lets a column hold the value of another table’s row instead of a literal. The syntax is:
=Table/Row/Column
When the column is read, SignalSQL resolves the reference and returns the target
value. Row may be a primary-key value or a Name. This is how an input signal
gets routed to a control algorithm and on to an output — see
Hardware modules and the
brewery example.
-- Read the current temperature of a 1-wire probe by referencing its INPUT row
'=INPUT/owdevice:28.F049AF040000/Value'
INPUT
The INPUT table consolidates every input signal supported by the loaded
modules into one unified view.
CREATE TABLE INPUT (
ID INT AUTO_INCREMENT PRIMARY KEY, -- The id of this INPUT.
Name VARCHAR(255), -- Symbolic name of this input signal
Type CHAR(1), -- 'A' or 'D' for an analog or digital input
Value double -- The value of this input
)
- ID is generated dynamically and varies between restarts — use it in queries but do not store it in your application.
- Name is generated by the module and is stable over time.
- Type is
A(analog) orD(digital). An analog signal is any value that fits in a double; a digital signal is only0or1.
OUTPUT
The OUTPUT table consolidates every output signal from the loaded modules.
Writing a row’s Value sets the desired output.
CREATE TABLE OUTPUT (
ID INT AUTO_INCREMENT PRIMARY KEY, -- The id of this OUTPUT.
Name VARCHAR(255), -- Symbolic name of this output signal
Type CHAR(1), -- 'A' or 'D' for an analog or digital output
Value double -- Desired value of this output
)
The same ID/Name rules apply as for INPUT. For a digital output, Value is
zero or non-zero.
MODULES
The MODULES table lets an application enable or disable modules at runtime.
CREATE TABLE MODULES (
ID INT AUTO_INCREMENT PRIMARY KEY, -- The id of this MODULE.
Name VARCHAR(255), -- Short name of this module
Enabled TINY -- 0 if the module is disabled, 1 if enabled
)
Name is the module’s short name (normally the same as its table name). Set
Enabled to zero to deactivate the corresponding module.
Reading and writing signals
Because signals are just rows, you use ordinary SQL:
-- List every input signal
SELECT * FROM INPUT;
-- Read one probe by name
SELECT Value FROM INPUT WHERE Name = 'owdevice:28.F049AF040000';
-- Drive a digital output on
UPDATE OUTPUT SET Value = 1 WHERE Name = 'owdevice:12.574B7D000000';