The leader in industrial automation and control solutions

Function Blocks

Function blocks are useful for reducing repetitive codes. It must be defined before use and supports any variable and statement type. A function block could be called by putting its name followed by parameters in parenthesis. After the function block is executed, it returns the value to the caller function where it is used as an assignment value or as a condition.

A return type is not required in function definition, which means that a function block does not have to return a value. The parameters can also be ignored in function definition while the function has no need to take any parameters from the caller.

The syntax is as follows:

Function definition with return type

sub type <name> [(parameters)]
Local variable declarations
[Statements]
[return [value]]
end sub

Example:

sub int Add(int x, int y)

int result

result = x +y

return result

end sub

macro_command main()

int a = 10, b = 20, sum

sum = Add(a, b)

end macro_command

or:

sub int Add()

int result, x=10, y=20

result = x +y

return result

end sub

macro_command main()

int sum

sum = Add()

end macro_command

Function definition without return type

sub <name> [(parameters)]
Local variable declarations
[Statements]
end sub

Example:

sub Add(int x, int y)

int result

result = x + y

end sub

macro_command main()

int a = 10, b = 20

Add(a, b)

end macro_command

or:

sub Add()

int result, x=10, y=20

result = x +y

end sub

macro_command main()

Add()

end macro_command

Syntax Description

subMust be used to begin the function block
typeOptional. This is the data type of value that the function returns. A function block is not always necessary to return a value.
(parameters)Optional. The parameters hold values that are passed to the function. The passed parameters must have their type declared in the parameter field and assigned a variable name.

For example: sub int MyFunction(int x, int y). x and y would be integers passed to the function. This function is called by a statement that looks similar to this: ret = MyFunction(456, pressure) where “pressure” must be integer according to the definition of function.

Notice that the calling statement can pass hard coded values or variables to the function. After this function is executed, an integer values is return to ‘ret’.
Local variable declarationVariables that are used in the function block must be declared first. This is in addition to passed parameters. In the above example x and y are variables that the function can used. Global variables are also available for use in function block.
[Statements]Statements to execute
[return [value]]Optional. Used to return a value to the calling statement. The value can be a constant or a variable. Return also ends function block execution. A function block is not always necessary to return a value, but, when the return type is defined in the beginning of the definition of function, the return command is needed.
end subMust be used to end a function block.

Built-In Function Block

EasyBuilder Pro has many built-in functions for retrieving and transferring data to the devices, data management and mathematical functions.

Device Functions

Function NameDescription
GetDataReceives data from the device.
GetDataExReceives data from the device and continues executing next
command even if there’s no response from the device.
GetErrorGets an error code.
SetDataSends data to the device.
SetDataExSends data to the device and continues executing next
command even if there’s no response from the device.

GetData

NameGetData
SyntaxGetData(read_data[start], device_name, device_type, address_offset, data_count)
or
GetData(read_data, device_name, device_type, address_offset, 1)
DescriptionReceives data from the device. When the data is not read successfully, the function will not continue executing the next command. Data is stored into read_data[start]~ read_data[start + data_count – 1].

data_count is the amount of received data. In general, read_data is an array, but if data_count is 1, read_data can be an array or an ordinary variable. Below are two methods to read one word data from the device.

macro_command main()
short read_data_1[2], read_data_2
GetData(read_data_1[0], “FATEK KB Series”, RT, 5, 1)

GetData(read_data_2, “FATEK KB Series”, RT, 5, 1)
end macro_command

Device_name is the device name enclosed in the double quotation marks (“) and this name has been defined in the device list of system parameters.

Device_type is the device type and encoding method (binary or BCD) of the device data. For example, if device_type is LW_BIN, it means the register is LW
and the encoding method is binary. If use BIN encoding method, “_BIN” can be ignored.

If device_type is LW_BCD, it means the register is LW and the encoding method is BCD.

Address_offset is the address offset in the device.
For example, GetData(read_data_1[0], “FATEK KB Series”, RT, 5, 1) represents that the address offset is 5.

If address_offset uses the format –”N#AAAAA”, N indicates that device’s station number is N. AAAAA represents the address offset. This format is used while multiple devices or controllers are connected to a single serial port.

