The TBASIC compiler in TRiLOGI Version 4.0
supports full 32-bit integer computations. All integer constants are treated as 32-bits
and there are 26 variables (A to Z ) that are 32 bits in length. These variables can
represent numbers between -231 to +231. The remaining system variables and data memory
DM[n] are all 16-bit variables which means that they can only store numbers between -32768
to +32767. These 16-bit variables are:
DM[1]..DM[4000] (Total = 4000), input[n],
output[n], relay[n], timerbit[n], ctrbit[n], timerPV[n],ctrPV[n], HSCPV[n], (High Speed
Counter). TIME[n], DATE[n].
However, all numeric computations in TBASIC
are carried out in 32-bit signed integers, regardless of the bit-length of the variables
involved in the numerical expression. All variables used in TBASIC are "GLOBAL
variables - this means that all these variables are shared and accessible by any of the
128 custom functions.
a) Assignment Operator: A string variable (A to Z, DM and
system variables, etc) may be assigned a string expression using the assignment statement:
A$ = "Hello, Welcome To TBASIC"
Z$ = MID$(A$,3,5)
b) Concatenation Operators: Two or more strings can be
concatenated (joined together) simply by using the "+" operator. e.g.
M$ = "Hello " + A$ + ", welcome to " + B$
If A$ contains "James", and B$ contains
"TBASIC", M$ will contain the string: "Hello James, welcome to TBASIC.
c) Comparison Operators: Two strings may be compared for
equality by using the function STRCMP(A$,B$). However, the integer comparator such as
"=", "<>", etc cannot be used for string comparison.
Command |
Purpose |
ABS(x) |
To return the absolute value of x |
ADC(n) |
To return the value from the A/D
Converter #n. |
ASC(x$,n) |
To return the ASCII code for the nth
char. of x$. |
CALL n |
To call another Custom Function
CusFn #n. |
CHR$(n) |
To convert a number n into
its corresponding ASCII character. n must be between 0 and 255) |
CLRBIT v,n |
To clear the Bit #n of the
integer variable v to '0'. |
FOR ... NEXT |
To execute a series of instructions
for a specified number of times in a loop. |
GetCtrSV (n) GetTimerSV (n) |
Return the Set Value (S.V) of
Counter or Timer #n. |
GETHIGH16(v) |
returns the upper 16-bit of a
32-bit integer variable |
GOTO @ n |
To branch unconditionally to a
specified line with label @n within the present Custom Function. |
HEX$(n) |
To return a hexadecimal string
expression of n. |
HEXVAL(x$) |
To convert hexadecimal number in
string x$. |
HSTIMER n |
To define PLC Timer #1 to #n as
High Speed Timers (HST) with time-base of 0.01s. |
HSCDEF ch, fn,v |
Enable and set up parameters for
the High Speed Counters channel ch. |
HSCOFF ch |
Disable High Speed Counter #ch |
IF .. THEN .. ELSE .. ENDIF |
To make a decision regarding
program flow based on the result returned by an expression |
INPUT$(ch) |
To get a string from communication
port ch. |
INTRDEF ch, fn,e |
Enable Interrupt Input channel ch
and the interrupt service routine CusFn # fn |
INTROFF ch |
Disable Interrupt Input channel ch. |
LEN(x$) |
To return the number of characters
in x$. |
LOAD_EEP(addr) |
To obtain16-bit integer value from
the EEPROM. |
LSHIFT i,n |
To shift 1 bit to the left the
16-bit integer variable I, |
MID$(x$,n,m) |
To extract a string of m
characters from x$, beginning from the nth character |
PAUSE |
To set a breakpoint for executing
the CusFn |
PIDdef ch, lmt, P,I,D |
To set up the parameters for a
Proportional, Integral and Derivative (PID) Controller function. |
PIDcompute (ch,E) |
Computes the output for the error E
using the P,I,D value set by the PIDdef command. |
PRINT# n x$;.. y; z.... |
To send the string formed by
parameter list (x$; y; z) to communication port # n. |
PMON ch PMOFF ch |
PMON enables Pulse Measurement
Function at channel #ch. PMOFF disables the channel |
PULSEFREQUENCY PULSEPERIOD
PULSEWIDTH |
Return in Hz the frequency of the
last input pulse ; Return in milli-seconds the width and period of the input pulses
arriving at channel ch. |
REFRESH |
To immediately refresh of the
physical outputs. |
RESET |
To perform a software reset of the
PLC |
RETURN |
Unconditionally return to the
caller function. |
REM (or ') |
Put explanatory remarks in the
program. |
RSHIFT i,n |
To shift the integer variable i
1 bit to the right. |
SAVE_EEP data, addr |
To store a 16-bit integer data
in the user's definable EEPROM address addr. |
SETBAUD ch, baud |
To set the communication Baud
Rate of the PLC's serial channel #ch |
SETBIT v,n |
To set the bit #n of the
integer variable v to '1'. |
SetCtrSV n, val SetTimerSV n, val |
Change the Set Value (S.V,) of the
Counter #n or Timer #n to value |
SETDAC n, x |
To set D/A converter #n to x |
SETTHIGH16 v,d |
To assign the upper 16-bit of a
32-bit variable v |
SETPWM n, x, y |
To set PWM channel #n with
duty cycle x%. |
STEPCOUNT(ch) |
Track the number of steps sent
since STEPMOVE. |
STEPSPEED ch, pps, acc |
Set the speed pps and acc
for the PLC's stepper motor controller (pulse-generator) channel #ch. |
STEPMOVE ch, count, r |
Activate the stepper motor pulse
generator channel #ch to output count number of pulses. |
STEPSTOP |
Immediately terminate Stepper
controller #n |
STR$(n) |
Convert the number n into a
string expression. |
STRCMP(A$, B$) |
Comparison of two strings: A$ and
B$. |
STRUPR$(A$) |
To return all upper-case copy of
A$. |
STRLWR$(A$) |
To return all-lower-case copy of
A$. |
TESTBIT (v,n) |
To return the logic state of bit #n
of the variable v. |
WHILE expression ....
ENDWHILE |
To execute a series of statements
in a loop as long as a given condition is true. |
VAL(x$) |
To return a value of a number in
the string x$. |