midas.js
This page contains the full API reference for midas.js, the library for calling midas from JavaScript. Its mjsonrpc_xxx functions call mhttpd's JSON-RPC methods, for example to read and write the ODB, and it defines constants such as the TID_xxx ODB data types.
For an introduction to custom pages and JavaScript, see the JavaScript API overview and Custom pages: overview.
For examples, see the "JS" tabs on the feature "programming" pages, such as ODB: programming.
JSON-RPC functions
mjsonrpc_al_reset_alarm
function mjsonrpc_al_reset_alarm(alarms, id)
Reset alarms
RPC method: "al_reset_alarm"
mjsonrpc_al_reset_alarm(["alarm1", "alarm2"]).then(function(rpc) {
var req = rpc.request; // reference to the rpc request
var id = rpc.id; // rpc response id (should be same as req.id)
var result = rpc.result; // rpc response result
... result.status[0]; // status of al_reset_alarm() for 1st alarm
... result.status[1]; // status of al_reset_alarm() for 2nd alarm
}).catch(function(error) {
mjsonrpc_error_alert(error);
});
Parameters:
-
alarms[in] –Array of alarm names (array of strings) -
id[in] –optional request id (see JSON-RPC specs) (object)
Returns:
-
new Promise
Defined in resources/midas.js:518
mjsonrpc_al_trigger_alarm
function mjsonrpc_al_trigger_alarm(name, message, xclass, condition, type, id)
Trigger an alarm
RPC method: "al_trigger_alarm"
mjsonrpc_al_trigger_alarm("Pressure", "Pressure is too high", "Alarm", "", AT_INTERNAL).then(function(rpc) {
var req = rpc.request; // reference to the rpc request
var id = rpc.id; // rpc response id (should be same as req.id)
var status = rpc.result.status; // return status of al_trigger_alarm()
...
}).catch(function(error) {
mjsonrpc_error_alert(error);
});
Parameters:
-
name[in] –Alarm name (string) -
message[in] –Alarm message (string) -
xclass[in] –Alarm class (string) -
condition[in] –Alarm condition (string) -
type[in] –Alarm type, one of AT_xxx (integer) -
id[in] –optional request id (see JSON-RPC specs) (object)
Returns:
-
new Promise
Defined in resources/midas.js:544
mjsonrpc_call
function mjsonrpc_call(method, params, id)
Creates a JSON-RPC request and sends it to mhttpd via HTTP POST. RPC response and error handling is done using the Javascript Promise mechanism:
mjsonrpc_call(method, params, id).then(function(rpc) {
var req = rpc.request; // reference to the rpc request
var id = rpc.id; // rpc response id (should be same as req.id)
var result = rpc.result; // rpc response result
...
}).catch(function(error) {
mjsonrpc_error_alert(error);
});
Parameters:
-
method[in] –name of the RPC method (string) -
params[in] –parameters of the RPC method (object) -
id[in] –optional request id (see JSON-RPC specs) (object)
Returns:
-
new Promise
Defined in resources/midas.js:410
mjsonrpc_cm_exist
function mjsonrpc_cm_exist(name, unique, id)
Check if a MIDAS program is running via cm_exist()
RPC method: "cm_exist"
mjsonrpc_cm_exist("my_program_name").then(function(rpc) {
if (rpc.result.status == 1) {
// Program is running
} else if (rpc.result.status == 103) {
// Program is not running
} else {
// Some unexpected error happened
}
}).catch(function(error) {
mjsonrpc_error_alert(error);
});
Parameters:
-
name[in] –Name of program to check (string) -
unique[in] –bUnique argument to cm_exist() (bool) -
id[in] –optional request id (see JSON-RPC specs) (object)
Returns:
-
new Promise
Defined in resources/midas.js:487
mjsonrpc_cm_msg
function mjsonrpc_cm_msg(message, type, id)
Generate a midas message
RPC method: "cm_msg1"
mjsonrpc_cm_msg("this is a new message").then(function(rpc) {
var req = rpc.request; // reference to the rpc request
var id = rpc.id; // rpc response id (should be same as req.id)
var status = rpc.result.status; // return status of MIDAS cm_msg1()
...
}).catch(function(error) {
mjsonrpc_error_alert(error);
});
Parameters:
-
message[in] –Text of midas message (string) -
type[in] –optional message type, one of MT_xxx. Default is MT_INFO (integer) -
id[in] –optional request id (see JSON-RPC specs) (object)
Returns:
-
new Promise
Defined in resources/midas.js:879
mjsonrpc_db_copy
function mjsonrpc_db_copy(paths, id)
Get a copy of ODB. Symlinks are not resolved, ODB path names are not converted to lower-case.
Instead of this function, please use db_get_values() as a simple way to get easy to use ODB values.
RPC method: "db_copy"
mjsonrpc_db_copy(["/runinfo", "/equipment/foo"]).then(function(rpc) {
var req = rpc.request; // reference to the rpc request
var id = rpc.id; // rpc response id (should be same as req.id)
var result = rpc.result; // rpc response result
... result.status[0]; // status of db_get_value() for /runinfo
... result.status[1]; // status of db_get_value() for /equipment
var runinfo = result.data[0]; // javascript object representing the ODB runinfo structure
var equipment = result.data[1]; // javascript object representing /equipment/foo
}).catch(function(error) {
mjsonrpc_error_alert(error);
});
Parameters:
-
paths[in] –Array of ODB paths (array of strings) -
id[in] –optional request id (see JSON-RPC specs) (object)
Returns:
-
new Promise
Defined in resources/midas.js:577
mjsonrpc_db_create
function mjsonrpc_db_create(paths, id)
Create ODB entries
RPC method: "db_create"
Parameters:
-
paths[in] –Array of ODB entries to create (array of objects) -
id[in] –optional request id (see JSON-RPC specs) (object) -
paths[i].path[in] –ODB path name to create (string) -
paths[i].type[in] –TID_xxx data type (integer) -
paths[i].array_length[in] –Optional array length (default is 1) (integer) -
paths[i].string_length[in] –Optional string length (default is NAME_LENGTH) (integer)
Returns:
-
new Promise
Defined in resources/midas.js:862
mjsonrpc_db_delete
function mjsonrpc_db_delete(paths, id)
Delete ODB entries
RPC method: "db_delete"
mjsonrpc_db_delete(["/test/test1", "/test/test2"]).then(function(rpc) {
var req = rpc.request; // reference to the rpc request
var id = rpc.id; // rpc response id (should be same as req.id)
var result = rpc.result; // rpc response result
... result.status[0]; // status of db_delete() for 1st path
... result.status[1]; // status of db_delete() for 2nd path
}).catch(function(error) {
mjsonrpc_error_alert(error);
});
Parameters:
-
paths[in] –Array of ODB paths (array of strings) -
id[in] –optional request id (see JSON-RPC specs) (object)
Returns:
-
new Promise
Defined in resources/midas.js:780
mjsonrpc_db_get_value
function mjsonrpc_db_get_value(paths, id)
Get values of ODB variables
RPC method: "db_get_value"
mjsonrpc_db_get_value("/runinfo").then(function(rpc) {
var req = rpc.request; // reference to the rpc request
var id = rpc.id; // rpc response id (should be same as req.id)
var result = rpc.result; // rpc response result
... result.status[0]; // status of db_get_value() for /runinfo
... result.status[1]; // status of db_get_value() for /equipment
... result.last_written[0]; // "last written" timestamp for /runinfo
... result.last_written[1]; // "last written" timestamp for /equipment
var runinfo = result.data[0]; // javascript object representing the ODB runinfo structure
... runinfo["run number"]; // access the run number, note: all ODB names should be in lower-case.
... runinfo["run number/last_written"]; // "last_written" timestamp for the run number
... result.data[1].foo.variables.bar; // access /equipment/foo/variables/bar
}).catch(function(error) {
mjsonrpc_error_alert(error);
});
Parameters:
-
paths[in] –Array of ODB paths (array of strings) -
id[in] –optional request id (see JSON-RPC specs) (object)
Returns:
-
new Promise
Defined in resources/midas.js:639
mjsonrpc_db_get_values
function mjsonrpc_db_get_values(paths, id)
Get values of ODB variables
RPC method: "db_get_values"
mjsonrpc_db_get_values(["/runinfo", "/equipment"]).then(function(rpc) {
var req = rpc.request; // reference to the rpc request
var id = rpc.id; // rpc response id (should be same as req.id)
var result = rpc.result; // rpc response result
... result.status[0]; // status of db_get_value() for /runinfo
... result.status[1]; // status of db_get_value() for /equipment
... result.last_written[0]; // "last written" timestamp for /runinfo
... result.last_written[1]; // "last written" timestamp for /equipment
var runinfo = result.data[0]; // javascript object representing the ODB runinfo structure
... runinfo["run number"]; // access the run number, note: all ODB names should be in lower-case.
... runinfo["run number/last_written"]; // "last_written" timestamp for the run number
... result.data[1].foo.variables.bar; // access /equipment/foo/variables/bar
}).catch(function(error) {
mjsonrpc_error_alert(error);
});
Parameters:
-
paths[in] –Array of ODB paths (array of strings) -
id[in] –optional request id (see JSON-RPC specs) (object)
Returns:
-
new Promise
Defined in resources/midas.js:607
mjsonrpc_db_key
function mjsonrpc_db_key(paths, id)
Get ODB keys
RPC method: "db_key"
mjsonrpc_db_key(["/test/intarray1", "/test/dblarray2"]).then(function(rpc) {
var req = rpc.request; // reference to the rpc request
var id = rpc.id; // rpc response id (should be same as req.id)
var result = rpc.result; // rpc response result
... result.status[0]; // status of db_get_key() for 1st path
... result.status[1]; // status of db_get_key() for 2nd path
}).catch(function(error) {
mjsonrpc_error_alert(error);
});
Parameters:
-
paths[in] –Array of ODB paths (array of strings) -
id[in] –optional request id (see JSON-RPC specs) (object)
Returns:
-
new Promise
Defined in resources/midas.js:739
mjsonrpc_db_ls
function mjsonrpc_db_ls(paths, id)
Get list of contents of an ODB subdirectory, similar to odbedit command "ls -l". To get values of ODB variables, use db_get_values().
RPC method: "db_ls"
mjsonrpc_db_ls(["/alarms/alarms", "/equipment"]).then(function(rpc) {
var req = rpc.request; // reference to the rpc request
var id = rpc.id; // rpc response id (should be same as req.id)
var result = rpc.result; // rpc response result
... result.status[0]; // status of db_copy_json_ls() for /alarms/alarms
... result.status[1]; // status of db_copy_json_ls() for /equipment
var alarms = result.data[0]; // javascript object representing the contents of ODB /alarms/alarms
var equipment = result.data[1]; // javascript object representing the contents of ODB /equipment
}).catch(function(error) {
mjsonrpc_error_alert(error);
});
Parameters:
-
paths[in] –Array of ODB paths (array of strings) -
id[in] –optional request id (see JSON-RPC specs) (object)
Returns:
-
new Promise
Defined in resources/midas.js:683
mjsonrpc_db_paste
function mjsonrpc_db_paste(paths, values, id)
Write values info ODB.
RPC method: "db_paste"
mjsonrpc_db_paste(["/runinfo/run number", "/equipment/foo/settings/bar"], [123,456]).then(function(rpc) {
var req = rpc.request; // reference to the rpc request
var id = rpc.id; // rpc response id (should be same as req.id)
var result = rpc.result; // rpc response result
... result.status[0]; // status of db_set_value() for /runinfo
... result.status[1]; // status of db_set_value() for /equipment
}).catch(function(error) {
mjsonrpc_error_alert(error);
});
Parameters:
-
paths[in] –Array of ODB paths (array of strings) -
values[in] –Array of ODB values (array of anything) -
id[in] –optional request id (see JSON-RPC specs) (object)
Returns:
-
new Promise
Defined in resources/midas.js:806
mjsonrpc_db_resize
function mjsonrpc_db_resize(paths, new_lengths, id)
Change size of ODB arrays
RPC method: "db_resize"
mjsonrpc_db_resize(["/test/intarray1", "/test/dblarray2"], [10, 20]).then(function(rpc) {
var req = rpc.request; // reference to the rpc request
var id = rpc.id; // rpc response id (should be same as req.id)
var result = rpc.result; // rpc response result
... result.status[0]; // status of db_set_num_values() for 1st path
... result.status[1]; // status of db_set_num_values() for 2nd path
}).catch(function(error) {
mjsonrpc_error_alert(error);
});
Parameters:
-
paths[in] –Array of ODB paths (array of strings) -
new_lengths -
id[in] –optional request id (see JSON-RPC specs) (object) -
new_sizes[in] –Array of new sizes for each path (array of ints)
Returns:
-
new Promise
Defined in resources/midas.js:711
mjsonrpc_db_set_mode
function mjsonrpc_db_set_mode(paths, modes, id, recursive)
Set access modes for ODB keys RPC method: "db_set_mode"
Parameters:
-
paths[in] –Array of ODB paths (array of strings) -
modes[in] –Array of access mode bitmaps -
id[in] –optional request id -
recursive[in] –Optional flag to include directory contents recursively (default false)
Returns:
-
new Promise
Defined in resources/midas.js:765
mjsonrpc_db_set_value
function mjsonrpc_db_set_value(path, value, id)
Write value info ODB.
RPC method: "db_set_value"
mjsonrpc_set_value("runinfo/run number", 123).then(function(rpc) {
var req = rpc.request; // reference to the rpc request
var id = rpc.id; // rpc response id (should be same as req.id)
var result = rpc.result; // rpc response result
... result.status[0]; // status of db_set_value() for /runinfo
... result.status[1]; // status of db_set_value() for /equipment
}).catch(function(error) {
mjsonrpc_error_alert(error);
});
Parameters:
-
path -
value -
id[in] –optional request id (see JSON-RPC specs) (object) -
paths[in] –Array of ODB paths (array of strings) -
values[in] –Array of ODB values (array of anything)
Returns:
-
new Promise
Defined in resources/midas.js:834
mjsonrpc_debug_alert
function mjsonrpc_debug_alert(rpc)
Debug method to show RPC response
Parameters:
-
rpc[in] –object (object), see mjsonrpc_send_request()
Returns:
-
nothing
Defined in resources/midas.js:293
mjsonrpc_decode_error
function mjsonrpc_decode_error(error)
Convert RPC error status to human-readable string
Parameters:
-
error[in] –rejected promise error object (object)
Returns:
-
decoded error report (string)
Defined in resources/midas.js:317
mjsonrpc_error_alert
function mjsonrpc_error_alert(error, callback, param)
Handle all errors
Parameters:
-
error[in] –rejected promise error object (object) -
callback -
param
Returns:
-
nothing
Defined in resources/midas.js:369
mjsonrpc_make_request
function mjsonrpc_make_request(method, params, id)
Creates a new JSON-RPC request object
Parameters:
-
method[in] –name of the RPC method (string) -
params[in] –parameters of the RPC method (object) -
id[in] –optional request id (see JSON-RPC specs) (object)
Returns:
-
the request object (object)
Defined in resources/midas.js:383
mjsonrpc_send_request
async
async function mjsonrpc_send_request(req)
Send JSON-RPC request(s) via HTTP POST. RPC response and error handling is done using the Javascript Promise mechanism:
var req = mjsonrpc_make_request(method, params, id);
mjsonrpc_send_request(req).then(function(rpc) {
var req = rpc.request; // reference to the rpc request
var id = rpc.id; // rpc response id (should be same as req.id)
var result = rpc.result; // rpc response result
...
}).catch(function(error) {
mjsonrpc_error_alert(error);
});
Parameters:
-
req[in] –request object or an array of request objects (object or array of objects)
Returns:
-
new Promise
Defined in resources/midas.js:153
mjsonrpc_set_url
function mjsonrpc_set_url(url)
Change the URL of JSON-RPC server
Parameters:
-
url[in] –the new URL, i.e. "https://daqserver.example.com:8443" (string)
Returns:
-
nothing
Defined in resources/midas.js:132
mjsonrpc_start_program
function mjsonrpc_start_program(name, id)
Start a MIDAS program
RPC method: "start_program"
mjsonrpc_start_program("logger").then(function(rpc) {
var req = rpc.request; // reference to the rpc request
var id = rpc.id; // rpc response id (should be same as req.id)
var result = rpc.result; // rpc response result
var status = rpc.result.status; // return status of ss_system(), see MIDAS JSON-RPC docs
...
}).catch(function(error) {
mjsonrpc_error_alert(error);
});
Parameters:
-
name[in] –Name of program to start, should be same as the ODB entry "/Programs/name" (string) -
id[in] –optional request id (see JSON-RPC specs) (object)
Returns:
-
new Promise
Defined in resources/midas.js:435
mjsonrpc_stop_program
function mjsonrpc_stop_program(name, id)
Stop a MIDAS program via cm_shutdown()
RPC method: "cm_shutdown"
mjsonrpc_stop_program("logger").then(function(rpc) {
var req = rpc.request; // reference to the rpc request
var id = rpc.id; // rpc response id (should be same as req.id)
var result = rpc.result; // rpc response result
var status = rpc.result.status; // return status of cm_shutdown(), see MIDAS JSON-RPC docs and cm_shutdown() docs
...
}).catch(function(error) {
mjsonrpc_error_alert(error);
});
Parameters:
-
name[in] –Name of program to stop (string) -
id[in] –optional request id (see JSON-RPC specs) (object)
Returns:
-
new Promise
Defined in resources/midas.js:461
modbset
function modbset(path, value)
Simplified function to initiate an ODB write RPC request. This function returns immediately, without waiting for the request to complete. There is no way to check that the write request completed without error. Multiple calls to modbset() may result in out-of-order writes to ODB (later requests may be processed before earlier requests).
Defined in resources/midas.js:927
Other functions and constants
Functions
align8
function align8(x)
Defined in resources/midas.js:941
bkToObj
function bkToObj(array)
Midas banks-to-object: Parses a raw midas even received via the new bm_receive_event call and converts it into an JS object of with following elements and returns it:
e.event_id <-- elements of midas event header
e.trigger_mask <-/
e.serial_number <-/
e.time_stamp <-/
e.time_stamp_date<-/
e.data_size <-/
e.banks_16bit <-- true if we have 16-bit banks
e.banks_32bit <-- true if we have 32-bit banks
e.banks_32bita <-- true if we have 64-bit aligned 32-bit banks
e.bank[] <-- array of banks
.name <-- name of bank
.type <-- bank type, one of TID_xxx
.size <-- bank size in bytes
.hexdata[] <-- array of raw (byte) data
.array[] <-- array of converted data (UINT16, UINT32, UINT32, INT32, FLOAT, DOUBLE)
This function is used by the event_dump.html page and can be used in a custom page for single event displays.
Defined in resources/midas.js:945
db_get_value
function db_get_value(path, callback)
Defined in resources/midas.js:671
loadScript
function loadScript(src)
Defined in resources/midas.js:141
mjsonrpc_get_timezone
function mjsonrpc_get_timezone()
Get timezone offset of server in hours
RPC method: "get_timezone"
mjsonrpc_get_timezone().then(function(rpc) {
var req = rpc.request; // reference to the rpc request
var tz = rpc.result; // server timezone
...
}).catch(function(error) {
mjsonrpc_error_alert(error);
});
Returns:
-
new Promise
Defined in resources/midas.js:907
Variables
AT_EVALUATED
const
const AT_EVALUATED = 3
Defined in resources/midas.js:88
AT_INTERNAL
const
const AT_INTERNAL = 1
Defined in resources/midas.js:86
AT_PERIODIC
const
const AT_PERIODIC = 4
Defined in resources/midas.js:89
AT_PROGRAM
const
const AT_PROGRAM = 2
Defined in resources/midas.js:87
mjsonrpc_default_url_file
var mjsonrpc_default_url_file = "https://localhost:8443/"
Defined in resources/midas.js:120
mjsonrpc_default_url_web
var mjsonrpc_default_url_web = ""
Defined in resources/midas.js:119
mjsonrpc_url
var mjsonrpc_url
Defined in resources/midas.js:122
MODE_ALLOC
const
const MODE_ALLOC = (1<<6)
Defined in resources/midas.js:114
MODE_DELETE
const
const MODE_DELETE = (1<<2)
Defined in resources/midas.js:112
MODE_EXCLUSIVE
const
const MODE_EXCLUSIVE = (1<<3)
Defined in resources/midas.js:113
MODE_READ
const
const MODE_READ = (1<<0)
Defined in resources/midas.js:110
MODE_WATCH
const
const MODE_WATCH = (1<<7)
Defined in resources/midas.js:115
MODE_WRITE
const
const MODE_WRITE = (1<<1)
Defined in resources/midas.js:111
MT_CALL
const
const MT_CALL = (1<<6)
Defined in resources/midas.js:97
MT_DEBUG
const
const MT_DEBUG = (1<<2)
Defined in resources/midas.js:93
MT_ERROR
const
const MT_ERROR = (1<<0)
Defined in resources/midas.js:91
MT_INFO
const
const MT_INFO = (1<<1)
Defined in resources/midas.js:92
MT_LOG
const
const MT_LOG = (1<<4)
Defined in resources/midas.js:95
MT_TALK
const
const MT_TALK = (1<<5)
Defined in resources/midas.js:96
MT_USER
const
const MT_USER = (1<<3)
Defined in resources/midas.js:94
STATE_PAUSED
const
const STATE_PAUSED = 2
MIDAS run paused
Defined in resources/midas.js:100
STATE_RUNNING
const
const STATE_RUNNING = 3
MIDAS run running
Defined in resources/midas.js:101
STATE_STOPPED
const
const STATE_STOPPED = 1
MIDAS run stopped
Defined in resources/midas.js:99
TID_ARRAY
const
const TID_ARRAY = 13
Defined in resources/midas.js:77
TID_BITFIELD
const
const TID_BITFIELD = 11
Defined in resources/midas.js:75
TID_BOOL
const
const TID_BOOL = 8
Defined in resources/midas.js:70
TID_BYTE
const
const TID_BYTE = 1
Defined in resources/midas.js:57
TID_CHAR
const
const TID_CHAR = 3
Defined in resources/midas.js:61
TID_DOUBLE
const
const TID_DOUBLE = 10
Defined in resources/midas.js:73
TID_DWORD
const
const TID_DWORD = 6
Defined in resources/midas.js:66
TID_FLOAT
const
const TID_FLOAT = 9
Defined in resources/midas.js:71
TID_FLOAT32
const
const TID_FLOAT32 = 9
Defined in resources/midas.js:72
TID_FLOAT64
const
const TID_FLOAT64 = 10
Defined in resources/midas.js:74
TID_INT
const
const TID_INT = 7
Defined in resources/midas.js:68
TID_INT16
const
const TID_INT16 = 5
Defined in resources/midas.js:65
TID_INT32
const
const TID_INT32 = 7
Defined in resources/midas.js:69
TID_INT64
const
const TID_INT64 = 17
Defined in resources/midas.js:81
TID_INT8
const
const TID_INT8 = 2
Defined in resources/midas.js:60
TID_KEY
const
const TID_KEY = 15
Defined in resources/midas.js:79
TID_LAST
const
const TID_LAST = 19
Defined in resources/midas.js:84
TID_LINK
const
const TID_LINK = 16
Defined in resources/midas.js:80
tid_name
const
const tid_name = […]
Defined in resources/midas.js:13
TID_QWORD
const
const TID_QWORD = 18
Defined in resources/midas.js:83
TID_SBYTE
const
const TID_SBYTE = 2
Defined in resources/midas.js:59
TID_SHORT
const
const TID_SHORT = 5
Defined in resources/midas.js:64
tid_size
const
const tid_size = […]
Defined in resources/midas.js:35
TID_STRING
const
const TID_STRING = 12
Defined in resources/midas.js:76
TID_STRUCT
const
const TID_STRUCT = 14
Defined in resources/midas.js:78
TID_UINT16
const
const TID_UINT16 = 4
Defined in resources/midas.js:63
TID_UINT32
const
const TID_UINT32 = 6
Defined in resources/midas.js:67
TID_UINT64
const
const TID_UINT64 = 18
Defined in resources/midas.js:82
TID_UINT8
const
const TID_UINT8 = 1
Defined in resources/midas.js:58
TID_WORD
const
const TID_WORD = 4
Defined in resources/midas.js:62
TR_DEFERRED
const
const TR_DEFERRED = 4096
Defined in resources/midas.js:108
TR_PAUSE
const
const TR_PAUSE = 4
Pause transition
Defined in resources/midas.js:105
TR_RESUME
const
const TR_RESUME = 8
Resume transition
Defined in resources/midas.js:106
TR_START
const
const TR_START = 1
Start transition
Defined in resources/midas.js:103
TR_STARTABORT
const
const TR_STARTABORT = 16
Start aborted transition
Defined in resources/midas.js:107
TR_STOP
const
const TR_STOP = 2
Stop transition
Defined in resources/midas.js:104