0% found this document useful (0 votes)
28 views

V-RTU2000 - VR-2400 VeestaScript Programming Language Manual V1-0-En

Uploaded by

h.toraby
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

V-RTU2000 - VR-2400 VeestaScript Programming Language Manual V1-0-En

Uploaded by

h.toraby
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 96

Veesta World Co

Technical Information

VR-2400 RTU Product

VeestaScript
Programming Manual

Author: Veesta World Co., Engineering Department


TRADEMARKS
VEESTA and VEESTA WORLD are trademarks of Veesta World Co. Iran

V-RTU2000 is trademarks of RTU system of VEESTA WORLD Co.

VR-2400 is trademarks of Rail Mount RTU system of VEESTA WORLD Co.

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

Version Date Comment

1.0 2023/10/06 First issue

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

Chapter 1 - Introduction ................................................................... 11


1.1 General Information.............................................................11
1.2 Veesta World Co .................................................................11
1.3 Copyrights ...........................................................................12
Chapter 2 - VeestaScritp Preface .................................................... 13
2.1 Overview .............................................................................13
2.2 The Language .....................................................................13
Chapter 3 - Basic Syntax.................................................................. 15
3.1 Lexal Conventions...............................................................15
3.2 Instruction Separation .........................................................15
3.3 Comments ...........................................................................16
Chapter 4 - Types ............................................................................. 17
4.1 Overview .............................................................................17
4.2 Boolean ...............................................................................17
4.2.1 Converting to Boolean .............................................18
4.3 Integers ...............................................................................18
4.4 Real number........................................................................20
4.5 NULL ...................................................................................20
4.6 String ...................................................................................21
4.6.1 Single quoted string .................................................21
4.6.2 Nowdoc....................................................................21
4.6.3 Double quoted string................................................22
4.7 JSON Arrays .......................................................................23
4.8 JSON Objects......................................................................25
4.9 Resource .............................................................................26
4.10 Type casting ........................................................................27
Chapter 5 - Variables........................................................................ 28
5.1 Overview .............................................................................28
5.2 Variable Scope ....................................................................28
5.2.1 The uplink keyword ..................................................29
5.2.2 The static keyword ...................................................30
5.3 Predefined Variables ...........................................................32

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

9.2.5 is_int ........................................................................63


9.2.6 is_integer .................................................................63
9.2.7 is_long .....................................................................63
9.2.8 is_string ...................................................................63
9.2.9 is_null.......................................................................64
9.2.10 is_numerci .............................................................64
9.2.11 is_scalar.................................................................64
9.2.12 is_array ..................................................................64
9.2.13 is_object.................................................................65
9.2.14 floatval ...................................................................65
9.2.15 intval ......................................................................65
9.2.16 strval ......................................................................65
9.2.17 empty .....................................................................66
9.3 Mathematical Functions.......................................................67
9.3.1 abs ...........................................................................67
9.3.2 sqrt...........................................................................67
9.3.3 exp ...........................................................................67
9.3.4 floor..........................................................................67
9.3.5 cos ...........................................................................68
9.3.6 sin ............................................................................68
9.3.7 acos .........................................................................68
9.3.8 asin ..........................................................................68
9.3.9 cosh .........................................................................69
9.3.10 sinh ........................................................................69
9.3.11 ceil .........................................................................69
9.3.12 tan..........................................................................69
9.3.13 tanh........................................................................70
9.3.14 atan........................................................................70
9.3.15 atan2......................................................................70
9.3.16 log ..........................................................................70
9.3.17 log10 ......................................................................71
9.3.18 pow ........................................................................71
9.3.19 pi ............................................................................71
9.3.20 fmod.......................................................................71
9.3.21 hypot ......................................................................72
9.3.22 round......................................................................72
9.3.23 dechex ...................................................................72
9.3.24 decoct ....................................................................72
9.3.25 decbin ....................................................................73
9.3.26 hexdec ...................................................................73
9.3.27 bindec ....................................................................73
9.3.28 octdec ....................................................................73
9.3.29 base_convert .........................................................74

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

9.4 String Handling Functions ...................................................75


9.4.1 strlen ........................................................................75
9.4.2 strcmp ......................................................................75
9.4.3 strncmp ....................................................................75
9.4.4 strcasecmp ..............................................................76
9.4.5 strncasecmp ............................................................76
9.4.6 trim...........................................................................76
9.4.7 rtrim..........................................................................77
9.4.8 ltrim ..........................................................................77
9.4.9 strtolower .................................................................77
9.4.10 strtoupper...............................................................78
9.4.11 ord..........................................................................78
9.4.12 chr..........................................................................78
9.4.13 bin2hex ..................................................................78
9.4.14 strstr.......................................................................79
9.4.15 stristr ......................................................................79
9.4.16 strpos .....................................................................79
9.4.17 stripos ....................................................................80
9.4.18 strrpos....................................................................80
9.4.19 strripos ...................................................................81
9.4.20 strrchr.....................................................................81
9.4.21 strrev......................................................................81
9.4.22 str_repeat...............................................................82
9.4.23 substr .....................................................................82
9.4.24 substr_compare .....................................................83
9.4.25 substr_count ..........................................................83
9.4.26 chunk_split.............................................................84
9.5 Time Functions....................................................................85
9.5.1 time ..........................................................................85
9.5.2 microtime .................................................................85
9.5.3 gettimeofday ............................................................85
9.5.4 getdate.....................................................................86
9.5.5 date..........................................................................86
9.5.6 gmdate.....................................................................87
9.5.7 localtime...................................................................87
9.5.8 mktime/gmmktime....................................................88
9.6 Cryptography Functions ......................................................90
9.6.1 md5..........................................................................90
9.6.2 sha1 .........................................................................90
9.6.3 crc32 ........................................................................90
9.7 Real-time Database Functions ............................................91
9.7.1 GetPnt......................................................................91
9.7.2 GetPntName ............................................................92

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

9.7.3 GetPntState .............................................................93


9.7.4 SetPnt ......................................................................94
9.7.5 Sleep........................................................................95

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

Figure 1-1: Veesta World Co Logo and sign .............................................................12

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

Table 3-1: VeestaScript reserved keywords ..............................................................15