For example, GetData(read_data_1[0], “FATEK KB Series”, RT, 2#5, 1) represents that the device’s station number is 2. If GetData() uses the default station number defined in the device list as follows, it is not necessary to define station number in address_offset.

The number of registers actually read from depends on both the type of the
read_data variable and the value of the number of data_count.

When a GetData() is executed using a 32-bit data type (int or float), the function will automatically convert the data.

For example,
macro_command main()
float f
GetData(f, “MODBUS”, 6x, 2, 1)      // f will contain a floating point value
end macro_command

Examplemacro_command main()
bool a
bool b_array[30]
char c
char c_array[20]
short s
short s_array[50]
int i
int i_array[10]
float f
float f_array[15]double g[10]


//    get the state of LB2 to the variable a
GetData(a, “Local HMI”, LB, 2, 1)

//    get 30 states of LB0 ~ LB29 to the variables b_array[0] ~ b_array[29] GetData(b_array[0], “Local HMI”, LB, 0, 30)

//    get lower byte of LW-0 to the variable c
//    note that char is 1 byte, and a LW address occupies 2 bytes (1 word). Reading the first byte in a word register will get the lower byte of the word.
//    Ex: when the value in LW-0 is 0x0201, then variable c will read 0x01 GetData(c, “Local HMI”, LW, 0, 1)

//    get data of LW1 ~ LW10 to the c_array[0] ~ c_array[19]
GetData(c_array[0], “Local HMI”, LB, 0, 20)

//    get one word from LW-2 to the variable s
GetData(s, “Local HMI”, LW, 2, 1)

//    get 50 words from LW-0 ~ LW-49 to the variables s_array[0] ~ s_array[49] GetData(s_array[0], “Local HMI”, LW, 0, 50)

//    get 2 words from LW-6 ~ LW-7 to the variable e
//    Ex: When value in LW-6 is 0x0002, in LW-7 is 0x0001, then i will read 0x00010002(65538)
//    note that int occupies 2 words (32-bit)
GetData(i, “Local HMI”, LW, 6, 1)

//    get 20 words (10 integer values) from LW-0 ~ LW-19 to variables i_array[0]
~ i_array[9], note that type of i_array[10] is int.
GetData(i_array[0], “Local HMI”, LW, 0, 10)

//    get data from LW-10 ~ LW-11 to the variable f
//    note that type of variable f is float.
GetData(f, “Local HMI”, LW, 10, 1)

//    get 30 words (15 float variables) from LW-0 ~ LW-29 to variables f_array[0]
~ f_array[14], note that type of f_array[15] is float.
//    note that float occupies 2 words (32-bit)
GetData(f_array[0], “Local HMI”, LW, 0, 15)

end macro_command

GetDataEx

NameGetDataEx
SyntaxGetDataEx(read_data[start], device_name, device_type, address_offset, data_count)
or
GetDataEx(read_data, device_name, device_type, address_offset, 1)
DescriptionReceives data from the device and continues executing next command even when the read operation fails.

Descriptions of read_data, device_name, device_type, address_offset and
data_count are the same as GetData.
Examplemacro_command main()
bool a
bool b
bool b_array[30]
char c
char c_array[20]
short s
short s_array[50]
int i
int i_array[10]
float f
float f_array[15]

//    get the state of LB2 to the variable a
GetDataEX(a, “Local HMI”, LB, 2, 1)

//    get 30 states of LB0 ~ LB29 to the variables b_array[0] ~ b_array[29] GetDataEX(b_array[0], “Local HMI”, LB, 0, 30)

//    get lower byte of LW-0 to the variable c
//    note that char is 1 byte, and a LW address occupies 2 bytes (1 word).
Reading the first byte in a word register will get the lower byte of the word.
//    Ex: when the value in LW-0 is 0x0201, then variable c will read 0x01
GetDataEX(c, “Local HMI”, LW, 0, 1)

//    get data of LW1 ~ LW10 to the c_array[0] ~ c_array[19]
GetDataEX(c_array[0], “Local HMI”, LB, 0, 20)

//     get one word from LW-2 to the variable s
GetDataEX(s, “Local HMI”, LW, 2, 1)

//    get 50 words from LW-0 ~ LW-49 to the variables s_array[0] ~ s_array[49] GetDataEX(s_array[0], “Local HMI”, LW, 0, 50)

//    get 2 words from LW-6 ~ LW-7 to the variable e
//    Ex: When value in LW-6 is 0x0002, in LW-7 is 0x0001, then i will read 0x00010002(65538)
//    note that int occupies 2 words (32-bit)
GetDataEX(i, “Local HMI”, LW, 6, 1)

//    get 20 words (10 integer values) from LW-0 ~ LW-19 to variables i_array[0]
i_array[9], note that type of i_array[10] is int.
GetDataEX(i_array[0], “Local HMI”, LW, 0, 10)

//    get data from LW-10 ~ LW-11 to the variable f
//    note that type of variable f is float.
GetDataEX(f, “Local HMI”, LW, 10, 1)

//    get 30 words (15 float variables) from LW-0 ~ LW-29 to variables f_array[0]
f_array[14], note that type of f_array[15] is float.
//    note that float occupies 2 words (32-bit)
GetDataEX(f_array[0], “Local HMI”, LW, 0, 15)

end macro_command

GetError

NameGetError
SyntaxGetError (err)
DescriptionGets an error code.
Examplemacro_command main()
short err
char byData[10]
 
GetDataEx(byData[0], “MODBUS RTU”, 4x, 1, 10)// read 10 bytes
 
// if err is equal to 0, it is successful to execute GetDataEx()
GetErr(err)// save an error code to err

end macro_command

Error code:
0: Normal
1: GetDataEx error
2: SetDataEx error

SetData

NameSetData
SyntaxSetData(send_data[start], device_name, device_type, address_offset, data_count)
or
SetData(send_data, device_name, device_type, address_offset, 1)
DescriptionSends data to the device. When the data is not written successfully, the function will not continue executing the next command. Data is defined in send_data[start]~ send_data[start + data_count – 1].

data_count is the amount of sent data. In general, send_data is an array, but if data_count is 1, send_data can be an array or an ordinary variable. Below are two methods to send one word data.

macro_command main()
short send_data_1[2] = { 5, 6}, send_data_2 = 5
SetData(send_data_1[0], “FATEK KB Series”, RT, 5, 1)

SetData(send_data_2, “FATEK KB Series”, RT, 5, 1)
end macro_command

device_name is the device name enclosed in the double quotation marks (“) and this name has been defined in the device list of system parameters. device_type is the device type and encoding method (binary or BCD) of the device data. For example, if device_type is LW_BIN, it means the register is LW and the encoding method is binary. If use BIN encoding method, “_BIN” can be ignored.
If device_type is LW_BCD, it means the register is LW and the encoding method is BCD.
address_offset is the address offset in the device.
For example, SetData(read_data_1[0], “FATEK KB Series”, RT, 5, 1) represents that the address offset is 5.
If address_offset uses the format –”N#AAAAA”, N indicates that device’s station number is N. AAAAA represents the address offset. This format is used while multiple devices or controllers are connected to a single serial port. For example, SetData(read_data_1[0], “FATEK KB Series”, RT, 2#5, 1) represents that the device’s station number is 2. If SetData () uses the default station number defined in the device list, it is not necessary to define station number in address_offset.

The number of registers actually sends to depends on both the type of the
send_data variable and the value of the number of data_count.

When a SetData() is executed using a 32-bit data type (int or float), the function will automatically send int-format or float-format data to the device.

For example,
macro_command main()
float f = 2.6
SetData(f, “MODBUS”, 6x, 2, 1)      // will send a floating point value to the device
end macro_command
Examplemacro_command main()
int i
bool a = true
bool b[30]
short c = false
short d[50]
int e = 5
int f[10]
 
for i = 0 to 29
b[i] = true
next i
 
for i = 0 to 49
d[i] = i * 2
next i
 
for i = 0 to 9
f [i] = i * 3
next i

// set the state of LB2
SetData(a, “Local HMI”, LB, 2, 1)
 
//    set the states of LB0 ~ LB29
SetData(b[0], “Local HMI”, LB, 0, 30)
 
//    set the value of LW-2
SetData(c, “Local HMI”, LW, 2, 1)

//    set the values of LW-0 ~ LW-49
SetData(d[0], “Local HMI”, LW, 0, 50)
 
//    set the values of LW-6 ~ LW-7,   note that the type of e is int
SetData(e, “Local HMI”, LW, 6, 1)
 
//    set the values of LW-0 ~ LW-19
// 10 integers equal to 20 words, since each integer value occupies 2 words. SetData(f[0], “Local HMI”, LW, 0, 10)
 
end macro_command

SetDataEx

NameSetDataEx
SyntaxSetDataEx (send_data[start], device_name, device_type, address_offset, data_count)
or
SetDataEx (send_data, device_name, device_type, address_offset, 1)
DescriptionSends data to the device and continues executing next command even when the write operation fails.
Descriptions of send_data, device_name, device_type, address_offset and
data_count are the same as SetData.
Examplemacro_command main()
int i
bool a = true
bool b[30]
short c = false
short d[50]
int e = 5
int f[10]

for i = 0 to 29
b[i] = true
next i

for i = 0 to 49
d[i] = i * 2
next i
 
for i = 0 to 9
f [i] = i * 3
next i

// set the state of LB2
SetDataEx (a, “Local HMI”, LB, 2, 1)

//    set the states of LB0 ~ LB29
SetDataEx (b[0], “Local HMI”, LB, 0, 30)

//    set the value of LW-2
SetDataEx (c, “Local HMI”, LW, 2, 1)

//    set the values of LW-0 ~ LW-49
SetDataEx (d[0], “Local HMI”, LW, 0, 50)

//    set the values of LW-6 ~ LW-7,   note that the type of e is int
SetDataEx (e, “Local HMI”, LW, 6, 1)

//    set the values of LW-0 ~ LW-19
// 10 integers equal to 20 words, since each integer value occupies 2 words. SetDataEx (f[0], “Local HMI”, LW, 0, 10)

end macro_command

Free Protocol Functions

GetCTSGets CTS signal of RS-232.
INPORTReads data from a COM port or Ethernet port.
INPORT2Reads data from a COM port or Ethernet port and then wait for
a the designated period of time.
INPORT3Reads data from a COM port or Ethernet port according to the
specified data size.
INPORT4Reads data from a COM port or Ethernet port and then stops
reading data when the ending character is reached.
OUTPORTSends out the specified data to a device or controller via a COM
port or Ethernet port.
PURGEClears the input and output buffers associated with the COM
port.
SetRTSRaises or lowers the RTS signal of RS-232.

GetCTS

NameGetCTS
SyntaxGetCTS(com_port, result)
DescriptionGets CTS state for RS232.
com_port refers to the COM port number. It can be either a variable or a constant. result is used for receiving the CTS signal. It must be a variable.
This command receives CTS signal and stores the received data in the result
variable. When the CTS signal is pulled high, it writes 1 to result, otherwise, it writes 0.
Examplemacro_command main()
char com_port=1
char result
 
GetCTS(com_port, result) // get CTS signal of COM1

GetCTS (1, result) // get CTS signal of COM1

end macro_command

INPORT

NameINPORT
SyntaxINPORT(read_data[start], device_name, read_count, return_value)
DescriptionReads data from a COM port or the Ethernet port. The data is stored to
read_data[start]~ read_data[start + read_count – 1].

device_name is the name of a device defined in the device table and the device must be a “Free Protocol”-type device.

read_count is the required amount of reading and can be a constant or a variable.

If the function is used successfully to get sufficient data, return_value will
return the length of the read word.
ExampleBelow is an example of executing an action of reading holding registers of a MODBUS device.

//    Read Holding Registers
macro_command main()
char command[32], response[32]
short address, checksum
short read_no, return_value, read_data[2]

FILL(command[0], 0, 32) //    command initialization
FILL(response[0], 0, 32)

command[0] = 0x1//    station no
command[1] = 0x3//   function code : Read Holding Registers
address = 0
HIBYTE(address, command[2])
LOBYTE(address, command[3])

read_no = 2 //    read 2 words (4x_1 and 4x_2)
HIBYTE(read_no, command[4])
LOBYTE(read_no, command[5])

CRC(command[0], checksum, 6)

LOBYTE(checksum, command[6])
HIBYTE(checksum, command[7])

//    send out a ‘Read Holding Registers” command
OUTPORT(command[0], “MODBUS RTU Device”, 8)

//    read responses for a ‘Read Holding Registers” command
INPORT(response[0], “MODBUS RTU Device”, 9, return_value)

if return_value > 0 then
read_data[0] = response[4] + (response[3] << 8) //    data in 4x_1
read_data[1] = response[6] + (response[5] << 8) //    data in 4x_2

SetData(read_data[0], “Local HMI”, LW, 100, 2)
end if
 
end macro_command

INPORT2

NameINPORT2
SyntaxINPORT2(response[start], device_name, receive_len, wait_time)
DescriptionReads data from a COM port or the Ethernet port. The data read will be saved in the response array.

device_name is the name of a device defined in the device table and the device must be a “Free Protocol”-type device.
receive_len stores the length of the data received. It must be a variable.
receive_len can’t exceed the size of response array.
wait_time (in millisecond) can be a constant or variable. After the data is read, if there’s no upcoming data during the designated time interval, the function
returns.
Examplemacro_command main()
 
short wResponse[6], receive_len, wait_time=20

INPORT2(wResponse[0], “Free Protocol”, receive_len, wait_time)
// wait_time unit : millisecond

if receive_len > 0 then
SetData(wResponse[0], “Local HMI”, LW, 0, 6)
// set responses to LW0
end if
 
end macro_command

INPORT3

NameINPORT3
SyntaxINPORT3(response[start], device_name, read_count, receive_len)
DescriptionReads data from a communication port (COM Port or Ethernet Port). The data read will be saved in the response array.
The amount of data to be read can be specified. The data that is not read yet will be stored in HMI buffer memory for the next read operation, in order to prevent losing data.

device_name is the name of a device defined in the device table and the device must be a “Free Protocol”-type device.
read_count stores the length of the data read each time.
receive_len stores the length of the data received. It must be a variable.
receive_len can’t exceed the size of response array.
Examplemacro_command main()

short wResponse[6], receive_len

INPORT3(wResponse[0], “Free Protocol”, 6, receive_len)   // read 6 words

if receive_len >= 6 then

SetData(wResponse[0], “Local HMI”, LW, 0, 6)          // set responses to LW0

end if

end macro_command

INPORT4

NameINPORT4
SyntaxINPORT4(response[start], device_name, receive_len, tail_ascii)
DescriptionReads data from a communication port (COM Port or Ethernet Port). The data read will be saved in the response array.
tail_ascii specifies the ending character. Data reading will stop when the ending character is reached.

device_name is the name of a device defined in the device table and the device must be a “Free Protocol”-type device.
receive_len stores the length of the data received. It must be a variable.
receive_len can’t exceed the size of response array.
Examplemacro_command main()

char tail_ascii = 0x03// == ETX

short wResponse[1024], receive_len

INPORT4(wResponse[0], “Free Protocol”, receive_len, 0x0d) //     0x0d == CR

INPORT4(wResponse[0], “Free Protocol”, receive_len, tail_ascii)

if receive_len >= 6 then

SetData(wResponse[0], “Local HMI”, LW, 0, 6) //      set responses to LW0

end if

end macro_command

OUTPORT

NameOUTPORT
SyntaxOUTPORT(source[start], device_name, data_count)
DescriptionSends out the specified data from source[start] to source[start + data_count -1] to the device via a COM port or an Ethernet port.

device_name is the name of a device defined in the device table and the device must be a “Free Protocol”-type device.
data_count is the amount of sent data and can be a constant or a variable.
ExampleTo use an OUTPORT function, a “Free Protocol” device must be created first in System Parameters.

The device is named ”MODBUS RTU Device”. The port attribute depends on the setting of this device. (the current setting is “19200,E, 8, 1”)
 
Below is an example of executing an action of writing single coil (SET ON) to a MODBUS device.

macro_command main()

char command[32]
short address, checksum

FILL(command[0], 0, 32) //     command initialization

command[0] = 0x1 //    station no
command[1] = 0x5 //   function code : Write Single Coil

address = 0
HIBYTE(address, command[2])
LOBYTE(address, command[3])

command[4] = 0xff //    force bit on
command[5] = 0

CRC(command[0], checksum, 6)

LOBYTE(checksum, command[6])
HIBYTE(checksum, command[7])

//    send out a “Write Single Coil” command
OUTPORT(command[0], “MODBUS RTU Device”, 8)

end macro_command

PURGE

NamePURGE
SyntaxPURGE (com_port)
Descriptioncom_port refers to the COM port number which ranges from 1 to 3. It can be either a variable or a constant. This function is used to clear the input and output buffers associated with the COM port.
Examplemacro_command main()

int com_port=3

PURGE (com_port)

PURGE (1)

end macro_command

SetRTS

NameSetRTS
SyntaxSetRTS(com_port, source)
DescriptionSets RTS state for RS232.

com_port refers to the COM port number. It can be either a variable or a constant. source can be either a variable or a constant.

This command raise RTS signal while the value of source is greater than 0 and
lower RTS signal while the value of source equals to 0.
Examplemacro_command main()

char com_port=1
char value=1
 
SetRTS(com_port, value) // raise RTS signal of COM1 while value>0

SetRTS(1, 0) // lower RTS signal of COM1

end macro_command

Process Control Functions

ASYNC_TRIG_MACROTriggers the execution of a macro asynchronously in a running
macro.
SYNC_TRIG_MACROTriggers the execution of a macro synchronously in a running
macro. The current macro will pause until the end of execution of this called macro.
DELAYSuspends the execution of the current macro for at least the
specified interval (time).

ASYNC_TRIG_MACRO

NameASYNC_TRIG_MACRO
SyntaxASYNC_TRIG_MACRO (macro_id or name)
DescriptionTriggers the execution of a macro asynchronously (use macro_id or macro name to designate this macro) in a running macro.

The current macro will continue executing the following instructions after
triggering the designated macro; in other words, the two macros will be active simultaneously.

macro_id can be a constant or a variable.
Examplemacro_command main()

char ON = 1, OFF = 0

SetData(ON, “Local HMI”, LB, 0, 1)

ASYNC_TRIG_MACRO(5) //    call a macro (its ID is 5)

ASYNC_TRIG_MACRO(“macro_1”)        // call a macro (its name is macro_1)

SetData(OFF, “Local HMI”, LB, 0, 1)

end macro_command

SYNC_TRIG_MACRO

NameSYNC_TRIG_MACRO
SyntaxSYNC_TRIG_MACRO(macro_id or name)
DescriptionTriggers the execution of a macro synchronously (use macro_id or macro name to designate this macro) in a running macro.

The current macro will pause until the end of execution of this called macro.

macro_id can be a constant or a variable.
Examplemacro_command main()

char ON = 1, OFF = 0

SetData(ON, “Local HMI”, LB, 0, 1)

SYNC_TRIG_MACRO(5)      // call a macro (its ID is 5)

SYNC_TRIG_MACRO(“macro_1”)       // call a macro (its name is macro_1)

SetData(OFF, “Local HMI”, LB, 0, 1)

end macro_command

DELAY

NameDELAY
SyntaxDELAY(time)
DescriptionSuspends the execution of the current macro for at least the specified interval (time). The unit of time is millisecond.

time can be a constant or a variable.
Examplemacro_command main()

int time == 500
 
DELAY(100)//    delay 100 ms
DELAY(time)//   delay 500 ms
 
end macro_command

Data Operation Functions

FILLSets array elements to the specified value.
SWAPBExchanges the high-byte and low-byte data of a 16-bit (Word).
SWAPWExchanges the high-word and low-word data of a 32-bit (DINT).
LOBYTERetrieves the low byte of a 16-bit source.
HIBYTERetrieves the high byte of a 16-bit source.
LOWORDRetrieves the low word of a 32-bit source.
HIWORDRetrieves the high word of a 32-bit source.
INVBITInverts the state of designated bit position of a data source.
SETBITONChanges the state of designated bit position of a data source to 1.
SETBITOFFChanges the state of designated bit position of a data source to 0.
GETBITGets the state of designated bit position of a data source.

FILL

NameFILL
SyntaxFILL(source[start], preset, count)
DescriptionSets array elements from ‘source[start]’ to ‘source[start + count – 1]’ to the specified value (preset).
source and start must be a variable, and preset can be a constant or variable.
Examplemacro_command main()
char result[4]
char preset

FILL(result[0], 0x30, 4)
//    result[0] is 0x30, result[1] is 0x30, , result[2] is 0x30, , result[3] is 0x30

preset = 0x31
FILL(result[0], preset, 2) //    result[0] is 0x31, result[1] is 0x31

end macro_command

SWAPB

NameSWAPB
SyntaxSWAPB(source, result)
DescriptionExchanges the high-byte and low-byte data of a 16-bit source into result.
source can be a constant or a variable. result must be a variable.
Examplemacro_command main()

short source, result

SWAPB(0x5678, result) //   result is 0x7856

source = 0x123

SWAPB(source, result) //      result is 0x2301
 
end macro_command

SWAPW

NameSWAPW
SyntaxSWAPW(source, result)
DescriptionExchanges the high-word and low-word data of a 32-bit source into result.
source can be a constant or a variable. result must be a variable.
Examplemacro_command main()

int source, result

SWAPW (0x12345678, result) //   result is 0x56781234

source = 0x12345

SWAPW (source, result) //      result is 0x23450001
 
end macro_command

LOBYTE

NameLOBYTE
SyntaxLOBYTE(source, result)
DescriptionRetrieves the low byte of a 16-bit source into result.
source can be a constant or a variable. result must be a variable.
Examplemacro_command main()

short source, result

LOBYTE(0x1234, result) //   result is 0x34

source = 0x123

LOBYTE(source, result) //      result is 0x23
 
end macro_command

HIBYTE

NameHIBYTE
SyntaxHIBYTE(source, result)
DescriptionRetrieves the high byte of a 16-bit source into result.
source can be a constant or a variable. result must be a variable.
Examplemacro_command main()

short source, result

HIBYTE(0x1234, result) //   result is 0x12

source = 0x123

HIBYTE(source, result) //      result is 0x01
 
end macro_command

LOWORD

NameLOWORD
SyntaxLOWORD(source, result)
DescriptionRetrieves the low word of a 32-bit source into result.
source can be a constant or a variable. result must be a variable.
Examplemacro_command main()

int source, result

LOWORD(0x12345678, result) //   result is 0x5678

source = 0x12345

LOWORD(source, result) //      result is 0x2345
 
end macro_command

HIWORD

NameHIWORD
SyntaxHIWORD(source, result)
DescriptionRetrieves the high word of a 32-bit source into result.
source can be a constant or a variable. result must be a variable.
Examplemacro_command main()

int source, result

HIWORD(0x12345678, result) //   result is 0x1234

source = 0x12345

HIWORD(source, result) //      result is 0x0001
 
end macro_command

INVBIT

NameINVBIT
SyntaxINVBIT(source, result, bit_pos)
DescriptionInverts the state of designated bit position of a data (source), and puts changed data into result.
source and bit_pos can be a constant or a variable. result must be a variable.
Examplemacro_command main()

int source, result

short bit_pos

INVBIT(4, result, 1) //    result = 6

source = 6

bit_pos = 1

INVBIT(source, result, bit_pos) //       result = 4

end macro_command

SETBITON

NameSETBITON
SyntaxSETBITON(source, result, bit_pos)
DescriptionChanges the state of designated bit position of a data (source) to 1, and puts changed data into result.
source and bit_pos can be a constant or a variable.
result must be a variable.
Examplemacro_command main()

int source, result

short bit_pos

SETBITON(1, result, 3) //    result is 9

source = 0

bit_pos = 2

SETBITON (source, result, bit_pos) //    result is 4
 
end macro_command

SETBITOFF

NameSETBITOFF
SyntaxSETBITOFF(source, result, bit_pos)
DescriptionChanges the state of designated bit position of a data (source) to 0, and puts changed data into result.
source and bit_pos can be a constant or a variable.
result must be a variable.
Examplemacro_command main()

int source, result

short bit_pos

SETBITOFF(9, result, 3) //    result is 1

source = 4

bit_pos = 2

SETBITOFF(source, result, bit_pos) //    result is 0
 
end macro_command

GETBIT

NameGETBIT
SyntaxGETBIT(source, result, bit_pos)
DescriptionGets the state of designated bit position of a data (source) into result.
result value will be 0 or 1.
source and bit_pos can be a constant or a variable.
result must be a variable.
Examplemacro_command main()

int source, result

short bit_pos

GETBIT(9, result, 3) //    result is 1

source = 4

bit_pos = 2

GETBIT(source, result, bit_pos) //    result is 1
 
end macro_command

Data Type Conversion Functions

ASCII2DECConverts an ASCII string to a decimal value.
ASCII2FLOATConverts an ASCII string to a float value.
ASCII2HEXConverts an ASCII string to a hexadecimal value.
ASCII2DOUBLEConverts an ASCII string (source) to a double value.
This function is only supported on cMT /cMT X models.
BIN2BCDConverts a binary-type value to a BCD-type value.
BCD2BINConverts a BCD-type value to a binary-type value.
DATE2ASCIIConverts current date to an ASCII string.
DATE2DECConverts current date to a decimal value.
DEC2ASCIIConverts a decimal value to an ASCII string.
FLOAT2ASCIIConverts a floating value to an ASCII string.
HEX2ASCIIConverts a hexadecimal value to an ASCII string.
DOUBLE2ASCIIConverts a double value (source) to an ASCII string.
This function is only supported on cMT /cMT X models.
StringDecAsc2BinConverts a decimal string to an integer.
StringBin2DecAscConverts an integer to a decimal string.
StringDecAsc2FloatConverts a decimal string to floats.
StringFloat2DecAscConverts a float to a decimal string.
StringHexAsc2BinConverts a hexadecimal string to binary data.
StringBin2HexAscConverts binary data to a hexadecimal string.

ASCII2DEC

NameASCII2DEC
SyntaxASCII2DEC(source[start], result, len)
DescriptionTransforms a string (source) into a decimal value saved to a variable (result).

The length of the string is len. The first character of the string is source[start].
source and len can be a constant or a variable. result must be a variable. start must be a constant.
Examplemacro_command main()

char source[4]
short result
  
source[0] = ‘5’
source[1] = ‘6’
source[2] = ‘7’
source[3] = ‘8’

ASCII2DEC(source[0], result, 4) //      result is 5678

end macro_command

ASCII2FLOAT

NameASCII2FLOAT
SyntaxASCII2FLOAT(source[start], result, len)
DescriptionTransforms a string (source) into a float value saved to a variable (result).

The length of the string is len. The first character of the string is source[start]. source and len can be a constant or a variable. result must be a variable. start must be a constant.
Examplemacro_command main() char source[4]
float result
 
 
source[0] = ‘5’
source[1] = ‘6’
source[2] = ‘.’
source[3] = ‘8’

ASCII2FLOAT (source[0], result, 4) //   result is 56.8

end macro_command

ASCII2HEX

NameASCII2HEX
SyntaxASCII2HEX (source[start], result, len)
DescriptionTransforms a string (source) into a hexadecimal value saved to a variable (result).

The length of the string is len. The first character of the string is source[start]. source and len can be a constant or a variable. result must be a variable. start
must be a constant.
Examplemacro_command main() char source[4]
short result
  
source[0] = ‘5’
source[1] = ‘6’
source[2] = ‘7’
source[3] = ‘8’

ASCII2HEX (source[0], result, 4) //    result is 0x5678

end macro_command

ASCII2DOUBLE

NameASCII2DOUBLE
SyntaxASCII2DOUBLE (source[start], result, count)
DescriptionTransforms a string (source) into a double value saved to a variable (result).

The length of the string is count. The first character of the string is
source[start]. source and count can be a constant or a variable. result must be a variable. start must be a constant.
Examplemacro_command main()
 
char source[4] = {‘5’, ‘6’, ‘.’, ‘8’}
double result
 
ASCII2DOUBLE(source[0], result, 4) //    result == 56.8
SetData(result, “Local HMI”, LW, 100, 1)
 
end macro_command

BIN2BCD

NameBIN2BCD
SyntaxBIN2BCD(source, result)
DescriptionTransforms a binary-type value (source) into a BCD-type value (result).

source can be a constant or a variable. result must be a variable.
Examplemacro_command main()
short source, result

BIN2BCD(1234, result) //    result is 0x1234

source = 5678
BIN2BCD(source, result) //    result is 0x5678
 
end macro_command

BCD2BIN

NameBCD2BIN
SyntaxBCD2BIN(source, result)
DescriptionTransforms a BCD-type value (source) into a binary-type value (result).

source can be a constant or a variable. result must be a variable.
Examplemacro_command main()

short source, result

BCD2BIN(0x1234, result) //    result is 1234
 
source = 0x5678
BCD2BIN(source, result) //    result is 5678
 
end macro_command

DATE2ASCII

NameDATE2ASCII
SyntaxDATE2ASCII(day_offset, date[start], count, [separator])
DescriptionTransforms a date with day_offset added into an ASCII string, and saves it to an array (date).

count represents the length of the string and the unit of length depends on result’s type.
separator separates year, month, and day. By default, the separator is “/”.
day_offset and count can be a constant or a variable.
start and separator must be a constant.
Examplemacro_command main()

char result[10]
 
DATE2ASCII(5, result[0], 10)
//    result[0]~[9] == “2019/02/16”
//    today is 2019/02/11
 
DATE2ASCII(5, result[0], 10,2019/02/16″
//    today is 2019/02/11-16″
// today is 2019/02/11
 
end macro_command

DATE2DEC

NameDATE2DEC
SyntaxDATE2DEC(day_offset, date)
DescriptionTransforms a date with day_offset added into a decimal value saved to a variable (date).

day_offset can be a constant or a variable. date must be a variable.
Examplemacro_command main()
int day_offset = 5, date
 
DATE2DEC(0, date)                       //     date == 20190211 (Today is 2019/02/11) DATE2DEC(day_offset, date)      //     date == 20190216 (20190211 + 5)

end macro_command

DEC2ASCII

NameDEC2ASCII
SyntaxDEC2ASCII(source, result[start], len)
DescriptionTransforms a decimal value (source) into an ASCII string and saves it to an array (result).

len represents the length of the string and the unit of length depends on result’s type., i.e. if result’s type is “char” (the size is byte), the length of the string is (byte * len). If result’s type is “short” (the size is word), the length of the string is (word * len), and so on.
The first character is put into result[start], the second character is put into result[start + 1], and the last character is put into result[start + (len -1)]. source and len can be a constant or a variable. result must be a variable.
start must be a constant.
Examplemacro_command main()
short source
char result1[4]
short result2[4]
char result3[6]
source = 5678
 
DEC2ASCII(source, result1[0], 4)
// result1[0] is ‘5’, result1[1] is ‘6’, result1[2] is ‘7’, result1[3] is ‘8’
// the length of the string (result1) is 4 bytes( = 1 * 4)

DEC2ASCII(source, result2[0], 4)
// result2[0] is ‘5’, result2[1] is ‘6’, result2[2] is ‘7’, result2[3] is ‘8’
// the length of the string (result2) is 8 bytes( = 2 * 4)
 
 
source=-123
DEC2ASCII(source, result3[0], 6)
// result1[0] is ‘-‘, result1[1] is ‘0’, result1[2] is ‘0’, result1[3] is ‘1’
// result1[4] is ‘2’, result1[5] is ‘3’
// the length of the string (result1) is 6 bytes( = 1 * 6)
 
end macro_command

FLOAT2ASCII

NameFLOAT2ASCII
SyntaxFLOAT2ASCII(source, result[start], len)
DescriptionTransforms a floating value (source) into ASCII string saved to an array (result).

len represents the length of the string and the unit of length depends on result’s type., i.e. if result’s type is “char” (the size is byte), the length of the string is (byte * len). If result’s type is “short” (the size is word), the length of the string is (word * len), and so on.
source and len can be a constant or a variable. result must be a variable. start
must be a constant.
Examplemacro_command main()
float source
char result[4]
 
source = 56.8
FLOAT2ASCII (source, result[0], 4)
//    result[0] is ‘5’, result[1] is ‘6’, result[2] is ‘.’, result[3] is ‘8’
 
end macro_command

HEX2ASCII

NameHEX2ASCII
SyntaxHEX2ASCII(source, result[start], len)
DescriptionTransforms a hexadecimal value (source) into ASCII string saved to an array (result).

len represents the length of the string and the unit of length depends on result’s type., i.e. if result’s type is “char” (the size is byte), the length of the string is (byte * len). If result’s type is “short” (the size is word), the length of the string is (word * len), and so on.
source and len can be a constant or a variable. result must be a variable. start
must be a constant.
Examplemacro_command main()
short source
char result[4]
 
source = 0x5678
HEX2ASCII (source, result[0], 4)
//    result[0] is ‘5’, result[1] is ‘6’, result[2] is ‘7’, result[3] is ‘8’
 
end macro_command

DOUBLE2ASCII

NameDOUBLE2ASCII
SyntaxDOUBLE2ASCII (source, result[start], count)
DescriptionTransforms a double value (source) into ASCII string saved to an array (result).

count represents the length of the string and the unit of length depends on result’s type., i.e. if result’s type is “char” (the size is byte), the length of the string is (byte * count). If result’s type is “short” (the size is word), the length of the string is (word * count), and so on.
source and count can be a constant or a variable. result must be a variable.
start must be a constant.
This function is only supported on cMT / cMT X models.
Examplemacro_command main()
 
double source = 56.8
char result[4]
 
DOUBLE2ASCII(source, result[0], 4)
//    result[0] == ‘5’, result[1] == ‘6’, result[2] == ‘.’, result[3] == ‘8’
 
end macro_command

StringDecAsc2Bin

NameStringDecAsc2Bin
Syntaxsuccess = StringDecAsc2Bin(source[start], destination)
or
success = StringDecAsc2Bin(“source”, destination)
DescriptionThis function converts a decimal string to an integer. It converts the decimal string in source parameter into an integer, and stores it in the destination variable.

The source string parameter accepts both static string (in the form: “source”) and char array (in the form: source[start]).
Destination must be a variable, to store the result of conversion.
This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. The string can only contain these characters: +, -, and 0 to 9. If the string contains other characters, it returns false.
The success field is optional.
Examplemacro_command main()
char src1[5]=”12345″
int result1
bool success1
success1 = StringDecAsc2Bin(src1[0], result1)
// success1=true, result1 is 12345
 
char src2[5] = “-6789”
short result2
bool success2
success2 = StringDecAsc2Bin(src2[0], result2)
// success2 = true,result2 is -6789

char result3
bool success3
success3 = StringDecAsc2Bin(“32768”, result3)
// success3=true, but the result exceeds the data range of result3
 
char src4[2]=”4b”
char result4
bool success4
success4 = StringDecAsc2Bin (src4[0], result4)
// success4=false, because src4 contains characters other than ‘+’ or ‘-’ and ‘0’ to ‘9’
 
end macro_command

StringBin2DecAsc

NameStringBin2DecAsc
Syntaxsuccess = StringBin2DecAsc (source, destination[start])
DescriptionThis function converts an integer to a decimal string. It converts the integer in source parameter into a decimal string, and stores it in the destination buffer. Source can be either a constant or a variable.
Destination must be an one-dimensional char array, to store the result of conversion.
This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. If the length of decimal string after conversion exceeds the size of destination buffer, it returns false.
The success field is optional.
Examplemacro_command main()
int src1 = 2147483647
char dest1[20]

bool success1
success1 = StringBin2DecAsc(src1, dest1[0])
// success1=true, dest1=”2147483647″
 
short src2 = 0x3c
char dest2[20]
bool success2
success2 = StringBin2DecAsc(src2, dest2[0])
// success2=true, dest2=”60″
 
int src3 = 2147483647 char dest3[5]
bool success3
success3 = StringBin2DecAsc(src3, dest3[0])
// success3=false, dest3 remains the same.
 
end macro_command

StringDecAsc2Float

NameStringDecAsc2Float
Syntaxsuccess = StringDecAsc2Float (source[start], destination)
or
success = StringDecAsc2Float (“source”, destination)
DescriptionThis function converts a decimal string to floats. It converts the decimal string in source parameter into float, and stores it in the destination variable.
The source string parameter accepts both static string (in the form: “source”) and char array (in the form: source[start]).
Destination must be a variable, to store the result of conversion.
This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. If the source string contains characters other than ‘0’ to ‘9’ or ‘.’, it returns false.
The success field is optional.
Examplemacro_command main()
char src1[10]=”12.345″
float result1
bool success1
success1 = StringDecAsc2Float(src1[0], result1)
// success1=true, result1 is 12.345
 
float result2
bool success2
success2 = StringDecAsc2Float(“1.234567890”, result2)
// success2=true, but the result exceeds the data range of result2, which
// might result in loss of precision
 
char src3[2]=”4b”
float result3
bool success3
success3 = StringDecAsc2Float(src3[0], result3)
// success3=false, because src3 contains characters other than ‘0’ to ‘9’ or
// ‘.’

end macro_command

StringFloat2DecAsc

NameStringFloat2DecAsc
Syntaxsuccess = StringFloat2DecAsc(source, destination[start])
DescriptionThis function converts a float to a decimal string. It converts the float in source parameter into a decimal string, and stores it in the destination buffer. Source can be either a constant or a variable.
Destination must be an one-dimensional char array, to store the result of conversion.
This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. If the length of decimal string after conversion exceeds the size of destination buffer, it returns false.
The success field is optional.
Examplemacro_command main()
float src1 = 1.2345
char dest1[20]
bool success1
success1 = StringFloat2DecAsc(src1, dest1[0])
// success1=true, dest1=”1.2345″
 
float src2 = 1.23456789
char dest2 [20]
bool success2
success2 = StringFloat2DecAsc(src2, dest2 [0])
// success2=true, but it might lose precision
 
float src3 = 1.2345
char dest3[5]
bool success3
success3 = StringFloat2DecAsc(src3, dest3 [0])
// success3=false, dest3 remains the same.
 
end macro_command

StringHexAsc2Bin

NameStringHexAsc2Bin
Syntaxsuccess = StringHexAsc2Bin (source[start], destination)
or
success = StringHexAsc2Bin (“source”, destination)
DescriptionThis function converts a hexadecimal string to binary data. It converts the hexadecimal string in source parameter into binary data, and stores it in the destination variable.
The source string parameter accepts both static string (in the form: “source”) and char array (in the form: source[start]).
Destination must be a variable, to store the result of conversion.
This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. If the source string contains characters other than ‘0’ to ‘9’, ‘a’ to ‘f’ or ‘A’ to ‘F’, it returns false.
The success field is optional.
Examplemacro_command main()
char src1[5]=”0x3c”
int result1
bool success1
success1 = StringHexAsc2Bin(src1[0], result1)
// success1=true, result1 is 3c
 
short result2
bool success2
success2 = StringDecAsc2Bin(“1a2b3c4d”, result2)
// success2=true, result2=3c4d.The result exceeds the data range of
// result2
 
char src3[2]=”4g”
char result3
bool success3
success3 = StringDecAsc2Bin (src3[0], result3)
// success3=false, because src3 contains characters other than ‘0’ to ‘9’
// , ‘a’ to ‘f’ or ‘A’ to ‘F’
 
end macro_command

StringBin2HexAsc

NameStringBin2HexAsc
Syntaxsuccess = StringBin2HexAsc (source, destination[start])
DescriptionThis function converts binary data to a hexadecimal string. It converts the binary data in source parameter into a hexadecimal string, and stores it in the destination buffer.
Source can be either a constant or a variable.
Destination must be an one-dimensional char array, to store the result of conversion.
This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. If the length of hexadecimal string after conversion exceeds the size of destination buffer, it returns false.
The success field is optional.
Please note that this function cannot convert negative values.
Examplemacro_command main()
int src1 = 20
char dest1[20]
bool success1
success1 = StringBin2HexAsc(src1, dest1[0])
// success1=true, dest1=”14″
 
short src2 = 0x3c
char dest2[20]
bool success2
success2 = StringBin2HexAsc(src2, dest2[0])
// success2=true, dest2=”3c”
 
int src3 = 0x1a2b3c4d c
har dest3[6]
bool success3
success3 = StringBin2HexAsc(src3, dest3[0])
// success3=false, dest3 remains the same.
 
end macro_command

String Operation Functions

String2UnicodeConverts all the characters in the source string to Unicode.
StringCatAppends source string to destination string.
StringComparePerforms a case-sensitive comparison of two strings.
StringCompareNoCasePerforms a case-insensitive comparison of two strings.
StringCopyCopies one string to another.
StringExcludingRetrieves a substring of the source string that contains
characters that are not in the set string.
StringFindReturns the zero-based index of the first character of substring
in the source string that matches the target string.
StringFindOneOfReturns the zero-based index of the first character in the source
string that is also in the target string.
StringGetReceives data from the device.
StringGetExReceives data from the device and continues executing next
command even if there’s no response from the device.
StringIncludingRetrieves a substring of the source string that contains
characters in the set string, beginning with the first character in the source string and ending when a character is found in the source string that is not in the target string.
StringInsertInserts a string in a specific location within the destination
string content.
StringLengthObtains the length of a string.
StringMD5Generates a string using MD5 message-digest algorithm.
StringMidRetrieves a character sequence from the specified offset of the
source string.
StringReverseFindReturns the position of the last occurrence of target string in
the source string.
StringSetSends data to the device.
StringSetExSends data to the device and continues executing next
command even if there’s no response from the device.
StringToUpperConverts all the characters in the source string to uppercase
characters.
StringToLowerConverts all the characters in the source string to lowercase
characters.
StringToReverseReverses the characters in the source string
StringTrimLeftTrims the leading specified characters in the set buffer from the
source string.
StringTrimRightTrims the trailing specified characters in the set buffer from the
source string.
Unicode2Utf8Converts a Unicode string to a UTF8 string.
UnicodeCatConcatenates two Unicode Strings
UnicodeComparePerforms case-sensitive comparison between two Unicode
strings.
UnicodeCopyCopies a Unicode string.
UnicodeExcludingRetrieves a substring of the source string that contains
characters that are not in the set string.
UnicodeLengthObtains the length of a Unicode string.
Utf82UnicodeConverts a UTF8 string to a Unicode string.

String2Unicode

NameString2Unicode
Syntaxresult = String2Unicode(“source”, destination[start])
DescriptionConverts all the characters in the source string to Unicode and stores the result in the destination buffer. The length of result string after conversion will be stored to result.
Source must be a constant but not a variable.
Examplemacro_command main()
 
char dest[20]
int result
result = String2Unicode(“abcde”, dest[0]) // “result” will be set to 10.
result = String2Unicode(“abcdefghijklmno”, dest[0]) // “result” will be set to 20.
// “result” will be the length of converted Unicode string
 
end macro_command

StringCat

NameStringCat
Syntaxsuccess = StringCat (source[start], destination[start])
or
success = StringCat (“source”, destination[start])
DescriptionThis function appends source string to destination string. It adds the contents of source string to the last of the contents of destination string.
The source string parameter accepts both static string (in the form: “source”) and char array (in the form: source[start]).
Destination must be an one-dimensional char array.
This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. If the length of result string after concatenation exceeds the max. size of destination buffer, it returns false.
The success field is optional.
Examplemacro_command main()
char src1[20]=”abcdefghij”
char dest1[20]=”1234567890″
bool success1
success1= StringCat(src1[0], dest1[0])
// success1=true, dest1=”123456790abcdefghij”
 
char dest2 [10]=”1234567890″
bool success2
success2= StringCat(“abcde”, dest2 [0])
// success2=false, dest2 remains the same.
 
char src3[20]=”abcdefghij”
char dest3[20]
bool success3
success3= StringCat(src3[0], dest3[15])
// success3=false, dest3 remains the same.
 
end macro_command

StringCompare

NameStringCompare
Syntaxret = StringCompare (str1[start], str2[start])
ret = StringCompare (“string1”, str2[start])
ret = StringCompare (str1[start], “string2”)
ret = StringCompare (“string1”, “string2”)
DescriptionPerforms a case-sensitive comparison of two strings.
The two string parameters accept both static string (in the form: “string1”) and char array (in the form: str1[start]).
This function returns a Boolean indicating the result of comparison. If two strings are identical, it returns true. Otherwise it returns false.
The ret field is optional.
Examplemacro_command main()
char a1[20]=”abcde”
char b1[20]=”ABCDE”
bool ret1
ret1= StringCompare(a1[0], b1[0])
// ret1=false
 
char a2[20]=”abcde”
char b2[20]=”abcde”
bool ret2
ret2= StringCompare(a2[0], b2[0])
// ret2=true
 
char a3 [20]=”abcde”
char b3[20]=”abcdefg”
bool ret3
ret3= StringCompare(a3[0], b3[0])
// ret3=false
 
end macro_command

StringCompareNoCase

NameStringCompareNoCase
Syntaxret = StringCompareNoCase(str1[start], str2[start])
ret = StringCompareNoCase(“string1”, str2[start])
ret = StringCompareNoCase(str1[start], “string2”)
ret = StringCompareNoCase(“string1”, “string2”)
DescriptionPerforms a case-insensitive comparison of two strings.
The two string parameters accept both static string (in the form: “string1”) and char array (in the form: str1[start]).
This function returns a Boolean indicating the result of comparison. If two strings are identical, it returns true. Otherwise it returns false.
The ret field is optional.
Examplemacro_command main()
char a1[20]=”abcde”
char b1[20]=”ABCDE”
bool ret1
ret1= StringCompareNoCase(a1[0], b1[0])
// ret1=true
 
char a2[20]=”abcde”
char b2[20]=”abcde”
bool ret2
ret2= StringCompareNoCase(a2[0], b2[0])
// ret2=true
 
char a3 [20]=”abcde”
char b3[20]=”abcdefg”
bool ret3
ret3= StringCompareNoCase(a3[0], b3[0])
// ret3=false
 
end macro_command

StringCopy

NameStringCopy
Syntaxsuccess = StringCopy (“source”, destination[start])
or
success = StringCopy (source[start], destination[start])
DescriptionCopies one string to another. This function copies a static string (which is enclosed in quotes) or a string that is stored in an array to the destination buffer.
The source string parameter accepts both static string (in the form: “source”) and char array (in the form: source[start]).
destination[start] must be an one-dimensional char array.
This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. If the length of source string exceeds the max. size of destination buffer, it returns false and the content of destination remains the same.
The success field is optional.
Examplemacro_command main()
char src1[5]=”abcde”
char dest1[5]
bool success1
success1 = StringCopy(src1[0], dest1[0])
// success1=true, dest1=”abcde”
 
char dest2[5]
bool success2
success2 = StringCopy(“12345”, dest2[0])
// success2=true, dest2=”12345″
 
char src3[10]=”abcdefghij”
char dest3[5]
bool success3
success3 = StringCopy(src3[0], dest3[0])
// success3=false, dest3 remains the same.
 
char src4[10]=”abcdefghij”
char dest4[5]
bool success4
success4 = StringCopy(src4[5], dest4[0])
// success4=true, dest4=”fghij”
 
end macro_command

StringExcluding

NameStringExcluding
Syntaxsuccess = StringExcluding (source[start], set[start], destination[start])
success = StringExcluding (“source”, set[start], destination[start])
success = StringExcluding (source[start], “set”, destination[start])
success = StringExcluding (“source”, “set”, destination[start])
DescriptionRetrieves a substring of the source string that contains characters that are not in the set string, beginning with the first character in the source string and ending when a character is found in the source string that is also in the target string.
The source string and set string parameters accept both static string (in the form: “source”) and char array (in the form: source[start]).
This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. If the length of retrieved substring exceeds the size of destination buffer, it returns
false.
Examplemacro_command main()
char src1[20]=”cabbageabc”
char set1[20]=”ge”
char dest1[20]
bool success1
success1 = StringExcluding(src1[0], set1[0], dest1[0])
// success1=true, dest1=”cabba”
 
char src2[20]=”cabbage”
char dest2[20]
bool success2
success2 = StringExcluding(src2[0], “abc”, dest2[0])
// success2=true, dest2=””
 
char set3[20]=”ge”
char dest3[4]
bool success3
success3 = StringExcluding(“cabbage”, set3[0], dest3[0])
// success3=false, dest3 remains the same.
 
end macro_command

StringFind

NameStringFind
Syntaxposition = StringFind (source[start], target[start])
position = StringFind (“source”, target[start])
position = StringFind (source[start], “target”)
position = StringFind (“source”, “target”)
DescriptionReturns the position of the first occurrence of target string in the source string.
The two string parameters accept both static string (in the form: “source”) and char array (in the form: source[start]).
This function returns the zero-based index of the first character of substring in the source string that matches the target string. Notice that the entire sequence of characters to find must be matched. If there is no matched
substring, it returns -1.
Examplemacro_command main()
char src1[20]=”abcde”
char target1[20]=”cd”
short pos1
pos1= StringFind(src1[0], target1[0])
// pos1=2
 
char target2[20]=”ce”
short pos2
pos2= StringFind(“abcde”, target2[0])
// pos2=-1
 
char src3[20]=”abcde”
short pos3
pos3= StringFind(src3[3], “cd”)
// pos3=-1
 
end macro_command

StringFindOneOf

NameStringFindOneOf
Syntaxposition = StringFindOneOf (source[start], target[start])
position = StringFindOneOf (“source”, target[start])
position = StringFindOneOf (source[start], “target”)
position = StringFindOneOf (“source”, “target”)
DescriptionReturns the position of the first character in the source string that matches any character contained in the target string.
The two string parameters accept both static string (in the form: “source”) and char array (in the form: source[start]).
This function returns the zero-based index of the first character in the source
string that is also in the target string. If there is no match, it returns -1.
Examplemacro_command main()
char src1[20]=”abcdeabcde”
char target1[20]=”sdf”
short pos1
pos1= StringFindOneOf(src1[0], target1[0])
// pos1=3
 
char src2[20]=”abcdeabcde”
short pos2
pos2= StringFindOneOf(src2[1], “agi”)
// pos2=4
 
char target3 [20]=”bus”
short pos3
pos3= StringFindOneOf(“abcdeabcde”, target3[1])
// pos3=-1
 
end macro_command

StringGet

NameStringGet
SyntaxStringGet(read_data[start], device_name, device_type, address_offset, data_count)
DescriptionReceives data from the device. The String data is stored into read_data[start]~ read_data[start + data_count – 1]. read_data must be a one-dimensional char array.
Data_count is the number of received characters, it can be either a constant or a variable.
Device_name is the device name enclosed in the double quotation marks (“) and this name has been defined in the device list of system parameters.
Device_type is the device type and encoding method (binary or BCD) of the device data. For example, if device_type is LW_BIN, it means the register is LW
and the encoding method is binary. If use BIN encoding method, “_BIN” can be ignored.
If device_type is LW_BCD, it means the register is LW and the encoding method is BCD.
Address_offset is the address offset in the device.
For example, StringGet(read_data_1[0], “FATEK KB Series”, RT, 5, 1) represents that the address offset is 5.
If address_offset uses the format –”N#AAAAA”, N indicates that device’s station number is N. AAAAA represents the address offset. This format is used while multiple devices or controllers are connected to a single serial port. For example, StringGet(read_data_1[0], “FATEK KB Series”, RT, 2#5, 1) represents that the device’s station number is 2. If StringGet() uses the default station number defined in the device list as follows, it is not necessary to define station number in address_offset.
The number of registers actually read from depends on the value of the number of data_count since that the read_data is restricted to char array.
1 WORD register(16-bit) equals to the size of 2 ASCII characters. According to the above table, reading 2 ASCII characters is actually reading the content of one 16-bit register.
Examplemacro_command main()
char str1[20]
 
//    read 10 words from LW-0~LW-9 to the variables str1[0] to str1[19]
//    since that 1 word can store 2 ASCII characters, reading 20 ASCII
//    characters is actually reading 10 words of register

StringGet(str1[0], “Local HMI”, LW, 0, 20)

end macro_command

StringGetEx

NameStringGetEx
SyntaxStringGetEx (read_data[start], device_name, device_type, address_offset, data_count)
DescriptionReceives data from the device and continues executing next command even if there’s no response from this device.
Descriptions of read_data, device_name, device_type, address_offset and
data_count are the same as GetData.
Examplemacro_command main()
char str1[20]
short test=0
 
// macro will continue executing test = 1 even if the MODBUS device is
// not responding
StringGetEx(str1[0], “MODBUS RTU”, 4x, 0, 20)
test = 1
 
// macro will not continue executing test = 2 until MODBUS device responds StringGet(str1[0], “MODBUS RTU”, 4x, 0, 20)
test = 2
 
end macro_command

StringIncluding

NameStringIncluding
Syntaxsuccess = StringIncluding (source[start], set[start], destination[start])
success = StringIncluding (“source”, set[start], destination[start])
success = StringIncluding (source[start], “set”, destination[start])
success = StringIncluding (“source”, “set”, destination[start])
DescriptionRetrieves a substring of the source string that contains characters in the set string, beginning with the first character in the source string and ending when a character is found in the source string that is not in the target string.
The source string and set string parameters accept both static string (in the form: “source”) and char array (in the form: source[start]).
This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. If the length of retrieved substring exceeds the size of destination buffer, it returns
false.
Examplemacro_command main()
char src1[20]=”cabbageabc”
char set1[20]=”abc”
char dest1[20]
bool success1
success1 = StringIncluding(src1[0], set1[0], dest1[0])
// success1=true, dest1=”cabba”
 
char src2[20]=”gecabba”
char dest2[20]
bool success2
success2 = StringIncluding(src2[0], “abc”, dest2[0])
// success2=true, dest2=””
 
char set3[20]=”abc”
char dest3[4]
bool success3
success3 = StringIncluding(“cabbage”, set3[0], dest3[0])
// success3=false, dest3 remains the same.
 
end macro_command

StringInsert

NameStringInsert
Syntaxsuccess = StringInsert (pos, insert[start], destination[start])
success = StringInsert (pos, “insert”, destination[start])
success = StringInsert (pos, insert[start], length, destination[start])
success = StringInsert (pos, “insert”, length, destination[start])
DescriptionInserts a string in a specific location within the destination string content. The insert location is specified by the pos parameter.
The insert string parameter accepts both static string (in the form: “source”) and char array (in the form: source[start]).
The number of characters to insert can be specified by the length parameter. This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. If the length of string after insertion exceeds the size of destination buffer, it
returns false.
Examplemacro_command main()
 
char str1[20]=”but the question is”
char str2[10]=”, that is”
char dest[40]=”to be or not to be”
bool success
 
success = StringInsert(18, str1[3], 13, dest[0])
// success=true, dest=”to be or not to be the question”
 
success = StringInsert(18, str2[0], dest[0])
// success=true, dest=”to be or not to be, that is the question”
 
success = StringInsert(0, “Hamlet:”, dest[0])
// success=false, dest remains the same.
 
end macro_command

StringLength

NameStringLength
Syntaxlength = StringLength (source[start])
or
length = StringLength (“source”)
DescriptionObtains the length of a string. It returns the length of source string and stores it in the length field on the left-hand side of ‘=’ operator.
The source string parameter accepts both static string (in the form: “source”) and char array (in the form: source[start]).
The return value of this function indicates the length of the source string.
Examplemacro_command main()
char src1[20]=”abcde”
int length1
length1= StringLength(src1[0])
// length1=5
 
char src2[20]={‘a’, ‘b’, ‘c’, ‘d’, ‘e’}
int length2
length2= StringLength(src2[0])
// length2=5
 
char src3[20]=”abcdefghij”
int length3
length3= StringLength(src3 [2])
// length3=8
 
end macro_command

StringMD5

NameStringMD5
Syntaxresult = StringMD5(source[start], destination[start])
or
result = StringMD5(“source”, destination[start])
DescriptionRetrieves a string using MD5 Message-Digest algorithm.
The source string parameter accepts both static string (in the form: “source”) and char array (in the form: source[start]). For source[start], the start offset of the substring is specified by the index value.
destination[start] must be a one-dimensional char array, to store the retrieved substring.
This function returns the length of MD5 string stored in result.
Examplemacro_command main()
char source[32] = “password”, dest[32]
int result
 
result = StringMD5(source[0], dest[0])
result = StringMD5(“password”, dest[0]) // “result” will be set to 32.
// “result” will be the length of MD5 string.
// dest[] = 5f4dcc3b5aa765d61d8327deb882cf99
 
end macro_command

StringMid

NameStringMid
Syntaxsuccess = StringMid (source[start], count, destination[start])
or
success = StringMid (“string”, start, count, destination[start])
DescriptionRetrieves a character sequence from the specified offset of the source string and stores it in the destination buffer.
The source string parameter accepts both static string (in the form: “source”) and char array (in the form: source[start]). For source[start], the start offset of the substring is specified by the index value. For static source string(“source”), the second parameter(start) specifies the start offset of the substring.
The count parameter specifies the length of substring being retrieved. Destination must be an one-dimensional char array, to store the retrieved substring.
This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. If the length of retrieved substring exceeds the size of destination buffer, it returns false.
The success field is optional.
Examplemacro_command main()
char src1[20]=”abcdefghijklmnopqrst”
char dest1[20]
bool success1
success1 = StringMid(src1[5], 6, dest1[0])
// success1=true, dest1=”fghijk”
 
char src2[20]=”abcdefghijklmnopqrst”
char dest2[5]
bool success2
success2 = StringMid(src2[5], 6, dest2[0])
// success2=false, dest2 remains the same.
 
char dest3[20]=”12345678901234567890″
bool success3
success3 = StringMid(“abcdefghijklmnopqrst”, 5, 5, dest3[15])
// success3= true, dest3=”123456789012345fghij”
 
end macro_command

StringReverseFind

NameStringReverseFind
Syntaxposition = StringReverseFind (source[start], target[start])
position = StringReverseFind (“source”, target[start])
position = StringReverseFind (source[start], “target”)
position = StringReverseFind (“source”, “target”)
DescriptionReturns the position of the last occurrence of target string in the source string. The two string parameters accept both static string (in the form: “source”) and char array (in the form: source[start]).
This function returns the zero-based index of the first character of substring in the source string that matches the target string. Notice that the entire sequence of characters to find must be matched. If there exists multiple substrings that matches the target string, function will return the position of
the last matched substring. If there is no matched substring, it returns -1.
Examplemacro_command main()
char src1[20]=”abcdeabcde”
char target1[20]=”cd”
short pos1
pos1= StringReverseFind(src1[0], target1[0])
// pos1=7
 
char target2[20]=”ce”
short pos2
pos2= StringReverseFind(“abcdeabcde”, target2[0])
// pos2=-1
 
char src3[20]=”abcdeabcde”
short pos3
pos3= StringReverseFind(src3[6], “ab”)
// pos3=-1
 
end macro_command

StringSet

NameStringSet
SyntaxStringSet(send_data[start], device_name, device_type, address_offset, data_count)
DescriptionSends data to the device. Data is defined in send_data[start]~ send_data[start
+ data_count – 1]. send_data must be a one-dimensional char array. data_count is the number of sent characters, it can be either a constant or a variable.
device_name is the device name enclosed in the double quotation marks (“) and this name has been defined in the device list of system parameters. device_type is the device type and encoding method (binary or BCD) of the device data. For example, if device_type is LW_BIN, it means the register is LW and the encoding method is binary. If use BIN encoding method, “_BIN” can be ignored.
If device_type is LW_BCD, it means the register is LW and the encoding method is BCD.
address_offset is the address offset in the device.
For example, StringSet(read_data_1[0], “FATEK KB Series”, RT, 5, 1) represents that the address offset is 5.
If address_offset uses the format –”N#AAAAA”, N indicates that device’s station number is N. AAAAA represents the address offset. This format is used while multiple devices or controllers are connected to a single serial port. For example, StringSet(read_data_1[0], “FATEK KB Series”, RT, 2#5, 1) represents that the device’s station number is 2. If SetData () uses the default station number defined in the device list, it is not necessary to define station number in address_offset.
The number of registers actually sends to depends on the value of the number of data_count, since that send_data is restricted to char array.
1 WORD register(16-bit) equals to the size of 2 ASCII characters. According to the above table, sending 2 ASCII characters is actually writing to one 16-bit register. The ASCII characters are stored into the WORD register from low byte to high byte. While using the ASCII Display object to display the string data stored in the registers, data_count must be a multiple of 2 in order to display full string content.

For example:
macro_command main()
char src1[10]=”abcde”
StringSet(src1[0], “Local HMI”, LW, 0, 5)
end macro_command


The ASCII Display object shows: abcd

If data_count is an even number that is greater than or equal to the length of the string, the content of string can be completely shown:

macro_command main()
char src1[10]=”abcde”
StringSet(src1[0], “Local HMI”, LW, 0, 6)
end macro_command


The ASCII Display object shows: abcde
Examplemacro_command main()
char str1[10]=”abcde”

//    Send 3 words to LW-0~LW-2
//    Data are being sent until the end of string is reached.
//    Even though the value of data_count is larger than the length of string, the
//    function will automatically stop.

StringSet(str1[0], “Local HMI”, LW, 0, 1

end macro_command

StringSetEx

NameStringSetEx
SyntaxStringSetEx (send_data[start], device_name, device_type, address_offset, data_count)
DescriptionSends data to the device and continues executing next command even if there’s no response from this device.

Descriptions of send_data, device_name, device_type, address_offset and
data_count are the same as StringSet.
Examplemacro_command main()
char str1[20]=”abcde”
short test=0
 
// macro will continue executing test = 1 even if the MODBUS device is
// not responding
StringSetEx(str1[0], “MODBUS RTU”, 4x, 0, 20)
test = 1
 
// macro will not continue executing test = 2 until MODBUS device responds StringSet(str1[0], “MODBUS RTU”, 4x, 0, 20)
test = 2
 
end macro_command

StringToUpper

NameStringToUpper
Syntaxsuccess = StringToUpper (source[start], destination[start])
success = StringToUpper (“source”, destination[start])
DescriptionConverts all the characters in the source string to uppercase characters and stores the result in the destination buffer.
The source string parameter accepts both static string (in the form: “source”) and char array (in the form: source[start]).
This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. If the length of result string after conversion exceeds the size of destination buffer, it
returns false.
Examplemacro_command main()
char src1[20]=”aBcDe”
char dest1[20]
bool success1
success1 = StringToUpper(src1[0], dest1[0])
// success1=true, dest1=”ABCDE”
 
char dest2[4]
bool success2
success2 = StringToUpper(“aBcDe”, dest2[0])
// success2=false, dest2 remains the same.
 
end macro_command

StringToLower

NameStringToLower
Syntaxsuccess = StringToLower (source[start], destination[start])
success = StringToLower (“source”, destination[start])
DescriptionConverts all the characters in the source string to lowercase characters and stores the result in the destination buffer.
The source string parameter accepts both static string (in the form: “source”) and char array (in the form: source[start]).
This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. If the length of result string after conversion exceeds the size of destination buffer, it
returns false.
Examplemacro_command main()
char src1[20]=”aBcDe”
char dest1[20]
bool success1
success1 = StringToLower(src1[0], dest1[0])
// success1=true, dest1=”abcde”
 
char dest2[4]
bool success2
success2 = StringToLower(“aBcDe”, dest2[0])
// success2=false, dest2 remains the same.
 
end macro_command

StringToReverse

NameStringToReverse
Syntaxsuccess = StringToReverse (source[start], destination[start])
success = StringToReverse (“source”, destination[start])
DescriptionReverses the characters in the source string and stores it in the destination buffer.
The source string parameter accepts both static string (in the form: “source”) and char array (in the form: source[start]).
This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. If the
length of reversed string exceeds the size of destination buffer, it returns false.
Examplemacro_command main()
char src1[20]=”abcde”
char dest1[20]
bool success1
success1 = StringToReverse(src1[0], dest1[0])
// success1=true, dest1=”edcba”
 
char dest2[4]
bool success2
success2 = StringToReverse(“abcde”, dest2[0])
// success2=false, dest2 remains the same.
 
end macro_command

StringTrimLeft

NameStringTrimLeft
Syntaxsuccess = StringTrimLeft (source[start], set[start], destination[start])
success = StringTrimLeft (“source”, set[start], destination[start])
success = StringTrimLeft (source[start], “set”, destination[start])
success = StringTrimLeft (“source”, “set”, destination[start])
DescriptionTrims the leading specified characters in the set buffer from the source string.
The source string and set string parameters accept both static string (in the form: “source”) and char array (in the form: source[start]).
This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. If the
length of trimmed string exceeds the size of destination buffer, it returns false.
Examplemacro_command main()
char src1[20]= “# *a*#bc”
char set1[20]=”# *”
char dest1[20]
bool success1
success1 = StringTrimLeft (src1[0], set1[0], dest1[0])
// success1=true, dest1=”a*#bc”
 
char set2[20]={‘#’, ‘ ‘, ‘*’}
char dest2[4]
bool success2
success2 = StringTrimLeft (“# *a*#bc”, set2[0], dest2[0])
// success2=false, dest2 remains the same.

char src3[20]=”abc *#”
char dest3[20]
bool success3
success3 = StringTrimLeft (src3[0], “# *”, dest3[0])
// success3=true, dest3=”abc *#”

end macro_command

StringTrimRight

NameStringTrimRight
Syntaxsuccess = StringTrimRight (source[start], set[start], destination[start])
success = StringTrimRight (“source”, set[start], destination[start])
success = StringTrimRight (source[start], “set”, destination[start])
success = StringTrimRight (“source”, “set”, destination[start])
DescriptionTrims the trailing specified characters in the set buffer from the source string. The source string and set string parameters accept both static string (in the form: “source”) and char array (in the form: source[start]).
This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. If the
length of trimmed string exceeds the size of destination buffer, it returns false.
Examplemacro_command main()
char src1[20]= “# *a*#bc# * ”
char set1[20]=”# *”
char dest1[20]
bool success1
success1 = StringTrimRight(src1[0], set1[0], dest1[0])
// success1=true, dest1=”# *a*#bc”
 
char set2[20]={‘#’, ‘ ‘, ‘*’}
char dest2[20]
bool success2
success2 = StringTrimRight(“# *a*#bc”, set2[0], dest2[0])
// success2=true, dest2=”# *a*#bc”
 
char src3[20]=”ab**c *#”
char dest3[4]
bool success3
success3 = StringTrimRight(src3[0], “# *”, dest3[0])
// success3=false, dest3 remains the same.
 
end macro_command

Unicode2Utf8

NameUnicode2Utf8
Syntaxresult = Unicode2Utf8(source[start], destination[start])
DescriptionConverts the source Unicode string to UTF8 string and stores the result in the destination buffer. This function returns a Boolean indicating whether the process is successfully done or not. If successful, it returns true,; otherwise it returns false.
Examplemacro_command main()
 
char unicode_str[20]
char utf8_str[20]
String2Unicode(“ABC”, unicode_str[0])
bool result
 
result = Unicode2Utf8(unicode_str[0], utf8_str[0])
// “result” will be set to true. “utf8_str” will equal “ABC” encoded in UTF8
StringCat(“DEF”, utf8_str[0]) // “utf8_str” will equal “ABCDEF” encoded in UTF8
 
char dst[20]
bool result2
 
result2 = Utf82Unicode(utf8_str[0], dst[0])
// “result” will be set to true. “dst” will equal “ABCDEF” encoded in Unicode.
 
end macro_command

UnicodeCat

NameUnicodeCat
Syntaxresult = UnicodeCat(source[start], destination[start])
or
result = UnicodeCat(“source”, destination[start])
DescriptionThis function concatenate strings. It appends the source string to the destination string.
The source string parameter accepts both static string (e.g. “source”) and char array (e.g. source[start]).
destination[start] must be an one-dimensional char array.
This function returns a Boolean indicating whether the process has been successfully completed. If successful, it returns true; otherwise it returns false. If the length of the result string after concatenation exceeds the max. size of destination buffer, it returns false, and the destination string remains unchanged.
Examplemacro_command main()
char strSrc[12]=”αθβγθδ”
char strDest[28]=”ζηθλ1234″
bool result
 
result = UnicodeCat(strSrc[0], strDest[0]) // “result” will be set to true
//”strDest” will be set to “ζηθλ1234αθβγθδ”
 
result = UnicodeCat(“ζηθλ”, strDest[0]) // the function fails.
// “result” will be set to false due to insufficient destination buffer size.
// In this case, the content of “strDest” remains the same.
 
end macro_command

UnicodeCompare

NameUnicodeCompare
Syntaxresult = UnicodeCompare(string1[start], string2[start])
result = UnicodeCompare(“string1”, string2[start])
result = UnicodeCompare(string1[start], “string2”)
result = UnicodeCompare(“string1”, “string2”)
DescriptionPerforms case-sensitive comparison of two strings.
The two string parameters accept both static string (e.g. “string”) and char array (e.g. string[start]).
This function returns a Boolean indicating the result of comparison. If two
strings are identical, it returns true. Otherwise it returns false.
Examplemacro_command main()
char str1[10]=” θαβθγ”
char str2[8]=”αβγδ”
bool result
 
result = UnicodeCompare(str1[0], str2[0]) // “result” will be set to false.
result = UnicodeCompare(str1[0], “θαβθγ”) // “result” will be set to true.
 
end macro_command

UnicodeCopy

NameUnicodeCopy
Syntaxresult = UnicodeCopy(“source”, destination[start])
or
result = UnicodeCopy(source[start], destination[start])
DescriptionCopies a string. This function copies a static string (which is enclosed in quotes) or a string that is stored in an array to the destination buffer.
The source string parameter accepts both static string (e.g. “source”) and char array (in the form: source[start]).
destination[start] must be an one-dimensional char array.
This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. If the length of source string exceeds the max. size of destination buffer, it returns false and the content of destination remains unchanged.
The result field is optional.
Examplemacro_command main()
char strSrc[14]=”αβθγδθε”      //αβθγδθε
char strDest[14]
bool result
 
result = UnicodeCopy(strSrc[0], strDest[0]) // “result” will be set to true.
result = UnicodeCopy(“αβθγδθε”, strDest[0])
// “result” will be set to true, strDest = αβθγδθε”
result = UnicodeCopy(“αβγδεζαβγδεζ”, strDest[0])
// “result” will be set to false.
// The size of source string exceeds the size of destination string.
 
end macro_command

UnicodeExcluding

NameUnicodeExcluding
Syntaxresult = UnicodeExcluding(source[start], set[start], destination[start])
result = UnicodeExcluding(“source”, set[start], destination[start])
result = UnicodeExcluding(source[start], “set”, destination[start])
result = UnicodeExcluding(“source”, “set”, destination[start])
DescriptionRetrieves a substring of the source string that contains characters that are not in the set string. The result string is the part of the source string beginning with the first character and ending before any character in the target string is found in the source string.
The source string and set string parameters accept both static string (in the form: “source”) and char array (in the form: source[start]).
This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false. If the length of retrieved substring exceeds the size of destination buffer, it returns
false.
Examplemacro_command main()
char source[14]=”γδξκθλθ, dest[8]
char set[4]=”λθ”
bool result
 
result = UnicodeExcluding(source[0], set[0], dest[0]) // the function succeeds.
// “result” will be set to true and “dest” will be set to “γδξκ”.
 
result = UnicodeExcluding(source[0], set[0], dest[4]) // the function fails.
// “result” will be set to false due to insufficient destination buffer size.
 
end macro_command

UnicodeLength

NameUnicodeLength
Syntaxresult = UnicodeLength(source[start])
or
result = UnicodeLength(“source”)
DescriptionObtains the length of a Unicode string.
The source string parameter accepts both static string (e.g. “source”) and char array (in the form: source[start]).
The returned value is the length of the source string.
Examplemacro_command main()
 
char strSrc[6]=”ÅÈÑ”
int result1, result2
 
result1 = UnicodeLength(strSrc[0]) // “result1” is equal to 3 result2 = UnicodeLength(“trSrc[0]) // “re2” is equal to 3
 
end macro_command

Utf82Unicode

NameUtf82Unicode
Syntaxresult = Utf82Unicode(source[start], destination[start])
DescriptionConverts the source UTF8 string to a Unicode string and stores the result in the destination buffer. This function returns a Boolean indicating whether the process has been successfully completed. If so, it returns true; otherwise it returns false.
Examplemacro_command main()
char unicode_str[20]
char utf8_str[20]

String2Unicode(“ABC”, unicode_str[0])
bool result
 
result = Unicode2Utf8(unicode_str[0], utf8_str[0])
// “result” will be set to true. “utf8_str” will equal “ABC” encoded in UTF8
StringCat(“DEF”, utf8_str[0]) // “utf8_str” will equal “ABCDEF” encoded in UTF8
 
char dst[20]
bool result2
 
result2 = Utf82Unicode(utf8_str[0], dst[0])
// “result” will be set to true. “dst” will equal “ABCDEF” encoded in Unicode.
 
end macro_command

Mathematics Functions

SQRTCalculates the square root of source.
CUBERTCalculates the cube root of source.
POWCalculates the exponential of source.
SINCalculates the sine of source.
COSCalculates the cosine of source.
TANCalculates the tangent of source.
COTCalculates the cotangent of source.
SECCalculates the secant of source.
CSCCalculates the cosecant of source.
ASINCalculates the arc sine of source.
ACOSCalculates the arc cosine of source.
ATANCalculates the arc tangent of source.
LOGCalculates the natural logarithm of a number.
LOG10Calculates the base-10 logarithm of a number.
RANDCalculates a random integer.
CEILGet the smallest integral value that is not less than input.
FLOORGet the largest integral value that is not greater than input.
ROUNDGet the integral value that is nearest the input.

SQRT

NameSQRT
SyntaxSQRT(source, result)
DescriptionCalculates the square root of source and stores the result into result. source can be a constant or a variable. result must be a variable. source must be a nonnegative value.
Examplemacro_command main()
float source, result

SQRT(15, result)

source = 9.0
SQRT(source, result) //    result is 3.0
 
end macro_command

CUBERT

NameCUBERT
SyntaxCUBERT(source, result)
DescriptionCalculates the cube root of source and stores the result into result. source can be a constant or a variable. result must be a variable. source must be a nonnegative value.
Examplemacro_command main()
float source, result

CUBERT (27, result) // result is 3.0

source = 27.0
CUBERT(source, result) //    result is 3.0
 
end macro_command

POW

NamePOW
SyntaxPOW(source1, source2, result)
DescriptionCalculates source1 to the power of source2.
source1 and source2 can be a constant or a variable.
result must be a variable.
source1 and source2 must be a nonnegative value.
Examplemacro_command main()

float y, result
y = 0.5
POW (25, y, result) // result = 5

end macro_command

SIN

NameSIN
SyntaxSIN(source, result)
DescriptionCalculates the sine of source (degree) into result.
source can be a constant or a variable. result must be a variable.
Examplemacro_command main()
float source, result

SIN(90, result) //    result is 1

source = 30
SIN(source, result) //    result is 0.5
 
end macro_command

COS

NameCOS
SyntaxCOS(source, result)
DescriptionCalculates the cosine of source (degree) into result.
source can be a constant or a variable. result must be a variable.
Examplemacro_command main()
float source, result

COS(90, result)//   result is 0

source = 60
COS(source, result)//    result is 0.5
 
end macro_command

TAN

NameTAN
SyntaxTAN(source, result)
DescriptionCalculates the tangent of source (degree) into result.
source can be a constant or a variable. result must be a variable.
Examplemacro_command main()
float source, result

TAN(45, result) //   result is 1

source = 60
TAN(source, result) //    result is 1.732
 
end macro_command

COT

NameCOT
SyntaxCOT(source, result)
DescriptionCalculates the cotangent of source (degree) into result.
source can be a constant or a variable. result must be a variable.
Examplemacro_command main()
float source, result

COT(45, result) //   result is 1

source = 60
COT(source, result) //    result is 0.5774
 
end macro_command

SEC

NameSEC
SyntaxSEC(source, result)
DescriptionCalculates the secant of source (degree) into result.
source can be a constant or a variable. result must be a variable.
Examplemacro_command main()
float source, result

SEC(45, result) //   result is 1.414

source = 60
SEC(source, result) //    if source is 60, result is 2
 
end macro_command

CSC

NameCSC
SyntaxCSC(source, result)
DescriptionCalculates the cosecant of source (degree) into result.
source can be a constant or a variable. result must be a variable.
Examplemacro_command main()
float source, result

CSC(45, result) //    result is 1.414

source = 30
CSC(source, result) //    result is 2
 
end macro_command

ASIN

NameASIN
SyntaxASIN(source, result)
DescriptionCalculates the arc sine of source into result (degree).
source can be a constant or a variable. result must be a variable.
Examplemacro_command main()
float source, result

ASIN(0.8660, result) //    result is 60

source = 0.5
ASIN(source, result) //    result is 30
 
end macro_command

ACOS

NameACOS
SyntaxACOS(source, result)
DescriptionCalculates the arc cosine of source into result.
source can be a constant or a variable. result must be a variable.
Examplemacro_command main()
float source, result

ACOS(0.8660, result) //   result is 30

source = 0.5
ACOS(source, result) //    result is 60
 
end macro_command

ATAN

NameATAN
SyntaxATAN(source, result)
DescriptionCalculates the arc tangent of source into result.
source can be a constant or a variable. result must be a variable.
Examplemacro_command main()
float source, result

ATAN(1, result) //   result is 45

source = 1.732
ATAN(source, result) //    result is 60
 
end macro_command

LOG

NameLOG
SyntaxLOG (source, result)
DescriptionCalculates the natural logarithm of a number and saves into result.
source can be either a variable or a constant. result must be a variable.
Examplemacro_command main()
float source = 100, result

LOG (source, result)//   result is approximately 4.6052

end macro_command

LOG10

NameLOG10
SyntaxLOG10(source, result)
DescriptionCalculates the base-10 logarithm of a number and saves into result.
source can be either a variable or a constant. result must be a variable.
Examplemacro_command main()
float source = 100, result

LOG10 (source, result) // result is 2

end macro_command

RAND

NameRAND
SyntaxRAND(result)
DescriptionCalculates a random integer and saves into result. (Range: 0 ~ 32766)
result must be a variable.
Examplemacro_command main()
short result

RAND (result) //result is not a fixed value when executes macro every time

end macro_command

CEIL

NameCEIL
Syntaxresult=CEIL(source)
DescriptionGet the smallest integral value that is not less than input.
Examplemacro_command main()
 
float x = 3.8
int result

result = CEIL(x)// result = 4

end macro_command

FLOOR

NameFLOOR
Syntaxresult=FLOOR(source)
DescriptionGet the largest integral value that is not greater than input.
Examplemacro_command main()
 
float x = 3.8
int result

result = FLOOR(x) // result = 3

end macro_command

ROUND

NameROUND
Syntaxresult=ROUND(source)
DescriptionGet the integral value that is nearest the input.
Examplemacro_command main()
 
float x = 5.55
int result

result = ROUND(x) // result = 6

end macro_command

Statistics Functions

AVERAGEGets the average value from array.
HARMEANGets the harmonic mean value from array.
MAXGets the maximum value from array.
MEDIANGets the median value from array.
MINGets the minimum value from array.
STDEVPGets the standard deviation value from array.
STDEVSGets the sample standard deviation value from array.

AVERAGE

NameAVERAGE
SyntaxAVERAGE(source[start], result, count)
DescriptionGets the average value from array.
Exampleint data[5] = {1, 2, 3, 4, 5}
float result

AVERAGE(data[0], result, 5)               // result is equal to 3
AVERAGE(data[2], result, 3)          // result is equal to 4

HARMEAN

NameHARMEAN
SyntaxHARMEAN(source[start], result, count)
DescriptionGets the harmonic mean value from array.
Exampleint data[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
float result

HARMEAN(data[0], result, 10)           // result is equal to 3.414

MAX

NameMAX
SyntaxMAX(source[start], result, count)
DescriptionGets the maximum value from array.
Exampleint data[5] = {1, 2, 3, 4, 5}
int result

MAX(data[0], result, 5)           // result is equal to 5
MAX(data[1], result, 3) // result is equal to 4

MEDIAN

NameMEDIAN
SyntaxMEDIAN(source[start], result, count)
DescriptionGets the median value from array.
Exampleint data[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
float result

MEDIAN(data[0], result, 10)   // result is equal to 5.5

MIN

NameMIN
SyntaxMIN(source[start], result, count)
DescriptionGets the minimum value from array.
Exampleint data[5] = {1, 2, 3, 4, 5}
int result

MIN(data[0], result, 5)            // result is equal to 1
MIN(data[1], result, 3)  // result is equal to 2

STDEVP

NameSTDEVP
SyntaxSTDEVP(source[start], result, count)
DescriptionGets the standard deviation value from array.
Exampleint data[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
float result

STDEVP(data[0], result, 10)    // result is equal to 2.872

STDEVS

NameSTDEVS
SyntaxSTDEVS(source[start], result, count)
DescriptionGets the sample standard deviation value from array.
Exampleint data[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
float result

STDEVS(data[0], result, 10)      // result is equal to 3.027

Recipe Database Functions

RecipeGetDataGets recipe Data.
RecipeQueryQueries recipe data.
RecipeQueryGetDataGets the data in the query result obtained by RecipeQuery.
RecipeQueryGetRecordIDGets the record ID numbers of those records gained by
RecipeQuery.
RecipeSetDataWrites data to recipe database.
RecipeTransactionBeginInitiates bulk writing of recipes. Must be used in conjunction with RecipeTransactionCommit or RecipeTransactionRollback.
This function is supported only on cMT / cMT X Series.
RecipeTransactionCommitExecutes bulk writing of recipes.
This function is supported only on cMT / cMT X Series.
RecipeTransactionRollbackRolls back bulk writing of recipes.
This function is supported only on cMT / cMT X Series.

RecipeGetData

NameRecipeGetData
SyntaxRecipeGetData(destination, recipe_address, record_ID)
DescriptionGets Recipe Data. The gained data will be stored in destination, and must be a variable. recipe_address consists of recipe name and item name:
“recipe_name.item_name”. record_ID specifies the ID number of the record in
recipe being gained.
Examplemacro_command main()

int data=0
char str[20]
int recordID
bool result

recordID = 0
result = RecipeGetData(data, “TypeA.item_weight”, recordID)
// From recipe “TypeA” get the data of the item “item_weight” in record 0.

recordID = 1
result = RecipeGetData(str[0], “TypeB.item_name”, recordID)
// From recipe “TypeB” get the data of the item “item_name” in record 1.

end macro_command

RecipeQuery

NameRecipeQuery
SyntaxRecipeQuery (SQL_command, destination)
DescriptionUses SQL statement to query recipe data. The number of records of query result will be stored in the destination. This must be a variable. SQL command can be static string or char array. Example:
RecipeQuery(“SELECT * FROM TypeA”, destination)
or
RecipeQuery(sql[0], destination)
SQL statement must start with “SELECT * FROM” followed by recipe name and
query condition.
Examplemacro_command main()

int total_row=0
char sql[100]=”SELECT * FROM TypeB”
short var
bool result

result = RecipeQuery(“SELECT * FROM TypeA”, total_row)
//    Query Recipe “TypeA”. Store the number of records of query result in total_row.

result = RecipeQuery(sql[0], total_row)
//    Query Recipe “TypeB”. Store the number of records of query result in total_row.

result = RecipeQuery(“SELECT * FROM Recipe WHERE Item >%(var)”, total_row)
//     Query “Recipe”, where “Item” is larger than var. Store the number of records of
// query result in total_row.

end macro_command

RecipeQueryGetData

NameRecipeQueryGetData
SyntaxRecipeQueryGetData (destination, recipe_address, result_row_no)
DescriptionGets the data in the query result obtained by RecipeQuery. This function must be called after calling RecipeQuery, and specify the same recipe name in recipe_address as RecipeQuery.
result_row_no specifies the sequence row number in query result
Examplemacro_command main()

int data=0
int total_row=0
int row_number=0
bool result_query
bool result_data

result_query = RecipeQuery(“SELECT * FROM TypeA”, total_row)
// Query Recipe “TypeA”. Store the number of records of query result in total_row.

if (result_query) then
for row_number=0 to total_row-1
result_data = RecipeQueryGetData(data, “TypeA.item_weight”, row_number)
next row_number
end if

end macro_command

RecipeQueryGetRecordID

NameRecipeQueryGetRecordID
SyntaxRecipeQueryGetRecordID (destination, result_row_no)
DescriptionGets the record ID numbers of those records gained by RecipeQuery. This function must be called after calling RecipeQuery.
result_row_no specifies the sequence row number in query result, and write
the obtained record ID to destination.
Examplemacro_command main()

int recordID=0
int total_row=0
int row_number=0
bool result_query
bool result_id

result_query = RecipeQuery(“SELECT * FROM TypeA”, total_row)
// Query Recipe “TypeA”. Store the number of records of query result in total_row.

if (result_query) then
for row_number=0 to total_row-1
result_id = RecipeQueryGetRecordID(recordID, row_number)
next row_number
end if

end macro_command

RecipeSetData

NameRecipeSetData
SyntaxRecipeSetData(source, recipe address, record_ID)
DescriptionWrites data to recipe. If success, returns true, else, returns false. recipe_address consists of recipe name and item name: “recipe_name.item_name”.
record_ID specifies the ID number of the record in recipe being modified.
Examplemacro_command main()

int data=99
char str[20]=”abc”
int recordID
bool result

recordID = 0
result = RecipeSetData(data, “TypeA.item_weight”, recordID)
// set data to recipe “TypeA”, where item name is “item_weight” and record ID is 0.

recordID = 1
result = RecipeSetData(str[0], “TypeB.item_name”, recordID)
// set data to recipe “TypeB”, where item name is “item_name” and record ID is 1.

end macro_command

RecipeTransactionBegin

NameRecipeTransactionBegin
SyntaxRecipeTransactionBegin ()
DescriptionInitiates bulk writing of recipes. Must be used in conjunction with RecipeTransactionCommit or RecipeTransactionRollback.

All recipe writing actions between RecipeTransactionBegin and RecipeTransactionCommit will be executed at once after the Commit
command.

All recipe writing actions between RecipeTransactionBegin and RecipeTransactionRollback will be completely rolled back after the Rollback command.

Warning
If neither RecipeTransactionCommit nor RecipeTransactionRollback is called before the macro ends, the system will automatically call RecipeTransactionRollback to roll back the writing, and the following warning message will appear in the cMT Diagnoser: “DB Transaction ended without commit/rollback, and rolled back all changes automatically.”
If RecipeTransactionBegin() is called repeatedly, the following warning message will appear in the cMT Diagnoser: “Cannot start a transaction within a
transaction.”

Note
When using RecipeTransactionBegin, minimize the time between RecipeTransactionBegin and RecipeTransactionCommit/RecipeTransactionRollback to avoid system anomalies caused by other objects operating in the recipe database
simultaneously.
Examplemacro_command main()
int data = 99
char str[20] = “abc”
int recordID = 0
bool result

result = RecipeSetData(data, “TypeA.item_weight”, recordID)
// Write data to the “item_weight” field of recipe “TypeA” with Record ID 0

RecipeTransactionBegin()
recordID = 1
result = RecipeSetData(str[0], “TypeB.item_name”, recordID) RecipeTransactionCommit()
// Write data to the “item_name” field of recipe “TypeB” with Record ID 1

RecipeTransactionBegin() recordID = 2
result = RecipeSetData(str[0], “TypeB.item_name”, recordID) RecipeTransactionRollback()
// Since the bulk writing of the recipe is rolled back, the Record ID remains 1

end macro_command

RecipeTransactionCommit

NameRecipeTransactionCommit
SyntaxRecipeTransactionCommit ()
DescriptionExecutes bulk writing of recipes. Must be used in conjunction with RecipeTransactionBegin.

All recipe writing actions between RecipeTransactionBegin and RecipeTransactionCommit will be executed at once after the Commit command.

Warning
If RecipeTransactionCommit is called without first calling
RecipeTransactionBegin, the system will display the following warning message in the cMT Diagnoser: “Cannot commit – no transaction is active.”
ExamplePlease refer to the RecipeTransactionBegin example above

RecipeTransactionRollback

NameRecipeTransactionRollback
SyntaxRecipeTransactionRollback ()
DescriptionRolls back bulk writing of recipes. Must be used in conjunction with RecipeTransactionBegin.

All recipe writing actions between RecipeTransactionBegin and RecipeTransactionRollback will be completely rolled back after the Rollback command.

Warning
If RecipeTransactionRollback is called without first calling
RecipeTransactionBegin, the system will display the following warning message in the cMT Diagnoser: “Cannot rollback – no transaction is active.”
ExamplePlease refer to the RecipeTransactionBegin example above

Data / Event Log Functions

FindDataSamplingDateFinds the date of the specified data sampling file.
FindDataSamplingIndexFinds the file index of the specified data sampling file.
FindEventLogDateFinds the date of the specified event log file.
FindEventLogIndexFinds the file index of the specified event log file.

FindDataSamplingDate

NameFindDataSamplingDate
Syntaxreturn_value = FindDataSamplingDate (data_log_number, index, year, month, day)
or
FindDataSamplingDate (data_log_number, index, year, month, day)
DescriptionA query function for finding the date of specified data sampling file according to the data sampling no. and the file index. The date is stored into year, month and day respectively in the format of YYYY, MM and DD.

The directory of saved data: [Storage location][filename]yyyymmdd.dtl. The data sampling files under the same directory are sorted according to the file name and are indexed starting from 0. The most recently saved file has the
smallest file index number.

For example, if there are four data sampling files as follows:
20101210.dtl
20101230.dtl
20110110.dtl
20110111.dtl

The file index are:
20101210.dtl -> index is 3 20101230.dtl -> index is 2 20110110.dtl -> index is 1 20110111.dtl -> index is 0

return_value equals to 1 if referred data sampling file is successfully found, otherwise it equals to 0.
data_log_number and index can be constant or variable. year, month, day and
return_value must be variable. return_value is optional.
Examplemacro_command main()

short data_log_number = 1, index = 2, year, month, day
short success

// if there exists a data sampling file named 20101230.dtl, with data sampling
// number 1 and file index 2.
// the result after execution: success == 1, year == 2010, month == 12 and
//day== 30

success = FindDataSamplingDate(data_log_number, index, year, month, day)

end macro_command

FindDataSamplingIndex

NameFindDataSamplingIndex
Syntaxreturn_value = FindDataSamplingIndex (data_log_number, year, month, day, index)
or
FindDataSamplingIndex (data_log_number, year, month, day, index)
DescriptionA query function for finding the file index of specified data sampling file
according to the data sampling no. and the date. The file index is stored into index. year, month and day are in the format of YYYY, MM and DD respectively.

The directory of saved data: [Storage location][filename]yyyymmdd.dtl. The data sampling files under the same directory are sorted according to the file name and are indexed starting from 0. The most recently saved file has the smallest file index number.

For example, if there are four data sampling files as follows:
20101210.dtl
20101230.dtl
20110110.dtl
20110111.dtl

The file index are:
20101210.dtl -> index is 3
20101230.dtl -> index is 2
20110110.dtl -> index is 1
20110111.dtl -> index is 0

return_value equals to 1 if referred data sampling file is successfully found, otherwise it equals to 0.
data_log_number, year, month and day can be constant or variable. index and
return_value must be variable. return_value is optional.
Example

FindEventLogDate

NameFindEventLogDate
Syntaxreturn_value = FindEventLogDate (index, year, month, day)
or
FindEventLogDate (index, year, month, day)
DescriptionA query function for finding the date of specified event log file according to file index. The date is stored into year, month and day respectively in the format of YYYY, MM and DD.

The event log files stored in the designated position (such as HMI memory storage or external memory device) are sorted according to the file name and are indexed starting from 0. The most recently saved file has the smallest file index number.

For example, if there are four event log files as follows:
EL_20101210.evt
EL_20101230.evt
EL_20110110.evt
EL_20110111.evt

The file index are:
EL_20101210.evt -> index is 3
EL_20101230.evt -> index is 2
EL_20110110.evt -> index is 1
EL_20110111.evt -> index is 0

return_value equals to 1 if referred data sampling file is successfully found, otherwise it equals to 0.
index can be constant or variable. year, month, day and return_value must be
variable. return_value is optional.
Examplemacro_command main()

short index = 1, year, month, day
short success

// if there exists an event log file named EL_20101230.evt,with index 1
// the result after execution: success == 1, year == 2010, month == 12, day
//==30

success = FindEventLogDate (index, year, month, day)

end macro_command

FindEventLogIndex

NameFindEventLogIndex
Syntaxreturn_value = FindEventLogIndex (year, month, day, index)
or
FindEventLogIndex (year, month, day, index)
DescriptionA query function for finding the file index of specified event log file according to date. The file index is stored into index. year, month and day are in the
format of YYYY, MM and DD respectively.

The event log files stored in the designated position (such as HMI memory storage or external memory device) are sorted according to the file name and are indexed starting from 0. The most recently saved file has the smallest file index number.

For example, if there are four event log files as follows:
EL_20101210.evt
EL_20101230.evt
EL_20110110.evt
EL_20110111.evt

The file index are:
EL_20101210.evt -> index is 3
EL_20101230.evt -> index is 2
EL_20110110.evt -> index is 1
EL_20110111.evt -> index is 0

return_value equals to 1 if referred data sampling file is successfully found, otherwise it equals to 0.
index can be constant or variable. year, month, day and return_value must be
variable. return_value is optional.
Examplemacro_command main()

short year = 2010, month = 12, day = 10, index
short success

// if there exists an event log file named EL_20101210.evt, with index 2
// the result after execution: success == 1, index == 2 success = FindEventLogIndex (year, month, day, index)

end macro_command

Checksum Functions

ADDSUMAdds up the elements of an array to generate a checksum.
XORSUMUses XOR to calculate the checksum.
BCCSame as XORSUM.
CRCCalculates the 16-bit CRC of variables to generate a checksum.
CRC8Calculates the 8-bit CRC of variables to generate a checksum.
CRC16_CCITTCalculates the 16-bit CRC of variables to generate a CRC16_CCITT checksum.
CRC16_CCITT_FALSECalculates the 16-bit CRC of variables to generate a
CRC16_CCITT_FALSE checksum.
CRC16_X25Calculates the 16-bit CRC of variables to generate a CRC16_X25 checksum.
CRC16_XMODEMCalculates the 16-bit CRC of variables to generate a
CRC16_XMODEM checksum.

ADDSUM

NameADDSUM
SyntaxADDSUM(source[start], result, data_count)
DescriptionAdds up the elements of an array (source) from source[start] to source[start + data_count – 1] to generate a checksum. Puts in the checksum into result. result must be a variable. data_count is the amount of the accumulated elements and can be a constant or a variable.
Examplemacro_command main()
char data[5]
short checksum
 
data[0] = 0x1
data[1] = 0x2
data[2] = 0x3
data[3] = 0x4
data[4] = 0x5

ADDSUM(data[0], checksum, 5) //      checksum is 0xf

end macro_command

XORSUM

NameXORSUM
SyntaxXORSUM(source[start], result, data_count)
DescriptionUses XOR to calculate the checksum from source[start] to source[start + data_count – 1]. Puts the checksum into result. result must be a variable. data_count is the amount of the calculated elements of the array and can be a constant or a variable.
Examplemacro_command main()

char data[5] = {0x1, 0x2, 0x3, 0x4, 0x5}
short checksum

XORSUM(data[0], checksum, 5) //      checksum is 0x1

end macro_command

BCC

NameBCC
SyntaxBCC(source[start], result, data_count)
DescriptionSame as XORSUM.
Examplemacro_command main()

char data[5] = {0x1, 0x2, 0x3, 0x4, 0x5}
char checksum

BCC(data[0], checksum, 5)     // checksum is 0x1

end macro_command

CRC

NameCRC
SyntaxCRC(source[start], result, data_count)
DescriptionCalculates 16-bit CRC of the variables from source[start] to source[start + data_count – 1]. Puts in the 16-bit CRC into result. result must be a variable. data_count is the amount of the calculated elements of the array and can be a constant or a variable.
Examplemacro_command main()

char data[5] = {0x1, 0x2, 0x3, 0x4, 0x5}
short checksum

CRC(data[0], checksum, 5)     // checksum is 0xbb2a, 16-bit CRC

end macro_command

CRC8

NameCRC8
SyntaxCRC8(source[start], result, data_count)
DescriptionCalculates 8-bit CRC of the variables from source[start] to source[start + data_count – 1]. Puts in the 8-bit CRC into result. result must be a variable. data_count is the amount of the calculated elements of the array and can be a
constant or a variable.
Examplemacro_command main()

char source[5] = {1, 2, 3, 4, 5}
short CRC8_result

CRC8(source[0], CRC8_result, 5)
// CRC8_result = 188

end macro_command

CRC16_CCITT

NameCRC16_CCITT
SyntaxCRC16_CCITT (source[start], result, data_count)
DescriptionCalculates 16-bit CRC of the variables from source[start] to source[start + data_count – 1] using CRC-16/CCITT algorithm. Puts in the 16-bit CRC into result. result must be a variable.
data_count is the amount of the calculated elements of the array and can be a
constant or a variable.
Examplemacro_command main()

char source[5] = “12345”
short crc_result

CRC16_CCITT(source[0], crc_result, 5)    //crc_result = 0xA5A2

end macro_command

CRC16_CCITT_FALSE

NameCRC16_CCITT_FALSE
SyntaxCRC16_CCITT_FALSE (source[start], result, data_count)
DescriptionCalculates 16-bit CRC of the variables from source[start] to source[start + data_count – 1] using CRC-16/CCITT-FALSE algorithm. Puts in the 16-bit CRC into result. result must be a variable.
data_count is the amount of the calculated elements of the array and can be a
constant or a variable.
Examplemacro_command main()

char source[5] = “12345”
short crc_result

CRC16_CCITT_FALSE(source[0], crc_result, 5)     // crc_result = 0x4560

end macro_command

CRC16_X25

NameCRC16_X25
SyntaxCRC16_X25 (source[start], result, data_count)
DescriptionCalculates 16-bit CRC of the variables from source[start] to source[start + data_count – 1] using CRC16/X25 algorithm. Puts in the 16-bit CRC into result. result must be a variable.
data_count is the amount of the calculated elements of the array and can be a
constant or a variable.
Examplemacro_command main()

char source[5] = “12345”
short crc_result

CRC16_X25(source[0], crc_result, 5)    //crc_result = 0xBB40

end macro_command

CRC16_XMODEM

NameCRC16_XMODEM
SyntaxCRC16_XMODEM (source[start], result, data_count)
DescriptionCalculates 16-bit CRC of the variables from source[start] to source[start + data_count – 1] using CRC16/XMODEM algorithm. Puts in the 16-bit CRC into result. result must be a variable.
data_count is the amount of the calculated elements of the array and can be a
constant or a variable.
Examplemacro_command main()

char source[5] = “12345”
short crc_result

CRC16_ XMODEM(source[0], crc_result, 5)     // crc_result = 0x546C

end macro_command

Miscellaneous Functions

BeepPlays beep sound.
BuzzerTurns ON / OFF the buzzer.
TRACEPrints out the current value of variables during run-time of
macro for debugging.
GetCnvTagArrayIndexWhen an user-defined conversion tag uses array, the [Read conversion] subroutine can get the relative array index before
doing conversion.

Beep

NameBeep
SyntaxBeep ()
DescriptionPlays beep sound.

This command plays a beep sound with frequency of 800 hertz and duration of
30 milliseconds.
Examplemacro_command main()

Beep()

end macro_command

Buzzer

NameBuzzer
SyntaxBuzzer (state)
DescriptionTurns ON / OFF the buzzer.
Examplemacro_command main()

char on = 1, off = 0

Buzzer(on) //    turn on the buzzer

DELAY(1000)   //    delay 1 second

Buzzer(off) //    turn off the buzzer

DELAY(500) //    delay 500ms

Buzzer(1)    //    turn on the buzzer

DELAY(1000)   //    delay 1 second

Buzzer(0)    //    turn off the buzzer

end macro_command

TRACE

NameTRACE
SyntaxTRACE(format, argument)
DescriptionUse this function to send specified string to the EasyDiagnoser / cMT
Diagnoser. Users can print out the current value of variables during run-time of
macro for debugging.

When TRACE encounters the first format specification (if any), it converts the value of the first argument after format and outputs it accordingly.

format refers to the format control of output string. A format specification, which consists of optional (in [ ]) and required fields (in bold underlined font), has the following form:
%[flags] [width] [.precision] type
Each field of the format specification is described as below:
flags (optional):
– : Aligns left. When the value has fewer characters than the specified width, it will be padded with spaces on the left.
+ : Precedes the result with a plus or minus sign (+ or -)
width (optional):
A nonnegative decimal integer controlling the minimum number of characters printed.
precision (optional):
A nonnegative decimal integer which specifies the precision and the number of characters to be printed.
type:
C or c     : specifies a single-byte character d  : signed decimal integer
i              : signed decimal integer
o            : unsigned octal integer
u            : unsigned decimal integer
X or x     : unsigned hexadecimal integer
lld          : signed long integer (64-bit) (cMT / cMT X Series only) llu : unsigned long integer (64-bit) (cMT / cMT X Series only) f     : signed floating-point value
llf           : double-precision floating-point value
E or e  : Scientific notation in the form “[ – ]d.dddd e [sign]ddd” , where d is a single decimal digit, dddd is one or more decimal digits, ddd is exactly three decimal digits, and sign is + or –.

The length of output string is limited to 256 characters. Extra characters will be ignored.
The argument part is optional. One format specification converts exactly one
argument.
Examplemacro_command main()

char c1 = ‘a’
short s1 = 32767
float f1 = 1.234567

TRACE(“The results are”) // output: The results are
TRACE(“c1 = %c, s1 = %d, f1 = %f”, c1, s1, f1)
// output: c1 = a, s1 = 32767, f1 = 1.234567

end macro_command

GetCnvTagArrayIndex

NameGetCnvTagArrayIndex
SyntaxGetCnvTagArrayIndex(array_index)
DescriptionWhen a user-defined conversion tag uses array, the GetCnvTagArrayIndex() function of [Read conversion] subroutine can get the relative array index before doing conversion.
ExampleSub short newfun(short param)

int index
GetCnvTagArrayIndex(index)
If index is 2, the third data record in the array will be converted.
return param

end sub