Easy Logic. Scripting Language Description PDF
Easy Logic. Scripting Language Description PDF
Easy Logic. Scripting Language Description PDF
Scripting
language description
www.galileosky.com
Easy Logic. Scripting language description
Contents
Introduction...................................................................................................................................4
Structure of the program.............................................................................................................4
Variables declaration..................................................................................................................5
Arrays and strings........................................................................................................................6
Functions.......................................................................................................................................8
Rational numbers.........................................................................................................................9
Built-in functions of scripting language....................................................................................10
Functions working with global variables............................................................................12
Functions for working with tags...........................................................................................13
Functions for working with serial ports RS232 and RS485..............................................14
Functions to work with microSD card file system...............................................................16
Functions for CRC calculation.............................................................................................19
Functions for CAN-bus processing.....................................................................................20
Other functions......................................................................................................................23
Appendix A. List of predefined global variables....................................................................24
Appendix B. List of tag IDs in scripting language context......................................................34
Easy Logic. Scripting language description
Introduction
For scripts programming in Configurator, C-like scripting language is used. It has some
special features in operation that will be considered in current manual.
main()
Diagnostics("Hello world")
3
Easy Logic. Scripting language description
Variables declaration
32-bit integer variables are used in the language.
Inside the variable big-endian format of reading is used (older bytes come first). To declare
a new variable, operator new followed by the name of the variable is used. Variables
should be declared before being used in expressions. Also variable value can be initialized
when being declared:
main()
const STATE_NOT_CONNECTED = 0
4
Easy Logic. Scripting language description
Index linking starts with 0 element. An array is a sequence of 32-bit words, access to which
is provided with square brackets [].Each word consists of 4 bytes, that is why to decrease
memory consumption you can use byte-serial access with the help of curly braces {}, it
allows to use an array as a sequence of bytes. As well as regular variables, an array can be
declared as a constant and/or can be initialized.
new oBuf{PORT_BUF_SIZE} //Array declaration with a size of 245 bytes and memory
consumption of 245/4 => 62 elements (32-bit words)
new cBuf[10] //Array declaration with a size of 10 elements 32-bit words), which is 10*4 =>
40 bytes
new const fMap_fAttr[2] = [0x20000, 0x50000] // Declaration of constant array with its
initialization
oBuf[1] = 0x5028100 // Value 0x5028100 assignment to the 1st element of the same array,
it will be equivalent to the following actions:
//oBuf{4} = 0x05
//oBuf{5} = 0x02
//oBuf{6} = 0x81
//oBuf{7} = 0x00
cBuf{1} = 0x5 // Equivalent to the following record (attention, 4 bytes are recorded at
once): cBuf[0] = 0x00050000
5
Easy Logic. Scripting language description
new e[2][] = [ "OK", "Cancel" ] // 2-dimensional array with subarrays with different length. e[1]
[5] contains letter "l", but e[0][5] is invalid element, as subarray length is equal to 3 ("O", "K", "\
0")
To find a size of an array - operator sizeof is used. It returns the number of elements (32-bit
words), but not bytes. For multi-dimensional arrays calling of such operator with array name
without brackets will return the main dimensions, with brackets – subarray dimensions:
new matrix[3][2] = { { 1, 2 }, { 3, 4 }, { 5, 6 } }
Diagnostics("%d %d", sizeof matrix, sizeof matrix[]); //Diagnostics will show a line 3 2
6
Easy Logic. Scripting language description
Functions
To declare a function enter its name, accepted arguments and its body in curly braces. The
order of a function declaration is not important. A function can both return values (operator
return <value> is used), or not return.
main()
//Custom function
myFunc(a, b)
a += 2
By default, arguments are sent to function by value, meaning that any changes of the value
in the function will not affect the value of the source variable. But they can also be sent by
reference. For this operator & is used when arguments are declared:
//Custom function
...
7
Easy Logic. Scripting language description
Array sending to function is automatically done only by reference. In order to do this you
should enter array variable when declaring the arguments:
myArrayFunc(buf{}, size)
main()
myArrayFunc(buf, 3)
Rational numbers
Current script language build doesn’t support operations with rational numbers. Only integer
operations can be used. Example of integer operations for calculation of expression
Pressure=Р*5,5-101,3 kPa and its translation to psi with rounding to whole numbers:
// ioBuf{7} - array element with encoded pressure value received from the sensor
p += 5
p /= 10
8
Easy Logic. Scripting language description
Maximum number of shown variables with one command is 2. If there are more operands-
variables, the result of display will be unpredictable.
Diagnostics("Tracker time: %d. Tracker status: %d", time, status) //What will be shown: Tracker
time: 946687968. Tracker status: 14848
new value = 14
9
Easy Logic. Scripting language description
// Showing hexadecimal values in diagnostics from the buf buffer with size determined by
variable size
printData(buf{}, size)
Delay(10)
if (size % 2)
Diagnostics("%02X", buf{size-1})
Delay(timeout)
DisablePulseCounting(inputNum, disabled)
10
Easy Logic. Scripting language description
SetOutputValue(outputNum, value)
value – output control: 1 – output closed; 0 – output opened and connected to the
ground.
SavePoint()
new time = GetVar(UNIX_TIME) //Reading predefined global variable containing unix time
new value = 56
11
Easy Logic. Scripting language description
TagWriteValue(tagId, value)
swapBuf(buf, size)
12
Easy Logic. Scripting language description
In order to make correct answer arrays are needed. Both arrays (reply text and extra data)
should be transformed from big-endian into little-endian, as well as array tag, for example,
using swapBuf function.
Command format:
dataSize – size of the array with additional data in bytes. If the data is not required
to be sent, size is set as 0.
swapBuf(oBuf, oBufSize)
13
Easy Logic. Scripting language description
For RS485 bus handler method is used, i.e. besides script the bus can interact with other
processes, e.g. the process of receiving photos from the camera, processing RFID-readers,
etc. The terminal cyclically changes handlers, waiting for completion of each of them, and
after entering the script – waits until it leaves it. So if only Easy Logic work with port is
required, e.g. when the terminal is a slave device, run an infinite cycle inside script so that it
will never complete.
main ()
PortWrite(PORT_INDEX, oiBuf, b_size) //Writing into port a buffer oiBuf with size
equal to b_size bytes
oiBuf{bytesRead} = c
bytesRead++
//Processing the received message using buffer oiBuf with a size equal to bytesRead
14
Easy Logic. Scripting language description
FileSize(const filename[])
• offset – offset from the file beginning, starting from where the data will be read.
15
Easy Logic. Scripting language description
• offset – offset from the file beginning, starting from where the data will be written. If
-1 is set, data will be written in the end of the file.
FileDelete(const filename[])
Example:
main()
16
Easy Logic. Scripting language description
const buf_1_len = 5;
const buf_2_len = 4;
const four_bytes_buff = 4;
new start_pos = 0;
new write_bytes = 0;
if (buf_1_len == write_bytes)
Diagnostics("Write success");
else
Diagnostics("Write fail");
new read_bytes = 0;
17
Easy Logic. Scripting language description
if (tmp_buf_len == read_bytes)
Diagnostics("Read success");
else
Diagnostics("Read fail");
}
}
Example:
#define MSG_SIZE 10
new msg{MSG_SIZE} = {0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x13, 0x4B, 0x13}
main()
new crc
//CRC 8
18
Easy Logic. Scripting language description
// CRC 16
main()
new canMessage[CANMSG]
canMessage.id = 0xFFFFFFFF
canMessage.dataSize = 8
canMessage.data[0] = 0x11223344
canMessage.data[1] = 0x55667788
CANInit(speed, active)
19
Easy Logic. Scripting language description
CANEnableReception(enable)
• id – CAN-message identifier.
new canMessage[CANMSG]
CANSend(canMessage)
new canMessage[CANMSG]
CANReceive(canMessage)
1. Receiving messages
main()
Delay(4000)
new can_message[CANMSG]
new in = CANInit(250000, 0)
CANSetFilter(0x1AF, 0, 0)
20
Easy Logic. Scripting language description
CANEnableReception(1)
while(1)
if(CANReceive(can_message))
{ DiagnosticsHex(can_message.data, 8) }
2. Sending messages
main()
Delay(5000)
new canMessage[CANMSG]
canMessage.id = 0x18DAEEF1
canMessage.idType = 1
canMessage.dataSize = 8
CANInit(250000, 1)
CANSetFilter(0, 0, 1)
CANEnableReception(1)
canMessage.data[0] = 0x02107E00
canMessage.data[1] = 0x00000000
if (!res)
21
Easy Logic. Scripting language description
Other functions
getIntFromBuf – receiving a 32-bit number from an array
Function returns 32-bit number constructed from elements, starting from the following:
22
Easy Logic. Scripting language description
23
Easy Logic. Scripting language description
24
Easy Logic. Scripting language description
25
Easy Logic. Scripting language description
26
Easy Logic. Scripting language description
27
Easy Logic. Scripting language description
28
Easy Logic. Scripting language description
29
Easy Logic. Scripting language description
30
Easy Logic. Scripting language description
31
Easy Logic. Scripting language description
32
Easy Logic. Scripting language description
33
Easy Logic. Scripting language description
34