Table 4-1: VeestaScript Escape sequence code.......................................................22
Table 5-1: VeestaScript Predefined Variables...........................................................32
Table 6-1: VeestaScript Assignment Operators ........................................................36
Table 6-2: VeestaScript Arithmetic Operators ...........................................................37
Table 6-3: VeestaScript Comparision Operators .......................................................38
Table 6-4: VeestaScript Bitwise Operators................................................................39
Table 6-5: VeestaScript Logical Operators................................................................40
Table 6-6: VeestaScript JSON Array/Object Operators.............................................44
Table 6-7: VeestaScript Operators Precedence ........................................................46

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

1.1 General Information

This is technical information of design of Product of V-RTU2000


Series of VR-2400, the Remote Terminal Unit and also
Programmable Logic Controller (PLC) from Veesta World Company.
This document helps you to find about how VR-2400 Series works
and designed for your purpose.

V-RTU2000, Series VR-2400 of RTU system adopted for from very


small RTU Controller or PLC device from that can be used in as
Feeder Terminal Unit up to very large scale PLC application and
RTU for Generation and Transmission High Voltage Substations, and
or other controlled stations.

Veesta World Co. is associated with you! in planning, designing,


manufacturing, supply, installation, commissioning and acceptance
test for the Remote Terminal Units and Controller in your projects.
Veesta World Company will render full support and services to its
customer to enable them to deliver first class services to the
Automation Market.

1.2 Veesta World Co

Veesta World Co is a leading company in


automation field in Iran and specialized in
design and installation of IT Network of wide
area and local area, Automation control units, control rooms, DCS
design, PLC and SCADA application installation and system
integration. The main advantage of Veesta World's products is
complying international standards and do customs basic design.

Veesta World Co is a dynamic company, whose main commitment is


the customer’s satisfaction. Business vision and its future evolution
together with the proper combination of new and existing
technologies are the main aspects considered in the solutions
proposed by Veesta World Co. Owing to this, key issues like
Scalability, the Return of Investment or the Total Cost of Ownership
are carefully considered. Consequently, the solutions offered by
Veesta World Co are able to cope with the requirements of a
sustainable growth. Veesta World Co is a service-oriented company
and the customer perspective is its action guide. An added value of
Page 11 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

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.

The objective of Veesta World Co is focused on the creation of value


for the customer through the proper business strategy alignment and
the right combination of technologies. These principles, developed
under the Total Quality Management practice, allow Veesta World Co
to offer, in a seamless approach, consultancy, engineering and
training services.

The founders of Veesta World Co are professionals with a large


experience in the Telecommunication and Networking and Industrial
fields.

Veesta World Co is formed by a balanced team of professionals that


gather knowledge in a wide range of technologies and specific know-
how on how to apply these technologies in mission-critical control
networks.

1.3 Copyrights

All of documents and materials in related to this document and this


document are copyrights of Veesta World Co and it is not permitted
to use or transfer the contents to any other parties.

The Veesta World Co logo is registered trademark of Veesta World


Co and its properties.

Figure 1-1: Veesta World Co Logo and sign

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

Chapter 2 - VeestaScritp Preface

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.

Being an extension language, "VeestaScript" has no notion of a


main program, it only works embedded in a host V-RTU2000 or other
application. This host program can write and read "VeestaScript"
variables and can register C/C++ functions to be called by
"VeestaScript" code.

2.2 The Language


This manual describes the lexis, the syntax, and the semantics of the
"VeestaScript" programming language. In other words, this manual
describes which tokens are valid, how they can be combined, and
what their combinations mean.
In the future you will see bellow chapters:

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

Chapter 3 - Basic Syntax

3.1 Lexal Conventions


Names (also called identifiers) in "VeestaScript" can be any string
(UTF-8 stream) of letters, digits, and underscores, not beginning with
a digit. This coincides with the definition of names in most languages.
Identifiers are used to name variables, functions and JSON objects
fields.
The following keywords are reserved and cannot be used as names:

if else elseif for


foreach while do (not used) switch
static function case print
const default as continue
break exit die import
include string bool boolean
int integer float uplink
class (not used) object (not used) array (not used) return
goto (not used)
Table 3-1: VeestaScript reserved keywords

"VeestaScript" is a case-sensitive language: if is a reserved word,


but IF and If are two different, valid names. As a convention, names
starting with an underscore followed by uppercase letters (such as
__VS__, __DATE__, __TIME__, etc.) are reserved for built-in
constants.

3.2 Instruction Separation


As in C or Perl, "VeestaScript" requires instructions to be terminated
with a semicolon ';' at the end of each statement.

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:

// One-line C++ comment

# Shell style comment

C style or block comments end at the first */ encountered. Make sure


you don't nest block style comments. It is easy to make this mistake if
you are trying to comment out a large block of code.

Example:

/*

* This is a block comment.

* Block comments don't nest.

*/

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

We in this chapter will study each type in details.

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

4.2.1 Converting to Boolean


To explicitly convert a value to boolean, use the (bool) or (boolean)
casts. However, in most cases the cast is unnecessary, since a value
will be automatically converted if an operator, function or control
structure requires a boolean argument.
When converting to boolean, the following values are considered
FALSE:
 the boolean FALSE itself
 The NULL type
 the integer 0 (zero)
 the float 0.0 (zero)
 the empty string "" , the string "0" and the string "false"
 a JSON array with zero elements
 a JSON object with zero members

Any other value is considered true even negative numbers and the
resource type.

Example:

dump((bool) -1); // bool(true)

dump((bool) ""); // bool(false)

dump((bool) "foo"); // bool(true)

dump((bool) 3.14e5); // bool(true)

dump((bool)[10,11,13]); // bool(true)

dump((bool){}); // bool(false)

dump((bool) "false"); // 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 +).

To use octal notation, precede the number with a 0 (zero). To use


hexadecimal notation precede the number with 0x. To use binary
notation precede the number with 0b.

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:

print 0xff; //255

print 1200; //1200

print 0766; //502

print -2; //-2

print 0b1011001; //89

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

Internally, integers are stored in 8 bytes (64 bit) regardless of the


target platform. The integer type can can store integer values
between -9223372036854775808 and +9223372036854775807
inclusive.

Integer size can be determined using the built-in constant


