Reference¶
The guides say why. These pages say exactly what: every built-in scope, object and function of the script language, every function you put in an XML chain, and every connection type and protocol — what to write, what it reads, what comes back, and the trap. Every example on these pages was run on engine 4.4.2.702 and its result is written beside it.
Engine 4.4.2.703 fixed the bugs these pages found (crashes in custom time formats and
CODEC, hangs in ELM.eval and jsn(), the role of a pro_onreq handler, chains over 63
characters, rounding, and more). Where a function changed, its page says what it does
now and, in a sentence starting "Before 4.4.2.703", what an older engine does.
Read a guide first. 03_Scripting explains where script lives and how the XML calls it; 02_Timers_and_Events why a write runs a chain. This reference assumes both.
The pages¶
| Page | What is on it |
|---|---|
| 01_Language | Types and literals, the global functions, Math, Number, String, Array, Object, JSON, Buffer, and the methods every value answers (toINT, toDEC, toDTM …) |
| 02_Time_Text_and_Codecs | Time, TIME, CODEC (Base64, hex, JWT), BYTES, Blob, SOAP, SYS, LOG, RES |
| 03_Events_Documents_and_Addresses | evt, xdb, element objects, new XML(..), threads, the address language and its functions (count, json(), stat() …), the special # addresses, sta and STA |
| 04_Attribute_and_Element_Functions | Chain functions: ATR, VAL, ELM, XDB, EVT, THR, SCR |
| 05_Alarms_Conditions_and_Protocol_Chains | Chain functions: ALM, IF, FILTER, CTRL, and the PRO functions every protocol shares |
| 06_Sessions_and_Protocol_Scripts | ses, exc, buffers, connection objects, req and res, every protocol hook (pro_onparse …), MQTT, TOPIC, AUTH, LDAP |
| 07_SQL_History_Files_and_Cluster | SQL, HIS, File, LIC, CLT, REP, RPC, OPC, PY |
| 08_Engine_Modules | FILE, IMG, CAM, GPIO, I2C, SPI, NET — the scopes of the engine modules beside the engine |
| 09_Connection_and_Protocol_Types | Every CON.x and PRO.x you put in a <con>'s xdb_fnc, and the con_* / pro_* fields each reads |
At the end of this page every name is listed once, with a link to its entry.
Ask the engine¶
The engine documents itself. The reference is the long form; the engine's
help is the short one, always at hand and always the version you run. The
same commands answer in three places.
In the console window¶
Start the engine in a console (run.bat, ./run.sh, or
AyXDB.exe -console <path>\db\AyXDB.xml) and press CTRL-X (CTRL-R does the
same). The log keeps running and a prompt with the document's name appears:
EDU/S00> help Math
| Type | What happens |
|---|---|
help or ? |
the commands, then every scope that documents itself, one line each |
help <SCOPE> |
that scope's help, and the names of its extra texts (help CON ends with CON.help_tcp, CON.help_ser …) |
ver |
version, current document, its log file, the licence |
pwd / cd NAME |
the document the prompt evaluates in / switch to another one |
log [lvl] [lines] |
the latest records of the current document's log |
log on [lvl] / log off |
how much of the log the console shows |
exit or CTRL-X |
leave the prompt; the engine runs on |
quit |
stop the engine |
| anything else | evaluated as script in the current document, and the value printed |
The console runs as the engine: no xdb_acl applies to it, it can read and
write everything. It exists only while the engine has a console of its own — an
engine that AySVC runs as a service has none. For that, the shell below.
In a telnet shell¶
A <con xdb_fnc="[CON.tcp,PRO.telnet]"> is the same prompt over a socket,
with a login. PRJEDU_telnet is a
complete one (log in as admin / admin123 on 127.0.0.1:2323). It knows the
same commands, plus who and history, and the arrow keys walk the history.
What you type runs with your session's role, so xdb_acl applies exactly
as it does to any other remote caller. The help itself is open to every role.
A session, as it comes back (trimmed):
SHL/S00> help CON
CON : General configuration fields
con_host : address to connect to
...
More under CON (type the whole name):
CON.help_sql
CON.help_tcp
...
SHL/S00> CON.help_tcp
TCP connection
CON.tcp : CLIENT/CONNECT mode: makes a TCP connection to a server
CON.tcp : SERVER/LISTEN mode: works as a server taking TCP connection requests
con_host='10.40.1.51' con_port='502'
SHL/S00> Object.keys(Time)
["help","GetTimeStr","FmtTimeStr","GetTimeMs","now","ParseTimeMs","GetTimeZoneMs","GetTimeDstMs","tz","AddDurationMs","SleepMs"]
From a script¶
Every scope's help is a value under the key help (lower case; an engine
module's scope keeps its text under a function's name, below):
evt.Log(4, Math.help); // the text into the log
evt.Log(4, Object.keys(Math)); // every name in the scope, as JSON text
var all = evt.AskValue("#shell", "help"); // what 'help' prints, as a string
var pro = evt.AskValue("#shell", "help PRO");
What to type for what¶
| You want | Type |
|---|---|
| every scope that has a help text | help |
| one scope | help Math or Math.help |
| every name in a scope, help or not | Object.keys(Math) — the complete list |
| one connection type or protocol | help CON / help PRO, then the name it lists: CON.help_tcp, PRO.help_modbus |
| the event object | Object.XDB_EVT.help (or evt.help in a script) |
| the document object | Object.XDB_DOC.help (or xdb.help) |
| the other objects | Object.keys(Object) names them: XDB_ELM, XDB_THR, XDB_CON, CON_SES, CON_EXC, CON_BUF, CON_PRO, SQL_CON, SQL_RS, HTTP_MSG, HTTP_RES, LDAP_CON; then Object.CON_SES.help … |
| an engine module's scope | FILE.help_list, IMG.help_decode, CAM.help_list, GPIO.help_chips, I2C.help_scan, SPI.help_sim; NET.help_ver once AyLIB_net is attached (by FILE.help_list, a mail or file-transfer connection, or xdb_lib="AyLIB_net") |
| SQL | PRO.help_sql (and Object.keys(SQL)) |
the values of log_cfg, xdb_log, sta and the type codes |
the root help, a value called help: in the console or the shell type "" + help (a bare help is the command), in a script evt.Log(4, help) |
Three things the list does not show, measured on 4.4.2.702:
SQLis not in the list — it has no help text.help SQLsaysSQL has no help text; its functions are described inPRO.help_sql.- The engine modules' scopes are not in the list (
FILE,IMG,CAM,GPIO,I2C,SPI,NET), andhelp FILEanswersno such scope. Their texts are named after a function: typeFILE.help_list— that attaches the module and prints the text. Before the module is attachedObject.keys(FILE)answers[].NETalone is not attached by its own name: it appears when something else attachesAyLIB_net. help CONandhelp PROlist a module's transports and protocols only once that module is attached.PRO.help_gpioprints nothing before; typeGPIO.help_chips(or use the module) andhelp PROthen listsPRO.help_gpioandPRO.help_reg. The same goes forAyLIB_net(FILE.help_list→PRO.help_smtp,PRO.help_ftp,PRO.help_sftp,CON.help_ssh) andAyLIB_vision(IMG.help_decode→CON.help_cam,PRO.help_cam,PRO.help_vision).
A help line is one line. Where it is too short, or a few still carry an internal change number in brackets, this reference is the long form.
How to read an entry¶
A script function starts with its call and what it gives back:
Math.round(v) → integer
then what it does, its arguments, what comes back on a bad argument, an example with the measured result as a comment, and the trap if there is one.
A chain function — one you write in XML, in a *_fnc attribute — starts
with three facts:
In: where it goes. Reads: the attributes it takes its parameters from. Changes: what it writes.
<atr> stands for the attribute whose chain it is in. ATR.rou in a val_fnc
reads val_rou; the same function in a pro_fnc reads pro_rou.
Roles are numbers: 0 Guest, 1 Customer, 2 Monitor, 3 Operator, 4 Supervisor,
5 Manager, 6 Engineer, 7 Admin, and two that are not people — 8 Document (a
replication peer) and 9 System (the engine itself). The engine's own timers and
chains run as System. A script started by a page, a telnet line or an MQTT
command runs with that user's role, and a function that needs "Engineer or above"
refuses anyone below with one ERROR line.
Types are the val_typ codes — 0x0308 a double, 0x0104 an unsigned 32-bit
integer, 0x0401 a string. 01_Language lists
the ones a script meets.
Every name¶
Language¶
- Types and literals — Arithmetic follows the left operand
- Global functions — Number() and String() ·
parseInt·parseFloat·isNaN·isFinite·debug·addressOf - Math —
Math.abs·Math.floor·Math.ceil·Math.round·Math.trunc·Math.sign·Math.min·Math.max·Math.pow·Math.sqrt·Math.log·Math.log10·Math.exp·Math.sin·Math.cos·Math.tan·Math.asin·Math.acos·Math.atan·Math.atan2·Math.random· Math constants - Number —
Number.toFixed·Number.toString·Number.isInteger·Number.isNaN·Number.isFinite·Number.parse· Number constants - String —
String.length·String.size·String.substr·String.slice·String.substring·String.at·String.charAt·String.charCodeAt·String.codePointAt·String.fromCharCode·String.indexOf·String.lastIndexOf·String.includes·String.startsWith·String.endsWith·String.replace·String.replaceAll·String.toUpperCase·String.toLowerCase·String.trim·String.trimStart·String.trimEnd·String.padStart·String.padEnd·String.repeat·String.concat·String.split·String.utf8·String.utf16 - Array —
Array.push·Array.pop·Array.shift·Array.unshift·Array.slice·Array.splice·Array.join·Array.indexOf·Array.includes·Array.reverse·Array.sort·Array.concat·Array.length·Array.isArray·Array.create·Array.ins·Array.del·Array.put·Array.get - Object —
Object.type·Object.isArray·Object.length·Object.keys·Object.item·Object.hasOwnProperty·Object.toUNS·Object.toINT·Object.toFLT·Object.toSTR·Object.create - JSON —
JSON.parse·JSON.stringify - Buffer —
Buffer.create·Buffer.ins·Buffer.del·Buffer.put·Buffer.get - Value methods —
value.toINT·value.toUNS·value.toHEX·value.toFLT·value.toSTR·value.toS08·value.toS16·value.toDEC·value.toDTM·value.toDATE·value.toTIME·value.toDUR
Time, text and codecs¶
- Time —
Time.GetTimeStr·Time.FmtTimeStr·Time.GetTimeMs·Time.now·Time.ParseTimeMs·Time.GetTimeZoneMs·Time.GetTimeDstMs·Time.tz·Time.AddDurationMs·Time.SleepMs - TIME: a chain function —
TIME.str - CODEC —
CODEC.B64_enc·CODEC.B64_dec·CODEC.HEX_enc·CODEC.HEX_dec·CODEC.Z64_enc·CODEC.Z64_dec·CODEC.JWT_sign·CODEC.JWT_verify·CODEC.JWT_dec - BYTES —
BYTES.u16be·BYTES.u16le·BYTES.i16be·BYTES.i16le·BYTES.u24be·BYTES.u32be·BYTES.u32le·BYTES.i32be·BYTES.text·BYTES.hex·BYTES.make·BYTES.crc8 - Blob —
new Blob·Blob.from·Blob.live·b.toBuffer - SOAP —
SOAP.parse·SOAP.stringify - SYS —
SYS.GetProcessId·SYS.GetComputerName - LOG —
LOG.wrt - RES —
RES.GRP_GET·RES.SUB_GET·RES.grp_str·RES.sub_str
Events, documents and addresses¶
- The sample document
- evt: the event — Inside a chain ·
evt.GetValue·evt.SetValue·evt.MskValue·evt.XorValue·evt.AddValue·evt.AskValue·evt.QueValue·evt.UpdValue·evt.PubValue·evt.AddElement·evt.GetElement·evt.DelElement·evt.ForEach·evt.Log·new XDB_EVT - evt.flg and the EVT.FLG constants
- xdb: the document —
xdb.doc·xdb.elm·xdb.GetValue·xdb.SetValue·xdb.MskValue·xdb.XorValue·xdb.AddValue·xdb.AskValue·xdb.QueValue·xdb.UpdValue·xdb.PubValue·xdb.AddElement·xdb.GetElement·xdb.DelElement·xdb.ForEach·xdb.Log·xdb.normalizePath·xdb.toID·xdb.newID·xdb.newUUID·xdb.lockID·xdb.unlockID·xdb.lock·xdb.unlock·xdb.save·xdb.sync·xdb.dur·xdb.ShellExecute·xdb.exitProgram·xdb.eval·xdb.callFunction·xdb.sta - Element objects —
elm.xdb_elm·elm.xdb_doc·elm.xdb_obj - new XML: the DOM —
new XML - Thread objects —
thr.lock·thr.unlock - Addresses — Steps and predicates · Other documents
- Address functions —
count·sum·min·max·xml·json·stat·api·rpc·xdb·jsn·sql - Special addresses —
#JScript·#PyScript·#shell·#save·#xdb_log·#log_cfg·#dur·#eval - STA: the sta word — The word ·
STA.get_run_eng·STA.get_run_alm·STA.get_run·STA.get_cmd·STA.set_run_eng·STA.set_run_alm·STA.set_run·STA.set_cmd·STA.upd·STA.lnk·STA.onstalnk
Attribute and element functions¶
- How a chain runs — The run bits in
_typ · What a function sees · How a chain ends · Three traps that silence a function - ATR: attribute functions —
ATR.and·ATR.or·ATR.xor·ATR.tog·ATR.set·ATR.rst·ATR.put·ATR.eval·ATR.inc·ATR.dec·ATR.hrec·ATR.vrec·ATR.cnv·ATR.cnvr·ATR.lmt·ATR.rou·ATR.tim·ATR.timstr·ATR.tot·ATR.upd·ATR.nup·ATR.tmr·ATR.map·ATR.mapr·ATR.json - VAL: functions that write val —
VAL.put·VAL.cnv·VAL.cnvr·VAL.set·VAL.rst·VAL.tog·VAL.inc·VAL.dec·VAL.map·VAL.mapr·VAL.upd - ELM: functions on another attribute of the element —
ELM.sta·ELM.put·ELM.and·ELM.or·ELM.xor·ELM.tog·ELM.set·ELM.rst·ELM.inc·ELM.dec·ELM.get·ELM.upd·ELM.tim·ELM.timstr·ELM.tim2int·ELM.eval·ELM.new·ELM.del·ELM.json - XDB: functions on an address —
XDB.get·XDB.put·XDB.msk·XDB.xor·XDB.add·XDB.tog·XDB.upd·XDB.fmt·XDB.eval·XDB.qry·XDB.evt·XDB.sta·XDB.elmnew·XDB.elmsub·XDB.elmdel·XDB.elmmod - EVT: timers —
EVT.cre·EVT.sta·EVT.put·EVT.set·EVT.rst·EVT.flgclrdir - THR: threads —
THR.cre·THR.sta - SCR: scripts —
SCR.prs·SCR.sta·SCR.trace·SCR.prof·SCR.dump·SCR.test
Alarms, conditions and protocol chains¶
- How these functions run
- ALM: alarms —
ALM.onlvl·ALM.onequ·ALM.onand·ALM.onin·ALM.onsta·ALM.onalmlnk·ALM.onstalnk·ALM.put·ALM.msk·ALM.lnk·ALM.tim·ALM.timstr·ALM.devsta·ALM.xdbsta·ALM.consta·ALM.thrsta·ALM.send - IF: conditions —
IF.equ·IF.neq·IF.grt·IF.gre·IF.les·IF.lse·IF.set·IF.rst·IF.chg·IF.and·IF.nand·IF.in·IF.else·IF.end·IF.alone·IF.edge·IF.hub·IF.any - FILTER: holding a change back —
FILTER.setcnt·FILTER.rstcnt·FILTER.rpttim·FILTER.chgtim - CTRL: the on-off controller —
CTRL.inpOOC·CTRL.outOOC - PRO: the protocol chain functions —
PRO.cre·PRO.sta·PRO.open·PRO.pol·PRO.inp·PRO.vrec·PRO.out·PRO.outc·PRO.outf·PRO.put·PRO.set·PRO.rst·PRO.cnv·PRO.cnvr·PRO.map·PRO.mapr·PRO.req·PRO.upd
Sessions and protocol scripts¶
- How a script reaches a connection
- con: a connection —
con.get_ses·con.add_ses·con.lock·con.unlock - con.pro: the connection's protocol
- ses: a session —
ses.user_role·ses.send·ses.receive·ses.connect·ses.disconnect·ses.close·ses.start·ses.stop·ses.wait_start·ses.wait_stop - exc: an exchange —
new CON_EXC·exc.send·exc.exchange·exc.complete·exc.starttls·exc.wr·exc.rd·exc.wrrd·exc.xfer·exc.result·exc.err - CON_BUF: a byte buffer —
new CON_BUF·buf.append·buf.insert·buf.remove·buf.copy·buf.find·buf.split - Protocol hooks — How a hook is written ·
pro_onparse·pro_onaccept·pro_onclose·pro_onpol·pro_onout·pro_onreq·pro_oninp·pro_oncon·pro_onconack·pro_onsub·pro_onunsub·pro_onlogin·pro_oncmd·xdb_pub - req: the HTTP request —
req.getParam·req.getForm·req.getHeader·req.fileServe - res: a server page's answer —
res.write·res.writeText·res.escape·res.header·res.redirect·res.clear - MQTT —
MQTT.publish·MQTT.subscribe·MQTT.unsubscribe·MQTT.sessions - TOPIC —
TOPIC.local·TOPIC.xpath·TOPIC.test - AUTH —
AUTH.hash·AUTH.hash_ok·AUTH.login·AUTH.verify·AUTH.resend·AUTH.token·AUTH.check·AUTH.logoff·AUTH.list·AUTH.unlock - LDAP_CON —
new LDAP_CON·ld.connect·ld.bind·ld.search·ld.modify·ld.disconnect
SQL, history, files and the cluster¶
- SQL: a database —
SQL.attach·SQL.disconnect·SQL.connect·SQL.exec_direct·SQL.prepare·SQL.parameter·SQL.execute·SQL.fetch·SQL.getdata·SQL.getrowqty·SQL.getcolqty·SQL.getcolname·SQL.close·SQL.errortext·SQL.dia·SQL.qry - SQL_CON and SQL_RS: the objects —
SQL_CON·SQL_RS - HIS: records and history —
HIS.cfg·HIS.new·HIS.val·HIS.evt·HIS.evtnew·HIS.alm·HIS.ref·HIS.rec·HIS.put·HIS.row·HIS.uid·HIS.pending·HIS.valstat·HIS.key·HIS.dirty·HIS.flush·HIS.del·HIS.refresh·HIS.stat·HIS.sqltest - File: plain files —
File.open·File.close·File.gets·File.puts·File.read·File.write·File.seek·File.size·File.tell·File.remove·File.rename - LIC: the licence —
LIC.list·LIC.hostid - CLT: the election —
CLT.cfg·CLT.cmd·CLT.info - REP: replication —
REP.cfg·REP.test - RPC: remote calls —
RPC.test - OPC: OPC UA tools —
OPC.test·OPC.cert·OPC.browse·OPC.gen·OPC.call - PY: calling Python —
PY.CallEvt·PY.CallArg·#PyScript
Engine modules¶
- How a module attaches
- FILE —
FILE.list·FILE.exists·FILE.mkdir·FILE.rmdir·FILE.move·FILE.zip - IMG —
IMG.decode·IMG.encode·IMG.gray·IMG.hsv·IMG.crop·IMG.resize·IMG.threshold·IMG.inrange·IMG.stats·IMG.hist·IMG.count·IMG.moments·IMG.absdiff·IMG.blur·IMG.label·IMG.rect·IMG.line·IMG.text·IMG.lut·IMG.grid·IMG.align·IMG.shift·IMG.lines·IMG.channel·IMG.erode·IMG.dilate·IMG.sobel·IMG.match - CAM —
CAM.list - GPIO —
GPIO.chips·GPIO.info·GPIO.pwm·GPIO.sim - I2C and SPI —
I2C.scan·I2C.sim·SPI.sim - NET —
NET.ver
Connection and protocol types¶
- The shape of a connection
- Fields every connection reads
- Fields every protocol reads
- Transports —
CON.tcp·CON.udp·CON.tls·CON.ser·CON.ws·CON.wss·CON.sql·CON.sqlite·CON.ssh·CON.cam·CON.gpio·CON.i2c·CON.spi·CON.raw·CON.hid·#link - Protocols —
PRO.raw·PRO.sql·PRO.modbus·PRO.http·PRO.rest·PRO.soap·PRO.mcp·PRO.telnet·PRO.rfid·PRO.bridge·PRO.mqtt·PRO.clt·PRO.rep·PRO.rpc·PRO.snmp·PRO.opc·PRO.smtp·PRO.ftp·PRO.sftp·PRO.cam·PRO.vision·PRO.gpio·PRO.reg - Not in this repository's bin —
PRO.s7pro