V-RTU2000 - VR-2400 VeestaScript Programming Language Manual V1-0-En
V-RTU2000 - VR-2400 VeestaScript Programming Language Manual V1-0-En
Technical Information
VeestaScript
Programming Manual
NOTICE
The information in this document is subject to change without notice and should not
be construed as a commitment by VEESTA WORLD Co. Veesta World Co assumes
no responsibility for any errors that may appear in this document.
In no event shall Veesta World Co be liable for direct, indirect, special, incidental or
consequential damages of any nature or kind arising from the use of this document,
nor shall Veesta World Co be liable for incidental or consequential damages arising
from use of any software or hardware described in this document.
This document and parts thereof must not be reproduced or copied without
Veesta World Co’s written permission and the contents thereof must not be imparted
to a third party nor be used for any unauthorized purpose.
V-RTU2000 - Series VR-2400 Document History
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
DOCUMENT HISTORY
Page 3 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Table of Content
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
TABLE OF CONTENT
Page 4 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Table of Content
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Chapter 6 - Expressions................................................................... 35
6.1 Introduction..........................................................................35
6.2 Operators ............................................................................35
6.3 Assignment Operators.........................................................36
6.4 Arithmetic Operators ...........................................................37
6.5 Comparison Operators ........................................................38
6.6 Ternary Operator.................................................................39
6.7 Bitwise Operators ................................................................39
6.8 Logical Operators ................................................................40
6.8.1 Short-circuit evaluation ............................................40
6.9 String Operators ..................................................................41
6.10 Member Access Operators..................................................41
6.11 Dot notation .........................................................................42
6.12 Bracket notation ..................................................................43
6.13 JSON Array/Object Operators .............................................44
6.14 Comma Operator.................................................................45
6.15 Operators Precedence ........................................................46
Chapter 7 - Statements .................................................................... 47
7.1 Introduction..........................................................................47
7.1.1 Block Statements .....................................................47
7.2 Conditionals.........................................................................48
7.2.1 if..else..else if..elseif.................................................48
7.3 While Statement ..................................................................49
7.4 For Statement......................................................................50
7.5 Break/Continue statements .................................................51
7.6 Foreach statement ..............................................................52
7.7 Switch statement .................................................................53
7.8 Return statement.................................................................54
7.9 Language Constructs ..........................................................55
Chapter 8 - Functions....................................................................... 56
8.1 Introduction..........................................................................56
8.2 Function Arguments ............................................................58
8.3 Returning values .................................................................58
8.4 Anonymous Function...........................................................59
8.5 Function overloading ...........................................................60
Chapter 9 - Built-In Functions ......................................................... 61
9.1 Introduction..........................................................................61
9.2 Variable Handling Functions................................................62
9.2.1 is_bool .....................................................................62
9.2.2 is_float .....................................................................62
9.2.3 is_real ......................................................................62
9.2.4 is_double .................................................................62
Page 5 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Table of Content
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Page 6 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Table of Content
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Page 7 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Table of Content
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Page 8 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Table of Content
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
TABLE OF FIGURES
Page 9 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Table of Content
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
INDEX OF TABELS
Page 10 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 1 - Introduction
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Chapter 1 - Introduction
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 1 - Introduction
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
the offer is the evaluation and Management of the risk. This issue is
getting a major relevance in the changing environment in which new
technologies have to be applied, particularly when profitability is a
major concern.
1.3 Copyrights
Page 12 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 2 - VeestaScritp Preface
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
2.1 Overview
"VeestaScript" is an scripting language also called extension
language designed to support general procedural programming with
data description facilities. "VeestaScript" is a dynamically typed
programming language based on JSON and implemented as a
library.
1- Basic Syntax
Lexical conventions
Instruction separation
Comments
2- Types
Introduction
Boolean
Integers
Real numbers
NULL
Strings
JSON Arrays
JSON Objects
Resource
Type casting
Page 13 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 2 - VeestaScritp Preface
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
3- Variables
Basics
Variable scope
Predefined variables
4- Expressions
Introduction
Operators
Operators precedence
5- Statements
Introduction
Conditionals
while
for
break/continue
foreach
switch
return
include
import
Language constructs
6- Functions
Introduction
Function arguments
Returning values
Anonymous functions
Function overloading
7- Built-in Functions
Introduction
Variable Handling Functions
Mathematical Functions
String Handling Functions
Time Functions
Cryptography Functions
Real-time Database Functions
Page 14 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 3 - Basic Syntax
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Example:
print 5+5;
continue;
rand();
Page 15 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 3 - Basic Syntax
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
3.3 Comments
"VeestaScript" supports C/C++ (//, /* */) style comments as well Unix
shell comments (#).
The "one-line" comment styles only comment to the end of the line.
Example:
Example:
/*
*/
Page 16 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 4 - Types
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Chapter 4 - Types
4.1 Overview
"VeestaScript" is a dynamically typed language.
This means that
variables do not have types; only values do. There are no type
definitions in the language. All values carry their own type.
Being based on JSON, all types are the one introduced by JSON
with the addition of the type resource which is used to pass data
(Typically malloc()ed pointers) between the host application and the
underlying "VeestaScript" virtual machine.
The following are the basic types: integer, real, string, boolean,
JSON objects, JSON arrays and the resource type.
Tip: To check the type and value of an expression, use the dump()
function.
To get a human-readable representation of a type for debugging, use
the gettype() function
4.2 Boolean
This is the simplest type. A Boolean expresses a truth value. It can
be either TRUE or FALSE.
To specify a boolean literal, use the keywords TRUE or FALSE. Both
are case-insensitive.
Example:
dump(TRUE); //bool(true)
dump(True); //bool(true)
dump(FALSE); //bool(false)
dump(False); //bool(false)
Page 17 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 4 - Types
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Any other value is considered true even negative numbers and the
resource type.
Example:
dump((bool)[10,11,13]); // bool(true)
dump((bool){}); // bool(false)
4.3 Integers
Integers can be specified in decimal (base 10), hexadecimal (base
16), octal (base 8) or binary (base 2) notation, optionally preceded by
a sign (- or +).
Page 18 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 4 - Types
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Example:
Using BNF:
decimal : [1-9][0-9]*
|0
hexadecimal : 0[xX][0-9a-fA-F]+
octal : 0[0-7]+
binary : 0b[01]+
integer : [+-]?decimal
| [+-]?hexadecimal
| [+-]?octal
| [+-]?binary
Page 19 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 4 - Types
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Using BNF:
LNUM [0-9]+
DNUM ([0-9]*[\.]{LNUM}) | ({LNUM}[\.][0-9]*)
EXPONENT_DNUM [+-]?(({LNUM} | {DNUM}) [eE][+-]? {LNUM})
4.5 NULL
Null is the type of the value NULL, whose main property is to be
different from any other value. It usually represents the absence of a
useful value. Both NULL and false make a condition false.
A variable is considered to be NULL if:
it has been assigned the constant NULL.
it has not been declared yet.
There is only one value of type NULL, and that is the case sensitive
keyword NULL or null.
Example:
$temp = NULL;
dump($temp); //null
Page 20 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 4 - Types
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
4.6 String
A string is a stream of bytes (i.e. UTF-8 or even binary stream).
Note: It is no problem for a string to become very large.
"VeestaScript" imposes no boundary on the size of a string; the
only limit is the available memory of the computer on which
"VeestaScript" is running.
A string literal can be specified in three different ways:
Single quoted
nowdoc
double quoted
Example:
$var = 'test';
4.6.2 Nowdoc
A nowdoc have the same semantic as a single quoted string except
that is used to hold big chunk of text such as unparsed
"VeestaScript" code or even binary chunks. The construct is ideal
for embedding large blocks of text without the need for escaping. It
Page 21 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 4 - Types
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
$var = 'test';
$str = <<<EOD
Example of string
spanning multiple lines
using nowdoc syntax.
print $str;
Page 22 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 4 - Types
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Sequence Description
\" Double quote
\' Single quote
\[0-7]{1,3} the sequence of characters matching the regular expression
is a character in octal notation.
\x[0-9A-Fa-f]{1,2} the sequence of characters matching the regular expression
is a character in hexadecimal notation.
\0 NUL byte.
Example:
$name = 'Hodjat';
print "Mr $person.name is $person.age years old\n"; //Mr Wolf is 27 years old
Page 23 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 4 - Types
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
[ [expr,expr] ];
Example:
/*
Declare a JSON array with two random numbers between 0 and 1024 inclusive
using the built-in rand() function.
*/
print $numbers,VS_EOL,$rand;
$array_name[expr];
Example:
print VS_EOL;
print VS_EOL;
Page 24 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 4 - Types
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Example:
$user = {
login : 'htp123',
age : 55
};
username = htp123
age = 55
Page 25 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 4 - Types
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
$person = {
firstName : "Hodjat",
lastName: "Toraby",
age: 55,
addr: {
city: "Tehran",
state : "TH",
postalCode : 1915673873
print VS_EOL;
4.9 Resource
The type resource or userdata in the "VeestaScript" jargon is a
special type which is provided to allow arbitrary C data to be stored in
"VeestaScript" variables and returned from foreign function.
The built-in standard library rely heavily on this type and is used for
example by the implementation of the IO stream functions such as
fopen(), fread(), fwrite() and so forth.
This type corresponds to a block of raw memory and has no pre-
defined operations in "VeestaScript", except assignment and identity
test.
Page 26 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 4 - Types
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
// To check the type and value of an expression, use the dump() function
$test = "256";
dump($test); //string(3,'256')
$test += 10;
dump($test); //int(266)
dump($test); //int(291)
$test *= 2.5;
dump($test); //float(3.59679...)
Page 27 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 5 - Variables
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Chapter 5 - Variables
5.1 Overview
Variables are places that store values. There are three kinds of
variables in "VeestaScript": global variables, static variables and
local variables.
Variable names (UTF-8 Stream) follow the same rules as other labels
in "VeestaScript". Refer to the lexical convention section for
additional information.
Example:
$var = 'Foo';
$Var = 'Bar';
/* Test */
dump($var,$Var);
$foo = __TIME__;
import 'driver.script';
Page 28 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 5 - Variables
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
function test()
This script will not produce any output because the print statement
refers to a local version of the $foo variable which is not declared and
assigned a value in this scope. You may notice that this is a little bit
different from the C language in that global variables in C are
automatically available to functions unless specifically overridden by
a local definition.
function test()
{
uplink $foo, $bar; //Make $foo and $bar available in the current scope
print $foo,' ',$bar; //Output the old value of $foo and $bar.
$foo = 1023;
print VS_EOL;
}
test();
/* Global scope */
Page 29 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 5 - Variables
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
That is, with the uplink statement, all references to either variable
will refer to the global version. There is no limit to the number of
global variables that can be manipulated by a function.
function test()
static $num = rand() & 1023; //Random integer between 0 and 1024 inclusive
print $num++;
print VS_EOL;
test(); //59
test(); //60
test(); //61
test(); //62
Static variables also provide one way to deal with recursive functions.
A recursive function is one which calls itself. Care must be taken
when writing a recursive function because it is possible to make it
recurse indefinitely. You must make sure you have an adequate way
Page 30 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 5 - Variables
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
function test()
static $count = 0;
test();
Page 31 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 5 - Variables
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Page 32 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 5 - Variables
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Predefined Variable
Purpose
Name
Page 33 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 5 - Variables
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Predefined Variable
Purpose
Name
The type definition for set the point state to desired states
PNT_SET_STATE
used in SetPnt function
The type definition for clear desired state on the point used in
PNT_CLEAR_STATE
SetPnt function
Represent the point is in Initialize state, it is return of GetPnt
PNT_STATE_INI
function in mode of PNT_GET_STATE
Represent the point is in Online state, it is return of GetPnt
PNT_STATE_ONLINE
function in mode of PNT_GET_STATE
Represent the point has communication or wire lost state, it is
PNT_STATE_COMERR
return of GetPnt function in mode of PNT_GET_STATE
Represent the point is in Chatter filter block state, it is return
PNT_STATE_CHATTER
of GetPnt function in mode of PNT_GET_STATE
Represent the point value is overflowed state, it is return of
PNT_STATE_OVERFL
GetPnt function in mode of PNT_GET_STATE
Represent the current point value has been entered manually
PNT_STATE_MANUAL state, it is return of GetPnt function in mode of
PNT_GET_STATE
Represent the point is in Invalid state, it is return of GetPnt
PNT_STATE_INVALID
function in mode of PNT_GET_STATE
Represent the point value is underflow state, it is return of
PNT_STATE_UNDERFL
GetPnt function in mode of PNT_GET_STATE
Page 34 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 6 - Expressions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Chapter 6 - Expressions
6.1 Introduction
An expression in a programming language is a combination of
explicit values, constants, variables, operators, and functions that are
interpreted according to the particular rules of precedence and of
association for a particular programming language, which computes
and then produces (returns, in a state full environment) another
value. This process, like for mathematical expressions, is called
evaluation. The value can be of various types, such as numerical,
string, and logical. (src: Wikipedia)
6.2 Operators
An operator is something that takes one or more values (or
expressions, in programming jargon) and yields another value (so
that the construction itself becomes an expression).
Operators can be grouped according to the number of values they
take. Unary operators take only one value, for example ! (the logical
not operator) or ++ (the increment operator). Binary operators take
two values, such as the familiar arithmetical operators + (plus) and -
(minus), and the majority of "VeestaScript" operators fall into this
category. Finally, there is a single ternary operator, ? , which takes
three values; this is usually referred to simply as "the ternary
Page 35 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 6 - Expressions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Page 36 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 6 - Expressions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Note that the assignment copies the original variable to the new one
(assignment by value), so changes to one will not affect the other.
An exception to the usual assignment by value occurs when dealing
with JSON arrays and objects which are assigned by reference (for
performance reason). That is, when assigning an already created
instance of a JSON array or object to a variable, the new variable will
access the same instance as the array or object that was assigned.
In other words, arrays and objects are shared between variables.
This behavior is the same when passing arrays or objects to a
function.
Page 37 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 6 - Expressions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
$x = 6, $y = 10
Page 38 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 6 - Expressions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Example:
$rank = 6;
Page 39 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 6 - Expressions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Example:
Page 40 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 6 - Expressions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Example:
Page 41 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 6 - Expressions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
$my_object = {
};
print VS_EOL;
$person = {
firstName : "Hodjat",
lastName: "Toraby",
age: 55,
addr: {
city: "Tehran",
state : "TH",
postalCode : 1915673873
print VS_EOL;
Page 42 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 6 - Expressions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
$array_name[expr];
Example:
print VS_EOL;
print VS_EOL;
$my_info = {};
$my_info['age'] = 55;
Page 43 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 6 - Expressions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Example:
$a = {
a : "apple",
b : "banana"
};
$b = {
a : "pear",
b : "strawberry",
c : "cherry"
};
$c = $a + $b; // Union of $a and $b
print "Union of \$a and \$b: \n";
print $c;
Page 44 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 6 - Expressions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Example:
$a = 25 , $b = $a << 1 , test();
/* Output the value of $a and $b */
function test(){
uplink $a,$b;
print "\$a = $a \$b= $b\n"; /* You should see: $a = 25 $b = 50*/
}
Page 45 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 6 - Expressions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Page 46 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 7 - Statements
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Chapter 7 - Statements
7.1 Introduction
A statement is the smallest standalone element of an imperative
programming language. A program written in such a language is
formed by a sequence of one or more statements. (src: Wikipedia)
Any expression is also a statement. See Expressions and Operators
for additional information.
Use the semicolon ; character to separate statements in
"VeestaScript" code.
7.1.1 Block Statements
A block statement is used to group statements. The block is delimited
by a pair of curly brackets:
stmt_1;
stmt_2;
...
stmt_n;
$x = 0;
print "$x\n";
Page 47 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 7 - Statements
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
7.2 Conditionals
A conditional statement is a set of commands that executes if a
specified condition is true. "VeestaScript" supports two conditional
statements: if...else and switch.
statement_1
[else if (condition_2)
statement_2]
...
[elseif (condition_n_1)
statement_n_1]
[else
statement_n]
if (condition) {
stmts_1
}else if (condition2){
stmts_2
}else{
stmts_3
Page 48 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 7 - Statements
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Example:
$x = 10, $y = 20;
if( $x > $y ){
}else{
while (expr)
statement
Example:
$x = 0;
print "$x\n";
Page 49 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 7 - Statements
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
/* example 1 */
for ($i = 1; $i <= 10; $i++) {
print $i;
}
/* example 2 */
for ($i = 1; ; $i++) {
if ($i > 10) {
break;
}
print $i;
}
/* example 3 */
$i = 1;
for (; ; ) {
if ($i > 10) {
break;
}
print $i;
$i++;
}
/* example 4 */
for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i, $i++);
Page 50 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 7 - Statements
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Page 51 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 7 - Statements
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
The first form loops over the target array or object given by
array_or_object_expr. On each loop, the value of the current element
is assigned to $value and the internal array/object cursor is advanced
by one (so on the next loop, you'll be looking at the next element).
The second form does the same thing, except that the current
element's key will be assigned to the variable $key on each loop.
Note: When foreach first starts executing, the internal array/object
pointer is automatically reset to the first element of the array.
Example:
/* Iterate over a JSON object */
$person = {
firstName : "Hodjat",
lastName: "Toraby",
age: 25,
addr: {
"streetAddress": "42 Golfam St. Nelson Mandela St.",
city: "Tehran",
state : "TH",
postalCode : 1915673873
}
}; //Don't forget the semi-colon here
Example2:
Page 52 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 7 - Statements
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
switch(expr){
case cond1:
stmt1;
[break;]
case cond2:
stmt2;
[break;]
[default:
def_stmt;
[break;]
The program first looks for a case clause with a label matching the
value of expression (Any complex expression including function calls)
and then transfers control to that clause, executing the associated
statements. If no matching label is found, the program looks for the
optional default clause, and if found, transfers control to that clause,
executing the associated statements. If no default clause is found,
the program continues execution at the statement following the end
of switch. By convention, the default clause is the last clause, but it
does not need to be so.
Page 53 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 7 - Statements
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Example:
$i = 'banana';
switch ($i) {
case "apple":
break;
case "banana":
break;
case "cake":
break;
Page 54 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 7 - Statements
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
die
die [expr];
Example:
die;
Page 55 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 8 - Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Chapter 8 - Functions
8.1 Introduction
Functions are one of the fundamental building blocks in
"VeestaScript". A function is a "VeestaScript" procedure a set of
statements that performs a task or calculates a value. To use a
function, you must define it somewhere in the scope from which you
wish to call it.
A function definition (also called a function declaration) consists
of the function keyword, followed by
The name of the function.
A list of arguments to the function with optional type enclosed in
parentheses and separated by commas.
The "VeestaScript" statements that define the function, enclosed
in curly braces, { }.
For example, the following code defines a simple function named
square:
function square($number)
The same function could be declared using the type hinting feature
as follows:
Page 56 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 8 - Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
return 1;
else
Example
Page 57 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 8 - Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Example:
Page 58 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 8 - Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Example:
$greet = function($name)
};
function main($callback)
if( !is_callable($callback) )
else
$callback();
Page 59 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 8 - Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Example:
// volume of a cube
function volume(int $s)
{
return $s*$s*$s;
}
// volume of a cylinder
function volume(float $r,int $h)
{
return 3.14*$r*$r*$h;
}
// volume of a cuboid
function volume(float $l,int $b,int $h)
{
return $l*$b*$h;
}
/* Test the overloading mechanism */
print volume(10)..VS_EOL; /* 1000 */
print volume(2.5,8)..VS_EOL; /* 157 */
print volume(100,75,15); /* 112500 */
Page 60 of 96
All rights reserved. Passing on and copying of this document, use and communication of its contents not permitted without written authorization.
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.1 Introduction
Page 61 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Parameters:
$var : The variable being evaluated
Return:
TRUE if var is a Boolean. FALSE otherwise
9.2.2 is_float
bool is_float($var)
Finds out whether a variable is a float.
Parameters:
$var : The variable being evaluated
Return:
TRUE if var is a float. FALSE otherwise
9.2.3 is_real
bool is_real($var)
Finds out whether a variable is a real.
Parameters:
$var : The variable being evaluated
Return:
TRUE if var is a real. FALSE otherwise
9.2.4 is_double
bool is_double($var)
Finds out whether a variable is a double.
Parameters:
$var : The variable being evaluated
Return:
TRUE if var is a double. FALSE otherwise
Page 62 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.2.5 is_int
bool is_int($var)
Finds out whether a variable is an integer.
Parameters:
$var : The variable being evaluated
Return:
TRUE if var is an integer. FALSE otherwise
9.2.6 is_integer
bool is_integer($var)
Finds out whether a variable is an integer.
Parameters:
$var : The variable being evaluated
Return:
TRUE if var is an integer. FALSE otherwise
9.2.7 is_long
bool is_long($var)
Finds out whether a variable is a long inetger.
Parameters:
$var : The variable being evaluated
Return:
TRUE if var is a long integer. FALSE otherwise
9.2.8 is_string
bool is_string($var)
Finds out whether a variable is s string.
Parameters:
$var : The variable being evaluated
Return:
TRUE if var is a string. FALSE otherwise
Page 63 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.2.9 is_null
bool is_null($var)
Finds out whether a variable is NULL.
Parameters:
$var : The variable being evaluated
Return:
TRUE if var is NULL. FALSE otherwise
9.2.10 is_numerci
bool is_numeric($var)
Finds out whether a variable has a numeric value.
Parameters:
$var : The variable being evaluated
Return:
TRUE if var is numeric. FALSE otherwise
9.2.11 is_scalar
bool is_scalar($var)
Finds out whether a variable is a scalar.
Parameters:
$var : The variable being evaluated
Return:
TRUE if var is a scalar. FALSE otherwise
9.2.12 is_array
bool is_array($var)
Finds out whether a variable is an array.
Parameters:
$var : The variable being evaluated
Return:
TRUE if var is an array. FALSE otherwise
Page 64 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.2.13 is_object
bool is_object($var)
Finds out whether a variable is an object.
Parameters:
$var : The variable being evaluated
Return:
TRUE if var is an object. FALSE otherwise
9.2.14 floatval
float floatval($var)
Get float value of variable.
Parameters:
$var : The variable being processed
Return:
The float value of a variable
9.2.15 intval
int intval($var)
Get integer value of variable.
Parameters:
$var : The variable being processed
Return:
The int value of a variable
9.2.16 strval
string strval($var)
Get the string representation of a variable.
Parameters:
$var : The variable being processed
Return:
The string value of a variable
Page 65 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.2.17 empty
bool empty($var)
Determine whether a variable is empty.
Parameters:
$var : The variable being checked.
Return:
TRUE if var has a non-empty and non-zero value
FALSE otherwise
Page 66 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Parameters:
$arg : The number to process.
Return:
The absolute value of number
9.3.2 sqrt
float sqrt(float $arg)
Square root of the given number
Parameters:
$arg: The number to process
Return:
The square root of arg or the special value Nan of failure
9.3.3 exp
float exp(float $arg)
Calculates the exponent of e
Parameters:
$arg: The number to process
Return:
'e' raised to the power of arg
9.3.4 floor
float floor(float $arg)
Round fractions down
Parameters:
$arg: The number to process
Return:
Returns the next lowest integer value by rounding down value if
necessary
Page 67 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.3.5 cos
float cos(float $arg)
Cosine function
Parameters:
$arg: The number to process
Return:
The cosine of arg
9.3.6 sin
float sin(float $arg)
Sine function
Parameters:
$arg: The number to process
Return:
The sine of arg
9.3.7 acos
float acos(float $arg)
Arc cosine function
Parameters:
$arg: The number to process
Return:
The arc cosine of arg
9.3.8 asin
float asin(float $arg)
Arc sine function
Parameters:
$arg: The number to process
Return:
The arc sine of arg
Page 68 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.3.9 cosh
float cosh(float $arg)
Hyperbolic cosine function
Parameters:
$arg: The number to process
Return:
The hyperbolic cosine of arg
9.3.10 sinh
float sinh(float $arg)
Hyperbolic sine function
Parameters:
$arg: The number to process
Return:
The hyperbolic sine of arg
9.3.11 ceil
float ceil(float $arg)
Round fractions up function
Parameters:
$arg: The number to process
Return:
The next highest integer value by rounding up value if necessary
9.3.12 tan
float tan(float $arg)
Tangent function
Parameters:
$arg: The number to process
Return:
The tangent of arg
Page 69 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.3.13 tanh
float tanh(float $arg)
Hyperbolic tangent function
Parameters:
$arg: The number to process
Return:
The Hyperbolic tangent of arg
9.3.14 atan
float atan(float $arg)
Arc tangent function
Parameters:
$arg: The number to process
Return:
The arc tangent of arg
9.3.15 atan2
float atan2(float $y, float $x)
Arc tangent of two variable function
Parameters:
$y: Dividend parameter
$x: Divisor parameter
Return:
The arc tangent of y/x in radian
9.3.16 log
float log(float $arg, [int/float $base])
Natural logarithm Function
Parameters:
$arg: The number to process
$base: The optional logarithmic base to use (only base-10 is
supported)
Return:
The logarithm of arg to base, if given, or the natural logarithm
Note: only Natural log and base-10 log are supported
Page 70 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.3.17 log10
float log10(float $arg)
Base-10 logarithm function
Parameters:
$arg: The number to process
Return:
The Base-10 logarithm of the given number
9.3.18 pow
int/float pow(int/float $base, int/float $exp)
Exponential expression
Parameters:
$base: The base to use
$exp: The exponent
Return:
base raised to the power of exp
If the result can be represented as integer it will be returned as
type integer, else it will be returned as type float
9.3.19 pi
float pi ()
Returns an approximation of pi
Parameters: none
Return:
The value of pi as float, You can use the M_PI constant which
yields identical results to pi()
9.3.20 fmod
float fmod(float $x, float $y)
Returns the floating point remainder (modulo) of the division of
the arguments
Parameters:
$x: The dividend
$y: The divisor
Return:
The floating point remainder of x/y
Page 71 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.3.21 hypot
float hypot(float $x, float $y)
Calculate the length of the hypotenuse of a right-angle triangle
Parameters:
$x: Length of first side
$y: Length of first side
Return:
Calculated length of the hypotenuse
9.3.22 round
float round(float $val [, int $precision = 0 [, int $mode =
VS_ROUND_HALF_UP ]])
Exponential expression
Parameters:
$val: The value to round
$precision: The optional number of decimal digits to round to
$mode: One of VS_ROUND_HALF_UP,
VS_ROUND_HALF_DOWN
Return:
The rounded value
9.3.23 dechex
string dechex(int $number)
Decimal to hexadecimal string view
Parameters:
$number: Decimal value to convert
Return:
Hexadecimal string representation of number
9.3.24 decoct
string decoct(int $number)
Decimal to Octal string view
Parameters:
$number: Decimal value to convert
Return:
Octal string representation of number
Page 72 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.3.25 decbin
string decbin(int $number)
Decimal to Binary string view
Parameters:
$number: Decimal value to convert
Return:
Binary string representation of number
9.3.26 hexdec
int64 hexdec(string $hex_string)
Hexadecimal string view to decimal
Parameters:
$hex_string: The hexadecimal string to convert
Return:
The decimal representation of hex_string
9.3.27 bindec
int64 hexdec(string $bin_string)
Binary string view to decimal
Parameters:
$bin_string: The binary string to convert
Return:
Returns the decimal equivalent of the binary number represented
by the binary_string argument
9.3.28 octdec
int64 octdec(string $oct_string)
Octal string view to decimal
Parameters:
$oct_string: The octal string to convert
Return:
Returns the decimal equivalent of the octal number represented
by the octal_string argument
Page 73 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.3.29 base_convert
string base_convert(string $number,
int $frommbase, int $tobase)
Convert a number between arbitrary bases
Parameters:
$number: The number string to convert
$frombase: The base number is in
$tobase: The base to convert number to
Return:
Number converted to base tobase
Page 74 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Parameters:
$string: The string being measured for length
Return:
The length of the given string
9.4.2 strcmp
int strcmp(string $str1, string $str2)
Perform a binary safe string comparison
Parameters:
$str1: The first string
$str2: The second string
Return:
Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2,
and 0 if they are equal
9.4.3 strncmp
int strncmp(string $str1, string $str2, int $n)
Perform a binary safe string comparison of the first n characters
Parameters:
$str1: The first string
$str2: The second string
$n: The length of strings to be used in the comparison
Return:
Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2,
and 0 if they are equal
Page 75 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.4.4 strcasecmp
int strcasecmp(string $str1, string $str2)
Perform a binary safe case-insensitive string comparison
Parameters:
$str1: The first string
$str2: The second string
Return:
Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2,
and 0 if they are equal
9.4.5 strncasecmp
int strncasecmp(string $str1, string $str2, int $n)
Perform a binary safe case-insensitive string comparison of the
first n characters
Parameters:
$str1: The first string
$str2: The second string
$n: The length of strings to be used in the comparison
Return:
Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2,
and 0 if they are equal
9.4.6 trim
string trim(string $str [, string $charlist ])
Strip whitespace (or other characters) from the beginning and
end of a string
Parameters:
$str: The string that will be trimmed
$charlist: Optionally, the stripped characters can also be
specified using the charlist parameter. Simply list all
characters that you want to be stripped.
With .. you can specify a range of characters
Return:
The processed string
Page 76 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.4.7 rtrim
string rtrim(string $str [, string $charlist ])
Strip whitespace (or other characters) from the end of a string
Parameters:
$str: The string that will be trimmed
$charlist: Optionally, the stripped characters can also be
specified using the charlist parameter. Simply list all
characters that you want to be stripped.
With .. you can specify a range of characters
Return:
The processed string
9.4.8 ltrim
string ltrim(string $str [, string $charlist ])
Strip whitespace (or other characters) from the beginning and
end of a string
Parameters:
$str: The string that will be trimmed
$charlist: Optionally, the stripped characters can also be
specified using the charlist parameter. Simply list all
characters that you want to be stripped.
With .. you can specify a range of characters
Return:
The processed string
9.4.9 strtolower
string strtolower(string $str)
Make a string lowercase
Parameters:
$str: The input string
Return:
The lowercased string
Page 77 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.4.10 strtoupper
string strtoupper(string $str)
Make a string uppercase
Parameters:
$str: The input string
Return:
The uppercased string
9.4.11 ord
int ord(string $string)
Returns the ASCII value of the first character of string
Parameters:
$str: The input string
Return:
The ASCII value as an integer
9.4.12 chr
int chr(int $ascii)
Returns a one-character string containing the character specified
by ascii
Parameters:
$ascii: The ASCII code
Return:
The specified character
9.4.13 bin2hex
string bin2hex (string $str)
Convert binary data into hexadecimal representation
Parameters:
$str: The input string
Return:
Returns the hexadecimal representation of the given string
Page 78 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.4.14 strstr
string strstr(string $haystack, string $needle
[, bool $before_needle = false ] )
Find the first occurrence of a string
Parameters:
$haystack: The input string
$needle: Search pattern (must be a string)
$before_needle: If TRUE, strstr() returns the part of the
haystack before the first occurrence of the needle
(excluding the needle)
Return:
Returns the portion of string, or FALSE if needle is not found
9.4.15 stristr
string stristr(string $haystack, string $needle
[, bool $before_needle = false ] )
Find the first occurrence of a Case-insensitive string
Parameters:
$haystack: The input string
$needle: Search pattern (must be a string)
$before_needle: If TRUE, strstr() returns the part of the
haystack before the first occurrence of the needle
(excluding the needle)
Return:
Returns the portion of string, or FALSE (0) if needle is not found
9.4.16 strpos
int strpos(string $haystack, string $needle[,int $offset=0] )
Returns the numeric position of the first occurrence of needle in
the haystack string
Parameters:
$haystack: The input string
$needle: Search pattern (must be a string)
$offset: This optional offset parameter allows you to specify
which character in haystack to start searching. The
position returned is still relative to the beginning of
haystack.
Return:
Returns the position as an integer
If needle is not found, strpos() will return FALSE (0)
Page 79 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.4.17 stripos
int stripos(string $haystack, string $needle[,int $offset=0] )
Returns the numeric position of the first occurrence of Case-
insensitive needle in the haystack string
Parameters:
$haystack: The input string
$needle: Search pattern (must be a string)
$offset: This optional offset parameter allows you to specify
which character in haystack to start searching. The
position returned is still relative to the beginning of
haystack.
Return:
Returns the position as an integer
If needle is not found, stripos() will return FALSE (0)
9.4.18 strrpos
int strrpos(string $haystack, string $needle[,int $offset=0] )
Find the numeric position of the last occurrence of needle in the
haystack string
Parameters:
$haystack: The input string
$needle: Search pattern (must be a string)
$offset: If specified, search will start this number of characters
counted from the beginning of the string. If the value
is negative, search will instead start from that many
characters from the end of the string, searching
backwards
Return:
Returns the position as an integer
If needle is not found, strrpos() will return FALSE (0)
Page 80 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.4.19 strripos
int strripos(string $haystack, string $needle[,int $offset=0])
Find the numeric position of the last occurrence of Case-
insensitive needle in the haystack string
Parameters:
$haystack: The input string
$needle: Search pattern (must be a string)
$offset: If specified, search will start this number of characters
counted from the beginning of the string. If the value
is negative, search will instead start from that many
characters from the end of the string, searching
backwards
Return:
Returns the position as an integer
If needle is not found, strripos() will return FALSE (0)
9.4.20 strrchr
int strrchr(string $haystack, mixed $needle )
Find the last occurrence of a character in a string
Parameters:
$haystack: The input string
$needle: If needle contains more than one character, only the
first is used. This behavior is different from that of
strstr().
If needle is not a string, it is converted to an integer
and applied as the ordinal value of a character
Return:
This function returns the portion of string, or FALSE (0) if needle
is not found
9.4.21 strrev
int strrev(string $string)
Reverse a string
Parameters:
$string: String to be reversed
Return:
The reversed string
Page 81 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.4.22 str_repeat
int str_repeat(string $input, int $multiplier)
Returns input repeated multiplier times
Parameters:
$input: String to be repeated
$multiplier: Number of time the input string should be repeated,
multiplier has to be greater than or equal to 0. If the
multiplier is set to 0, the function will return an empty
string
Return:
The repeated string
9.4.23 substr
string substr(string $string, int $start[, int $length])
Return part of a string
Parameters:
$string: The input string must be one character or longer
$start: If start is non-negative, the returned string will start at the
start'th position in string, counting from zero.
For instance, in the string 'abcdef', the character at
position 0 is 'a', the character at position 2 is 'c', and so
forth.
If start is negative, the returned string will start at the
start'th character from the end of string. If string is less
than or equal to start characters long, FALSE will be
returned.
$length: If length is given and is positive, the string returned will
contain at most length characters beginning from start
(depending on the length of string). If length is given and
is negative then many characters will be omitted from
the end of string (after the start position has been
calculated when a start is negative).
If start denotes the position of this truncation or beyond,
the false will be returned.
If length is given and is 0, FALSE or NULL an empty
string will be returned.
If length is omitted, the substring starting from start until
the end of the string will be returned.
Return:
Returns the extracted part of string, or FALSE on failure or an
empty string.
Page 82 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.4.24 substr_compare
int substr_compare(string $main_str, string $str,
int $offset
[, int $length
[, bool $case_insensitivity = false ] ] )
Binary safe comparison of two strings from an offset, up to length
characters
Parameters:
$main_str: The main string being compared
$str: The secondary string being compared
$offset: The start position for the comparison if negative, it
starts counting from the end of the string
$length: The length of the comparison, the default value is the
largest of the length of the str compared to the length
of main_str less the offset
$case_sensivity: If case_insensitivity is TRUE, comparison is
case insensitive
Return:
Returns < 0 if main_str from position offset is less than str, > 0 if
it is greater than str, and 0 if they are equal. If offset is equal to
or greater than the length of main_str or length is set and is less
than 1, substr_compare() prints a warning and returns FALSE
9.4.25 substr_count
int substr_count(string $ haystack, string $needle,
[, int $offset = 0
[, int $length ] ] )
Count the number of substring occurrences
Parameters:
$haystack: The string to search in
$needle: The substring to search for
$offset: The offset where to start counting
$length: The maximum length after the specified offset to
search for the substring It outputs a warning if the
offset plus the length is greater than the haystack
length
Return:
Total number of substring occurrences
Page 83 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.4.26 chunk_split
string chunk_split(string $body
[, int $chunklen = 76
[, int $end = "\r\n" ] ] )
Split a string into smaller chunks
Parameters:
$body: The string to search in
$chunklen: The chunk length default is 76
$end: The line ending sequence, default is "\r\n"
$length: The maximum length after the specified offset to
search for the substring It outputs a warning if the
offset plus the length is greater than the haystack
length
Return:
The chunked string or NULL on failure
Page 84 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Parameters: none
Return:
Returns the current time measured in the number of seconds
since the Unix Epoch (January 1 1970 00:00:00 GMT)
9.5.2 microtime
string/float microtime([ bool $get_as_float = false ] )
Returns the current EPOCH timestamp with microseconds
Parameters:
$get_as_float: If used and set to TRUE, microtime() will return a
float instead of a string as described in the return
values section below
Return:
By default, microtime() returns a string in the form "msec sec",
where sec is the current time measured in the number of
seconds since the Unix Epoch (0:00:00 January 1, 1970 GMT),
and msec is the number of microseconds that have elapsed
since sec expressed in seconds.
If get_as_float is set to TRUE, then microtime() returns a float,
which represents the current time in seconds since the Unix
epoch accurate to the nearest microsecond
9.5.3 gettimeofday
mixed gettimeofday([ bool $return_float = false ] )
Returns an associative array containing the data returned from
the system call
Parameters:
$return_float: When set to TRUE, a float instead of an array is
returned
Return:
By default an array is returned. If return_float is set, then a float
is returned
Page 85 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.5.4 getdate
array getdate([ int $timestamp = time() ])
Get date/time information
Parameters:
$timestamp: The optional timestamp parameter is an integer
Unix timestamp that defaults to the current local
time if a timestamp is not given. In other words, it
defaults to the value of time()
Return:
Returns an associative array of information related to the
timestamp. Elements from the returned associative array are as
follows:
KEY DESCRIPTION VALUE
"seconds" Numeric representation of seconds 0 to 59
"minutes" Numeric representation of minutes 0 to 59
"hours" Numeric representation of hours 0 to 23
"mday" Numeric representation of the day of the month 1 to 31
"wday" Numeric representation of the day of the week 0 (Sunday) .. 6 (Saturday)
"mon" Numeric representation of a month 1 through 12
"year" A full numeric representation of a year 4 digits
"yday" Numeric representation of the day of the year 0 through 365
"weekday" A full textual representation of the day of the week Sunday through Saturday
"month" A full textual representation of a month January through December
0 Seconds since the Unix Epoch, similar to the values time() EPOCH time
* NOTE: NULL is returned on failure
9.5.5 date
string date(string $format[, int $timestamp = time() ])
Returns a string formatted according to the given format string
using the given integer timestamp or the current time if no
timestamp is given. In other words, timestamp is optional and
defaults to the value of time()
Parameters:
$format: The format of the outputted date string
$timestamp: The optional timestamp parameter is an integer
Unix timestamp that defaults to the current local
time if a timestamp is not given. In other words, it
defaults to the value of time()
Return:
A formatted date string, if a non-numeric value is used for
timestamp, FALSE is returned
Page 86 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.5.6 gmdate
string date(string $format[, int $timestamp = time() ])
Identical to the date() function except that the time returned is
Greenwich Mean Time (GMT)
Parameters:
$format: The format of the outputted date string
$timestamp: The optional timestamp parameter is an integer
Unix timestamp that defaults to the current local
time if a timestamp is not given. In other words, it
defaults to the value of time()
Return:
A formatted date string, if a non-numeric value is used for
timestamp, FALSE is returned
9.5.7 localtime
array localtime( [int $timestamp = time()
[, bool $is_associative = false ]] )
Return the local time
Parameters:
$timestamp: The optional timestamp parameter is an integer
Unix timestamp that defaults to the current local
time if a timestamp is not given. In other words, it
defaults to the value of time()
$is_associative: If set to FALSE or not supplied then the array is
returned as a regular, numerically indexed array.
If the argument is set to TRUE then localtime()
returns an associative array containing all the
different elements of the structure returned by the
C function call to localtime.
Return:
An associative array of information related to the timestamp
Return bellow array if is_associative set to FALSE
is_associative = FALSE is_associative = TRUE Description
INDEX KEY VALUE
0 "tm_sec" 0 to 59 (seconds)
1 "tm_min" 0 to 59 (minutes)
2 "tm_hour" 0 to 23 (hours)
3 "tm_mday" 1 to 31 (day of month)
4 "tm_mon" 0 to 11 (Jan to Dec)
5 "tm_year" From 1900
6 "tm_wday" 0 to 6 (Sun to Sat)
7 "tm_yday" 0 to 365
8 "tm_isdst" is daylight savings time in
effect? Positive if yes, 0 if not,
negative if unknown
Page 87 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.5.8 mktime/gmmktime
int mktime ( [ int $hour = date("H")
[, int $minute = date("i")
[, int $second = date("s")
[, int $month = date("n")
[, int $day = date("j")
[, int $year = date("Y")
[, int $is_dst = -1 ]]]]]]] )
Parameters:
$hour: The number of the hour relevant to the start of the day,
determined by month, day and year, negative values
reference the hour before midnight of the day in
question. Values greater than 23 reference the
appropriate hour in the following day(s)
$minute: The number of the minute relevant to the start of the
hour, negative values reference the minute in the
previous hour Values greater than 59 reference the
appropriate minute in the following hour(s)
$second: The number of seconds relevant to the start of the
minute negative values reference the second in the
previous minute Values greater than 59 reference the
appropriate second in the following minute(s)
$month: The number of the month relevant to the end of the
previous year, Values 1 to 12 reference the normal
calendar months of the year in question. Values less
than 1 (including negative values) reference the
months in the previous year in reverse order, so 0 is
December, -1 is November and etc …
$day: The number of the day relevant to the end of the
previous month Values 1 to 28, 29, 30 or 31
(depending upon the month) reference the normal
days in the relevant month. Values less than 1
(including negative values) reference the days in the
previous month, so 0 is the last day of the previous
month, -1 is the day before that, etc. Values greater
than the number of days in the relevant month
reference the appropriate day in the following month(s)
Page 88 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Return:
mktime() returns the Unix timestamp of the arguments given.
If the arguments are invalid, the function returns FALSE (0)
Page 89 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
Parameters:
$str: The input string
$raw_output: If the optional raw_output is set to TRUE, then the
md5 digest is instead returned in raw binary
format with a length of 16
Return:
MD5 Hash as a 32-character hexadecimal string
9.6.2 sha1
string sha1(string $str[, bool $ raw_output = false ])
Calculate the sha1 hash of a string
Parameters:
$str: The input string
$raw_output: If the optional raw_output is set to TRUE, then the
sha1 digest is instead returned in raw binary
format with a length of 16
Return:
SHA1 Hash as a 40-character hexadecimal string
9.6.3 crc32
int64 crc32(string $str)
Calculates the crc32 polynomial of a input string
Parameters:
$str: The input string
Return:
CRC32 checksum of the given input (64-bit integer)
Page 90 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.7.1 GetPnt
int/float GetPnt(int $ComId, int $PntType, int $PntId )
Get the specific point Value or state by references of ComId and
PntId
Parameters:
$ComId: The referenced communication Id for desired point,
this is a value from 1 to 96 or maximum port
supported in VR2000 system.
You can use the constant of COMID to reference a
current port of VeestaScript protocol connection to
VR2000 platform. Normally use of constant of
COMID will be helpful when you want to write a
public script with common relative to the database
points.
$PntType: Specify which point data table you mean, you should
use from one of bellow constant:
AI: Refer to Ai table in database for integer value
AIF: Refer to Ai table in database for float value
DI: Refer to Di data table in database
PI: Refer to Pi data table in database
DO: Refer to Do data table in database
AO: Refer to Ao data table in database
$PntId: Addressed the point ID row of desired table row of
database, it is from 1 up to maximum number of
data points in desired table specified by PntType.
Return:
If the PntState option omitted then the return value is the current
value of addressed point by ComId and PntId from the desired
table specified by PntType
If PntTpe=AI : The current integer value of Ai point
If PntType=AIF: The current float value of Ai Point
If PntType=DI: The current status of ON or OFF for Di point
If PntType=PI: The current integer value of Pi point
Page 91 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.7.2 GetPntName
string GetPntName(int $ComId, int $PntType, int $PntId )
Get the specific point Name description by reference addressed
of ComId and PntId
Parameters:
$ComId: The referenced communication Id for desired point,
this is a value from 1 to 96 or maximum port
supported in VR2000 system.
You can use the constant of COMID to reference a
current port of VeestaScript protocol connection to
VR2000 platform. Normally use of constant of
COMID will be helpful when you want to write a
public script with common relative to the database
points.
$PntType: Specify which point data table you mean, you should
use from one of bellow constant:
AI: Refer to Ai table in database for integer value
DI: Refer to Di data table in database
PI: Refer to Pi data table in database
DO: Refer to Do data table in database
AO: Refer to Ao data table in database
$PntId: Addressed the point ID row of desired table row of
database, it is from 1 up to maximum number of
data points in desired table specified by PntType.
Return:
Return a string of point name in database,
Return NULL terminated string if any problem in like invalid
ComId or PntId and etc in function call or any other error
Page 92 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.7.3 GetPntState
int GetPntState(int $ComId, int $PntType, int $PntId )
Get the specific point state by references of ComId and PntId
Parameters:
$ComId: The referenced communication Id for desired point,
this is a value from 1 to 96 or maximum port
supported in VR2000 system.
You can use the constant of COMID to reference a
current port of VeestaScript protocol connection to
VR2000 platform. Normally use of constant of
COMID will be helpful when you want to write a
public script with common relative to the database
points.
$PntType: Specify which point data table you mean, you should
use from one of bellow constant:
AI: Refer to Ai table in database for integer value
DI: Refer to Di data table in database
PI: Refer to Pi data table in database
DO: Refer to Do data table in database
AO: Refer to Ao data table in database
$PntId: Addressed the point ID row of desired table row of
database, it is from 1 up to maximum number of
data points in desired table specified by PntType.
Return:
Function return one of bellow items based on state of point or
return NULL if an error occurred or ComId, PntId not found.
PNT_STATE_INI: Represent the point is in Initialize state
PNT_STATE_ONLINE: Represent the point is in online state
PNT_STATE_COMERR: The point communication or wire lost
PNT_STATE_CHATTER: The point in the chatter filter block
PNT_STATE_OVERFL: The point value is overflow
PNT_STATE_MANUAL: The current point value is manual enter
PNT_STATE_INVALID: The point is in invalid state
PNT_STATE_UNDERFL: The point value is underflow
Page 93 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.7.4 SetPnt
bool SetPnt(int $ComId, int $PntType, int $PntId, int $Value )
Parameters:
$ComId: The referenced communication Id for desired point,
this is a value from 1 to 96 or maximum port
supported in VR2000 system.
You can use the constant of COMID to reference a
current port of VeestaScript protocol connection to
VR2000 platform. Normally use of constant of
COMID will be helpful when you want to write a
public script with common relative to the database
points.
$PntType: Specify which point data table you mean, you should
use from one of bellow constant:
AI: Refer to Ai table in database for integer value
AIF: Refer to Ai table in database for float value
DI: Refer to Di data table in database
SOE: Refer to create a SOE event in database
PI: Refer to Pi data table in database
DO: Refer to send command based Do database
AO: Refer to set point Ao data table in database
$PntId: Addressed the point ID row of desired table row of
database, it is from 1 up to maximum number of
data points in desired table specified by PntType.
$Value: This is value of point to be set for the addressed
point, if the PntType is AI this is "interger" type, if
PntType is AIF it is "float" type, if PntType is DI it is
ON or OFF and if PntType is SOE the Value is ON
or OFF and function create the timetag event in
database, if PntType is DO the Value of OFF send
telecontrol Open command and if Value of OFF
send telecontrol Close command. If PntType is AO
so the Value is set pointed value of point.
Return:
If set point to the new value done successfully, the function
return TRUE
Page 94 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual
9.7.5 Sleep
void Sleep(int $ms)
Sleep the process wait until the specific milliseconds elapsed.
Parameters:
$ms: The input time in mili-seconds
Return:
No return value, just after call the Sleep() the execution of
program wait in sleep up to the time specific has been passed.
NOTE: We recommend to use the Sleep() function inside of infinit or
long loops in your script program, this function cause other process
better while your script program also work.
Page 95 of 96
Veesta World Co
E-Mail: [email protected]
World Wide Web: http://www.veesta-world.com/
D:\HD\D\VW-Products\V-RTU2000\Documents\VR-2400\V-RTU2000 - VR-2400 VeestaScript Programming Language Manual V1-0-en.doc
Page 96