VS_INT_SIZE, and maximum integer value using the constant
VS_INT_MAX.

To explicitly convert a value to integer, use either the (int) or


(integer) casts. However, in most cases the cast is not needed,
since a value will be automatically converted if an operator, function
or control structure requires an integer argument.

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

4.4 Real number


Reals also known as floating point numbers or doubles can be
specified using any of the following syntax:

3.142 or 3.4e2 or 6E-3

Using BNF:

LNUM [0-9]+
DNUM ([0-9]*[\.]{LNUM}) | ({LNUM}[\.][0-9]*)
EXPONENT_DNUM [+-]?(({LNUM} | {DNUM}) [eE][+-]? {LNUM})

The size of a float is platform-dependent, although a maximum of


~1.8e308 with a precision of roughly 14 decimal digits is a common
value (the 64 bit IEEE format).

Floating point numbers have limited precision. Although it depends


on the system, "VeestaScript" typically uses the IEEE 754 double
precision format, which will give a maximum relative error due to
rounding in the order of 1.11e-16. Non elementary arithmetic
operations may give larger errors, and, of course, error prorogation
must be considered when several operations are compounded.

To explicitly convert a value to real number, use either the (float)


casts.

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

4.6.1 Single quoted string


The simplest way to specify a string is to enclose it in single quotes
(the character ').
To specify a literal single quote, escape it with a backslash (\). To
specify a literal backslash, double it (\\). All other instances of
backslash will be treated as a literal backslash: this means that the
other escape sequences you might be used to, such as \r or \n, will
be output literally as specified rather than having any special
meaning.
 Note: Unlike the double-quoted string, variables and escape
sequences for special characters will not be expanded when they
occur in single quoted strings.

Example:

print 'Hello World!'; //Hello World

print 'It\'s me, Hodjat:'; //It's me, Hodjat:

//This will not expand a new line nor variable content

$var = 'test';

print 'Value of $var = $var\n'; //Value of $var = $var\n

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

shares some features in common with the SGML <![CDATA[ ]]>


construct, in that it declares a block of text which is not for parsing.
A nowdoc is identified with the <<< operator. After this operator, an
identifier is provided, then a newline. The string itself follows, and
then the same identifier again to close the quotation.
The closing identifier must begin in the first column of the line. Also,
the identifier must follow the same naming rules as any other label in
"VeestaScript".
Example:

$var = 'test';

$str = <<<EOD
Example of string
spanning multiple lines
using nowdoc syntax.

Value of $var = $var\n

//I'm not a comment


EOD;

print $str;

4.6.3 Double quoted string


If the string is enclosed in double-quotes ("),"VeestaScript" will
interpret more escape sequences for special characters:

Table 4-1: VeestaScript Escape sequence code


Sequence Description
\n Linefeed
\r Carriage return
\t Horizontal tab
\v Vertical tab
\f Form feed
\\ Backslash
\$ Dollar sign

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.

The most important feature of double-quoted strings is the fact that


variable names will be expanded:
If a dollar sign ($) is encountered, the parser will greedily take as
many tokens as possible to form a valid variable name including
JSON object and array members.

Example:

$name = 'Hodjat';

print "Hello, my name is = $name\n"; //Hello, my name is Hodjat

//Declare a simple JSON object

$person = {name : 'Wolf', age : 27 };

print "Mr $person.name is $person.age years old\n"; //Mr Wolf is 27 years old

//Declare a simple JSON array

$num = [27, 512];

print "$num[0+1] is greater than $num[0]\n"; //512 is greater than 27

4.7 JSON Arrays


A JSON array is simply an ordered sequence of values which can be
any valid "VeestaScript" expression including NULL, JSON objects
or even other arrays, comma-separated and enclosed in square
brackets.

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

The syntax is as follows:

[ [expr,expr] ];

Example:

$numbers = [ 15, 20, 50 << 1 ];

/*

Declare a JSON array with two random numbers between 0 and 1024 inclusive
using the built-in rand() function.

*/

$rand = [ rand() & 1023, rand() % 1024, (512 * 2) >> 1];

//Dump array contents

print $numbers,VS_EOL,$rand;

To access array values simply use the subscript operator.


The notation is:

$array_name[expr];

Example:

//Declare a JSON array with three fields

$my_array = [ __TIME__, __DATE__, VS_OS ];

print $my_array[0]; //14:24:05

print VS_EOL;

print $my_array[1]; //2023-01-06

print VS_EOL;

print $my_array[2]; //V-ELOSX, ...

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

4.8 JSON Objects


A JSON object is simply an unordered collection of key:value pairs
with the ':' character separating the key and the value (Which can be
any valid "VeestaScript" expression including NULL, JSON arrays or
even another objects), comma-separated and enclosed in curly
braces; the keys must be an identifier or a string and should be
distinct from each other.

Example:

//Declare a simple JSON object

$user = {

name : 'Hodjat Toraby',

login : 'htp123',

age : 55

};

print "username= $user.name;\n name = $user.login\n age = $user.age";

This example when running should display:

username = htp123

name = Hodjat Toraby

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

To access object member, simply use the member access operator


(Also called dot operator) as follows:

$person = {

firstName : "Hodjat",

lastName: "Toraby",

age: 55,

addr: {

"streetAddress": "42 Golfam St. Nelson Mandela St.",

city: "Tehran",

state : "TH",

postalCode : 1915673873

}; //Don't forget the semi-colon here

print $person.addr.city; //Tehran

print VS_EOL;

print $person.addr.postalCode; //1915673873

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

4.10 Type casting


Type casting in "VeestaScript" works much as it does in C. the
name of the desired type is written in parentheses before the
expression which is to be cast. As of this release, the supported
types are:
 Integer ==> (int) or (integer)
 Boolean ==> (bool) or (boolean)
 Real ==> (float)
 String ==> (string)
Forced cast of JSON arrays or objects is not supported and is
planned for future version.

$var = (int) 2.3e+1; //Force an int cast

$var = (string)0xff; //force a string cast

"VeestaScript" does not require explicit type definition in variable


declaration; a variable's type is determined by the context in which
the variable is used. That is, if a string value is assigned to variable
$var, $var becomes a string. If an integer value is then assigned to
$var, it becomes an integer.
An example of "VeestaScript" automatic type conversion is the
addition operator '+'. If either operand is a real, then both operands
are evaluated as reals, and the result will be a real. Otherwise, the
operands will be interpreted as integers, and the result will also be an
integer. Note that this does not change the types of the operands
themselves; the only change is in how the operands are evaluated
and what the type of the expression itself is.

// 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)

$test += "25 years old";

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.

Variables in "VeestaScript" are represented by a dollar sign followed


by the name of the variable. The variable name is case-sensitive.

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';

print "$var, $Var"; // outputs "Foo Bar"

/* Test */
dump($var,$Var);

5.2 Variable Scope


The scope of a variable is the context within which it is defined. For
the most part all "VeestaScript" variables only have a single scope.
This single scope spans imported files as well. For example:

$foo = __TIME__;
import 'driver.script';

Here the $foo variable will be available within the imported


driver.script script.
However, within user-defined functions a local function scope is
introduced. Any variable used inside a function is by default limited to
the local function scope. For example:

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

$foo = rand(); //A random integer

function test()

print $foo; //null, since $foo is not declared in this scope.

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.

5.2.1 The uplink keyword


In order to modify or to make a global variable available in a local
scope, you must use the uplink keyword with the name of the target
global variables as follows:

$foo = rand(); //A random integer

$bar = rand_str(3); //A random string of length 3

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.

/* Modify $foo and $bar */

$foo = 1023;

$bar = 'New value';

print VS_EOL;
}

test();

/* Global scope */

print $foo; //1023

print $bar; //New value

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.

5.2.2 The static keyword


a static variable is a variable that has been allocated statically and
whose lifetime extends across the entire run of the program. That is,
a static variable exists only in a local function scope, but it does not
lose its value when program execution leaves this scope.

To declare a variable static, simply precede it with the keyword static


as follows:

function test()

static $num = rand() & 1023; //Random integer between 0 and 1024 inclusive

/* Print the number and increment its value by one */

print $num++;

print VS_EOL;

test(); //59

test(); //60

test(); //61

test(); //62

Note that static variables can take any complex expressions


including function calls as their initialization value.

Declaring a variable static in the global scope is a no-op.

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

of terminating the recursion. The following simple function recursively


counts to 5, using the static variable $count to know when to stop:

function test()

static $count = 0;

/* Increment the static counter */

if( $count++ < 5 ){

/* Recurse and call test() again */

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

5.3 Predefined Variables


"VeestaScript" is shipped with a set of predefined global variables
available in all scopes (without the need of the uplink statement. The
following table summarizes the predefined variables and their
purposes.

Table 5-1: VeestaScript Predefined Variables


Predefined Variable
Purpose
Name
VS_VERSION The current VeestaScript Programming Version number
VS_ENGINE The current VeestaScript Engine Version number
Report the current OS that you run the VeestaScript. The
VS_OS is one of the following:
VS_OS Windows: For Windows operating system
Linux: For Linux Operating System
V-ELOSX: Represent the Veesta OS name for Veesta Products
The End Of Line escapes character to be used with print
VS_EOL
function. This will cause the new line after print of this.
This constant shows the largest integer supported by your
VS_INT_MAS
platform. Normally is it is 64 bits.
VS_INT_SIZE This expands the size in bytes of a 64-bit integer.
The current time of system based on GMT in format of
__TIME__
"hh:mm:ss"
The current date of system based on GMT in format of ISO-
__DATE__
8601 "yyyy-mm-dd"

M_PI The number of  = 3.1415926535898


M_E The number of e = 2.7182818284590452354

M_LOG2E The number of log 2 e = 1.4426950408889634074

M_LOG10E The number of log10 e = 0.4342944819032518276

M_LN2 The number of ln 2  = 0.69314718055994530942

M_LN10 The number of ln10 = 2.30258509299404568402

M_PI_2 The number of  = 1.57079632679489661923


2

M_PI_4 The number of  = 0.78539816339744830962


4

M_1_PI The number of 1 = 0.31830988618379067154


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

M_2_PI The number of 2 = 0.63661977236758134308


M_SQRTPI The number of  = 1.77245385090551602729

M_2_SQRTPI The number of 2 =1.12837916709551257390


M_SQRT2 The number of 2 =1.41421356237309504880

M_SQRT3 The number of 3 =1.73205080756887729352

M_SQRT1_2 The number of 1 =0.70710678118654752440


2

M_LNPI The number of ln  = 1.14472988584940017414


M_EULER The number Euler's constant  = 0.57721566490153286061
The current ID of Communication port of connected
COMID
VeestaScript Protocol device.
The current device number that contain the VeestaScript
DEVID

The type definition for Ai data table in integer format used in


AI
GetPnt and SetPnt functions.
The type definistaion for Ai data table in floating point format
AIF
used in GetPnt and SetPnt functions.
The type definition for Di data table used in GetPnt and
DI
SetPnt function.
The type definition for Pi data table used in GetPnt and SetPnt
PI
function.
The type definition for Do data table used in GetPnt and
DO
SetPnt function.
The type definition for Ao data table used in GetPnt and
AO
SetPnt function.
SOE The type definition for Di data table used in SetPnt function
SPI_OFF The constant value to define a SPI OFF state the value b0
SPI_ON The constant value to define a SPI ON state the value b1
DPI_INTERMEDIATE The constant value to define a INTERMEDIATE state b00
DPI_OFF The constant value to define a DPI OFF state value b01
DPI_ON The constant value to define a DPI ON state value b10
DPI_INDETERMINATE The constant value to define a INDETEMINATE state b11

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)

For example, 2+3 is arithmetic and programming expression which


evaluates to 5. A variable is an expression because it denotes a
value in memory, so $y+6 is an expression. An example of a
relational expression is 4 != 4, which evaluates to false

Expressions are the most important building stones of


"VeestaScript". In "VeestaScript", almost anything you write is an
expression. The simplest yet most accurate way to define an
expression is "anything that has a value".

Conceptually, there are two types of expressions: those that assign a


value to a variable, and those that simply have a value. For example,
the expression $x = 6 is an expression that assigns the variable $x
the value seven. This expression itself evaluates to seven. Such
expressions use assignment operators. On the other hand, the
expression 4 + 2 simply evaluates to seven; it does not perform an
assignment. The operators used in such expressions are referred to
simply as operators.

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

operator" (although it could perhaps more properly be called the


conditional operator).

"VeestaScript" has the following types of operators. This section


describes the operators and contains information about operator
precedence.
 Assignment Operators
 Arithmetic Operators
 Comparison Operators
 Ternary Operator
 Bitwise Operators
 Logical Operators
 String Operators
 Member Access Operators
 JSON Arrays/Objects Operators
 Comma Operator

6.3 Assignment Operators


An assignment operator assigns a value to its left operand based on
the value of its right operand. The basic assignment operator is equal
(=), which assigns the value of its right operand to its left operand.
That is, $x = 10 assigns the value of 10 to the variable $x.
In addition to the basic assignment operator, there are "combined
operators" for all of the binary arithmetic, JSON array/object union
and string operators that allow you to use a value in an expression
and then set its value to the result of that expression.

Table 6-1: VeestaScript Assignment Operators


Shorthand operator Meaning Description
$x = expr - Simple assignment.
Add and store. This is an overloaded operator
$x += expr x=x+y which mean that it's behavior depend on the
given operands.
$x -= expr x=x-y Subtract and store.
$x *= expr x=x*y Multiply and store.
$x /= expr x=x/y Divide and store.
$x %= expr x=x%y Modulo and store.
$x <<= expr x = x << y Left shift and store.
$x >>= expr x = x >> y Right shift and store.
$x .= expr x = x .. y Concatenate string and store.
$x &= expr x=x&y Bit-and and store.
$x ^= expr x=x^y Bit-xor and store.
$x |= expr x=x|y Bit-or and store.

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.

6.4 Arithmetic Operators


Arithmetic operators take numerical (64 integers or real numbers)
values (either literals, variables or even strings) as their operands
and return a single numerical value. The standard arithmetic
operators are addition (+), subtraction (-), multiplication (*), and
division (/). These operators work as they do in most other
programming languages when used with floating point numbers (in
particular, The division operator ("/") returns a float value unless the
two operands are integers (or strings that get converted to integers)
and the numbers are evenly divisible, in which case an integer value
will be returned.)

In addition, "VeestaScript" provides the arithmetic operators listed in


the following table.

Table 6-2: VeestaScript Arithmetic Operators


Operator Description Example
Unary increment operator. Adds one to its
operand. If used as a prefix operator If $x is 10, then ++$x; sets
++ (++$x), returns the value of its operand $x to 11 and returns 11,
after adding one; if used as a postfix whereas $x++; returns 10
operator ($x++), returns the value of its and, only then, sets $x to 11.
operand before adding one.

If $x is 10, then --$x; sets $x


Unary decrement operator. Subtracts one
-- to 9 and returns 9, whereas
from its operand. The return value is
$x--; returns 10 and, only
analogous to that for the increment operator.
then, sets $x to 9.
Modulus: Returns the integer remainder of
% print 1024 % 0xff; //4
dividing the two operands.
$x = -15;
Unary negation operator. Returns the
-
negation of its operand.
print $x; //-15

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

6.5 Comparison Operators


Comparison operators, as their name implies, allow you to compare
two values.

A comparison operator compares its operands and returns a logical


value based on whether the comparison is true. The operands can
be numerical, string, logical, or object values. Strings are compared
byte per byte using a memcmp() like function. In most cases, if the
two operands are not of the same type, "VeestaScript" attempts to
convert the operands to an appropriate type for the comparison. (The
sole exceptions to this rule are === and !==, which perform "strict"
equality and inequality and which do not attempt to convert the
operands to compatible types before checking equality.) The
following table describes the comparison operators, assuming the
following code:

$x = 6, $y = 10

Table 6-3: VeestaScript Comparision Operators


Operator Description Examples
6 == $x
== Equal Returns true if the operands are equal. "6" == $x
10 == 0xA
$x != 10
!= Not equal Returns true if the operands are not equal.
$y != "6"
$x <> 10
<> Not equal Returns true if the operands are not equal.
$y <> "6"
Returns true if the operands are equal and
=== Strict equal 6 === $x
of the same type.
Returns true if the operands are not equal $x !== "6"
!== Strict not equal
and/or not of the same type. 6 !== '6'
Returns true if the left operand is greater $x > $y
> Greater than
than the right operand. '12 sheep' > 0xA
Returns true if the left operand is greater $x >= $y
>= Greater than or equal
than or equal to the right operand. $x >= 100
Returns true if the left operand is less than
< Less than $x < $y
the right operand.
Returns true if the left operand is less than $x <= $y
<= Less than or equal
or equal to the right operand. $x <= 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

6.6 Ternary Operator


The ternary operator is the only "VeestaScript" operator that takes
three operands. The operator can have one of two values based on a
condition. The syntax is:
condition ? expr1 : expr2 ;

If condition is true, the operator has the value of expr1. Otherwise it


has the value of expr2. You can use the conditional operator
anywhere you would use a standard operator.

Example:

$rank = 6;

$status = $rank > 5 ? "good" : "bad";

print $status; //good

6.7 Bitwise Operators


Bitwise operators treat their operands as a set of 64 bits (zeros and
ones), rather than as decimal, hexadecimal, or octal numbers. For
example, the decimal number nine has a binary representation of
1001. Bitwise operators perform their operations on such binary
representations, but they return standard "VeestaScript" numerical
values.

Table 6-4: VeestaScript Bitwise Operators


Operator Usage Description
Returns a one in each bit position for which the corresponding
Bit AND a&b
bits of both operands are ones.
Returns a one in each bit position for which the corresponding
Bit OR a|b
bits of either or both operands are ones.
Returns a one in each bit position for which the corresponding
Bit XOR a^b
bits of either but not both operands are ones.
Bit NOT ~a Inverts the bits of its operand.
Shifts a in binary representation b bits to the left, shifting in
Left shift a << b
zeros from the right.
Shifts a in binary representation b bits to the right, discarding
Right shift a >> b
bits shifted off.

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

6.8 Logical Operators


Logical operators are typically used with Boolean (logical) values;
when they are, they return a Boolean value. However, the && and ||
operators actually return the value of one of the specified operands,
so if these operators are used with non-Boolean values, they may
return a non-Boolean value. The logical operators are described in
the following table.

Table 3.6 Logical operators


Table 6-5: VeestaScript Logical Operators
Operator Usage Description
(Logical AND) Returns expr1 if it can be converted to
false; otherwise, returns expr2. Thus, when used with
&& expr1 && expr2
Boolean values, && returns true if both operands are
true; otherwise, returns false.
(Logical OR) Returns expr1 if it can be converted to
true; otherwise, returns expr2. Thus, when used with
|| expr1 || expr2
Boolean values, || returns true if either operand is true;
if both are false, returns false.
(Logical NOT) Returns false if its single operand can be
! !expr
converted to true; otherwise, returns true.

Examples of expressions that can be converted to false are those


that evaluate to null, 0 or the empty string ("")

6.8.1 Short-circuit evaluation


As logical expressions are evaluated left to right, they are tested for
possible "short-circuit" evaluation using the following rules:

 false && anything is short-circuit evaluated to false.


 true || anything is short-circuit evaluated to true.

The rules of logic guarantee that these evaluations are always


correct. Note that the anything part of the above expressions is not
evaluated, so any side effects of doing so do not take effect.

Example:

//foo() will never get called as those operators are short-circuit


$x = false && foo(); // $x = false;
$y = true || foo(); // $y = true;

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

6.9 String Operators


In addition to the comparison operators, which can be used on string
values, the concatenation operator .. (two dots) concatenates two
string values together, returning another string that is the union of the
two operand strings. For example, "my " .. "string" returns the string
"my string".

The shorthand assignment operator .= can also be used to


concatenate strings.

Example:

$date = 'Current date is: ' .. __DATE__;

print $date .. VS_EOL; //Current date is: 2023-01-06

//Append a single space and the current time

$date .= ' ' .. __TIME__;

print $date //Current date is: 2023-01-06 11:58:02

6.10 Member Access Operators


Member operators provide access to an object's properties and
arrays entries.

A JSON object is actually an associative array (i.e. map, dictionary,


hash). The keys in this hash are the names of object members.
There are two ways to access array and object members: dot
notation and bracket notation (i.e: subscript operator).

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

6.11 Dot notation


Here, simply separate the object name and the target member
(including anonymous functions) with a dot as follows:
//declare a simple JSON object

$my_object = {

'time' : __TIME__, //Current time

'date' : __DATE__, //Current date

'os' : VS_OS //Host operating system

};

//Output object members values

print $my_object.time; //14:27:32

print VS_EOL; //\n

print $my_object.date; //2023-01-06

print VS_EOL;

print $my_object.os; //V-ELOSX or Windows …

Object that declare another object:

$person = {

firstName : "Hodjat",

lastName: "Toraby",

age: 55,

addr: {

"streetAddress": "42 Golfam St. Nelson Mandela St.",

city: "Tehran",

state : "TH",

postalCode : 1915673873

}; //Don't forget the semi-colon here

print $person.addr.city; //Tehran

print VS_EOL;

print $person.addr.postalCode; // 1915673873

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

6.12 Bracket notation


Bracket notation or subscript operator is used to access JSON array
fields where their keys are usually numeric and are automatically
assigned by the underlying "VeestaScript" virtual machine.
The notation is

$array_name[expr];

Example:

//Declare a JSON array with three fields

$my_array = [ __TIME__, __DATE__, VS_OS ];

print $my_array[0]; //14:24:05

print VS_EOL;

print $my_array[1]; //2023-01-06

print VS_EOL;

print $my_array[2]; //V-ELOSX

The subscript operator is used also to populate JSON objects/arrays


with new members (i.e. Key/Value pair) after their instantiation as
follows:

//Declare an empty JSON object

$my_info = {};

//Populate the object

$my_info['name'] = 'Hodjat Toraby';

$my_info['age'] = 55;

print $my_info; // { "name" : "Hodjat Toraby", "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

6.13 JSON Array/Object Operators

Table 6-6: VeestaScript JSON Array/Object Operators


Operator Usage Description
+ Union Union of two JSON array or object.
== Equality TRUE if the two object have the same key/value pairs.
!= Inequality TRUE if $y is not equal to $y.

Example:

//Declare two JSON objects and perform their union.

$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;

$c = $b + $a; // Union of $b and $a


print "Union of \$b and \$a: \n";
print $c;
When running, you should see something like that:

Union of $a and $b:


{ "a" : "apple", "b" : "banana", "c": "cherry" }
Union of $b and $a:
{ "a" : "pear", "b" : "strawberry", "c" : "cherry" }

The "VeestaScript" standard library includes a set of useful


functions for working with JSON arrays and objects (i.e. sorting,
merging, diff functions and so forth). Refer to the built-in functions
page for additional information.

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

6.14 Comma Operator


A comma expression contains two operands of any type separated
by a comma and has left-to-right associatively. The left operand is
fully evaluated, possibly producing side effects, and its value, if there
is one, is discarded. The right operand is then evaluated. The type
and value of the result of a comma expression are those of its right
operand, after the usual unary conversions.

Any number of expressions separated by commas can form a single


expression because the comma operator is associative. The use of
the comma operator guarantees that the sub-expressions will be
evaluated in left-to-right order, and the value of the last becomes the
value of the entire expression.

The following example assign the value 25 to the variable $a,


multiply the value of $a with 2 and assign the result to variable $b
and finally we call a test function to output the value of $a and $b.
Keep-in mind that all theses operations are done in a single
expression using the comma operator.

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*/
}

The primary use of comma expressions is to produce side effects in


the following situations:
 Calling a function
 Entering an iteration loop
 Testing a condition

In some contexts where the comma character is used, parentheses


are required to avoid ambiguity.

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

6.15 Operators Precedence


The precedence of operators determines the order they are applied
when evaluating an expression. You can override operator
precedence by using parentheses.
The following table describes the precedence of operators, from
highest to lowest.

Table 6-7: VeestaScript Operators Precedence


Operator Name Operator
Member Access . []
Function Call ()
Increment/Decrement ++ --
Unary/Negation -+!~
Type Cast (int) (string) (float) (bool)
Multiply/Divide/Modulo */%
Addition/Subtraction/Concatenation + - ..
Bitwise shift << >>
Relational > >= < <=
Equality <>
Equality == != === !==
Bitwise-and &
Bitwsise-xor ^
Bitwise-or |
Logical and &&
Logical or ||
Ternary ?:
Assignment = += -= *= /= %= .= &= |= ^= <<= >>=
Comma ,

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;

Block statements are commonly used with control flow statements


(i.e. if, for, while) as follows:

$x = 0;

while( $x++ < 5 ){

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.

7.2.1 if..else..else if..elseif


Use the if statement to execute a statement if a logical condition is
true. Use the optional else clause to execute a statement if the
condition is false. You may also compound the statements using else
if or elseif to have multiple conditions tested in sequence.
An if statement looks as follows:
if (condition)

statement_1

[else if (condition_2)

statement_2]

...

[elseif (condition_n_1)

statement_n_1]

[else

statement_n]

condition can be any expression that evaluates to true or false. If


condition evaluates to true, statement_1 is executed; otherwise,
statement_2 is executed. statement_1 and statement_2 can be any
statement, including further nested if statements.
To execute multiple statements, use a block statement ({ ... }) to
group those statements. In general, it is a good practice to always
use block statements, especially in code involving nested if
statements:

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 ){

print "\$x is greater than \$y\n";

}elseif ($x < $y ){

print "\$x is smaller than \$y\n";

}else{

print "\$x and \$y are equals\n";

7.3 While Statement


while loops are the simplest type of loop in "VeestaScript". They
behave just like their C counterparts. The basic form of a while
statement is:

while (expr)
statement

The meaning of a while statement is simple. It tells "VeestaScript" to


execute the nested statement(s) repeatedly, as long as the while
expression evaluates to TRUE. The value of the expression is
checked each time at the beginning of the loop, so even if this value
changes during the execution of the nested statement(s), execution
will not stop until the end of the iteration (each time "VeestaScript"
runs the statements in the loop is one iteration). Sometimes, if the
while expression evaluates to FALSE from the very beginning, the
nested statement(s) won't even be run once.

Example:

//Loop until $x >= 5

$x = 0;

while( $x++ < 5 ){

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

7.4 For Statement


for statement are one of the most powerful looping mechanism in
"VeestaScript". They behave like their C counterparts. The syntax of
a for loop is:

for (init_expr; cond_expr; post_expr)


statement

The first expression (init_expr) is evaluated (executed) once


unconditionally at the beginning of the loop.
In the beginning of each iteration, cond_expr is evaluated. If it
evaluates to TRUE, the loop continues and the nested statement(s)
are executed. If it evaluates to FALSE, the execution of the loop ends.
At the end of each iteration, post_expr is evaluated (executed).
Each of the expressions can be empty or contain multiple
expressions separated by commas. In cond_expr, all expressions
separated by a comma are evaluated but the result is taken from the
last part. cond_expr being empty means the loop should be run
indefinitely ("VeestaScript" implicitly considers it as TRUE, like C).
This may not be as useless as you might think, since often you'd
want to end the loop using a conditional break statement instead of
using the for truth expression.

/* 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

7.5 Break/Continue statements


break ends execution of the current for, foreach, while or switch
structure.
break accepts an optional numeric argument which tells it how many
nested enclosing structures are to be broken out of.
Example:

/* Using the optional argument. */


$i = 0;
while (++$i) {
switch ($i) {
case 5:
print "At 5\n";
break 1; /* Exit only the switch. */
case 10:
print "At 10; quitting\n";
break 2; /* Exit the switch and the while. */
default:
break;
}
}

continue is used within looping structures to skip the rest of the


current loop iteration and continue execution at the condition
evaluation and then the beginning of the next iteration.
continue accepts an optional numeric argument which tells it how
many levels of enclosing loops it should skip to the end of.
Note: continue 0; and continue 1; is the same as running continue;.
Example:
$i = 0;
while ($i++ < 5) {
print "Outer\n";
while (1) {
print "Middle\n";
while (1) {
print "Inner\n";
continue 3;
}
print "This never gets output.\n";
}
print "Neither does this.\n";
}

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

7.6 Foreach statement


The foreach construct simply gives an easy way to iterate over JSON
arrays or objects. foreach works only on arrays and objects, and will
issue a run-time warning when you try to use it on a variable with a
different data type or an uninitialized variable. There are two
syntaxes; the second is a minor but useful extension of the first:

foreach (array_or_object_expr as $value)


statement;

foreach ( array_or_object_expr as $key , $value)


statement;

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

foreach( $person as $key, $value ){


print "$key ==> $value\n";
}

Example2:

/* Iterate over a JSON array */


foreach( [5,6,7,8,9,10] as $value ){
print "$value\n";
}

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

7.7 Switch statement


A switch statement allows a program to evaluate an expression and
attempt to match the expression's value to a case label. If a match is
found, the program executes the associated statement.
A switch statement looks as follows:

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.

The optional break statement associated with each case clause


ensures that the program breaks out of switch once the matched
statement is executed and continues execution at the statement
following switch. If break is omitted, the program continues execution
at the next statement in the switch statement.

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

Note: Unlike some other languages, the continue statement applies


to switch and acts similar to break. If you have a switch inside a loop
and wish to continue to the next iteration of the outer loop, use
continue 2.

Example:

$i = 'banana';

switch ($i) {

case "apple":

print "i is apple";

break;

case "banana":

print "i is banana";

break;

case "cake":

print "i is cake";

break;

7.8 Return statement


If called from within a function, the return() statement immediately
ends execution of the current function, and returns its argument as
the value of the function call.
If called from the global scope, then execution of the current script
file is ended. If the current script file was include()ed or import()ed,
then control is passed back to the calling file. Furthermore, if the
current script file was include()ed, then the value given to return()
will be returned as the value of the include() call.
Note: If no parameter is supplied, then NULL is returned to the caller.

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

7.9 Language Constructs


The "VeestaScript" language constructs resemble to a standard
function except that you do not need parenthesis to invoke them.
These constructs are:

print

print expr[, expr];

The print construct is used to output one or more expressions to the


default VM output consumer callback.

die

die [expr];

This construct when invoked output a message if available and


terminate the current script.

Example:

die;

die 'Giving Up!!';

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)

return $number * $number;

The same function could be declared using the type hinting feature
as follows:

function square(int $number)

return $number * $number;

With type hinting, arguments are automatically and silently converted


to the desired type, here the integer type in our example.
Scalar parameters values (integer, string, floats and boolean) are
passed to functions by value; the value is passed to the function, but
if the function changes the value of the parameter, this change is not
reflected globally or in the calling function.

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

If you pass a JSON object or a JSON array, and the function


changes the object's properties, that change is visible outside the
function. This is called pass by reference.
A function can be recursive; that is, it can call itself. For example,
here is a function that computes factorials recursively:

function factorial(int $num){

if( $num == 0 || $num == 1 )

return 1;

else

return $num * factorial($num – 1);

print factorial(5); //120

 Note: The recursion limit (i.e. Total number of times a function


may call itself) in "VeestaScript" is controlled to 128 times.
 Note: Function names under "VeestaScript" are case-sensitive
which mean that Foo() and foo() are completely different.

"VeestaScript" supports the concept of variable functions. This


means that if a variable name has parentheses appended to it,
"VeestaScript" will look for a function with the same name as
whatever the variable evaluates to, and will attempt to execute it.
Among other things, this can be used to implement callbacks,
function tables, and so forth.

Example

function hello(string $name)


{
print "Hello $name\n";
}
//Assign the function name to the variable $x
$x = 'he'..'llo';
//Invoke whatever $x evaluate to
$x('Dean'); //Hello Dean

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

8.2 Function Arguments

Information may be passed to functions via the argument list, which


is a comma-delimited list of expressions.

A function may define C++-style default values for its arguments


which can be any complex expression including function call.

Example:

function test(string $name = 'user_id_'..rand_str(4), int $age = 10 * 2 + 5)

print "Name = $name\n";

print "Age = $age\n";

/* Call without arguments */

test(); /* You should see: name = user_id_resr age = 25 */

/* Call with a single argument */

test('Me'); /* You should see: name = Me age = 25 */

No special syntax is required, and argument lists may still be


explicitly provided with function definitions and will behave as normal.

8.3 Returning values


Refer to the section 7.8 Return statement for detail descriptions.

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

8.4 Anonymous Function


Anonymous functions, also known as lambda, allow the creation of
functions which have no specified name. They are most useful as the
value of callback parameters, but they have many other uses.
Anonymous functions are declared exactly like a standard function
but without the associated identifier (i.e. The function name).

Example:

$greet = function($name)

printf("Hello %s\n", $name);

};

$greet('World'); //Hello World

Like any other expressions, anonymous function can be passed as


an argument to a function as follows:

function main($callback)

if( !is_callable($callback) )

print "Not callable\n";

else

//Invoke the given callback

$callback();

//Pass a simple callback that display a greeting message

main(function(){ print "Hello World\n"; }); //Hello world

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

8.5 Function overloading


Function overloading is a feature found in various programming
languages such as C++ or Java, that allows creating several function
and/or methods with the same name which differ from each other in
the type of the input and the output of the function. It is simply
defined as the ability of one function to perform different tasks. (src:
Wikipedia)

Function overloading means two or more functions can have the


same name but either the number of arguments or the data type of
arguments has to be different.

"VeestaScript" has support for this powerful mechanism. That is,


you define two ore more standard "VeestaScript" functions with the
same name but with different arguments number and/or signature
and finally you perform a simple function call and let "VeestaScript"
peek the appropriate function for this context.

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

Chapter 9 - Built-In Functions

9.1 Introduction

The following chapter enumerates all built-in "VeestaScript"


functions and constants. As of this release, there are a total more
than 87 functions.

The Built-In functions will be updated by any new release of


"VeestaScript" service. They are categorized as bellow section:

1- Variable Handling Functions


2- Mathematical Functions
3- String Handling Functions
4- Time Functions
5- Cryptography Functions
6- Real-time Database Functions

Page 61 of 96
V-RTU2000 - Series VR-2400 Chapter 9 - Built-In Functions
Veesta - Remote Terminal Unit and Controller
VeestaScript Programming Language Manual

9.2 Variable Handling Functions


9.2.1 is_bool
bool is_bool($var)
Finds out whether a variable is a boolean.

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

9.3 Mathematical Functions


9.3.1 abs
float abs(float $arg)
int abs(int $arg)
Determine Absolute value.

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

9.4 String Handling Functions


9.4.1 strlen
int strlen($string)
Return the length of the given string

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

9.5 Time Functions


9.5.1 time
int64 time()
Current EPOCH timestamp

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 ]]]]]]] )

Returns the Unix timestamp corresponding to the arguments


given. This timestamp is a 64 bit integer containing the number
of seconds between the Unix Epoch (January 1 1970 00:00:00
GMT) and the time specified. Arguments may be left out in order
from right to left; any arguments thus omitted will be set to the
current value according to the local date and time

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

$year: The number of the year, may be a two or four digit


value, with values between 0-69 mapping to 2000-
2069 and 70-100 to 1970-2000.
$is_dst: This parameter can be set to 1 if the time is during
daylight savings time (DST), 0 if it is not, or -1 (the
default) if it is unknown whether the time is within
daylight savings time or not

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

9.6 Cryptography Functions


9.6.1 md5
string md5(string $str[, bool $ raw_output = false ])
Calculate the md5 hash of a string

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 Real-time Database Functions


In this Chapter, you will get acquainted with various functions related
to the connection with the database of the remote terminal system
VR2000.
These functions, which will be accessible in the VR2000 application,
allow you to access telemetry points collected through other
protocols on the VR2000 platform. Such as receiving the status of a
digital input signal or the value of an analog input signal, or even
receiving commands or sending telemetry commands are other
features that real-time database functions offer you.

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 )

Set the specific point by reference address of ComId, PntType,


PntId to the new value by 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

Any error like problem is addressing the point or specify invalid


PntType and other mistakes or not possible to change the point
value function return FALSE.

NOTE: Calling SetPnt() with point addressing to the ports that


have normal operation like master or slave ports of protocols like
Modbus or DNP3 and etc. may dose not have any effect,
because of the original point value will be overwrite on your new
writing value on the process of protocol port, so it is
recommended that call SetPnt() on the pseudo point on
database.

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

You might also like