Tms Script
Tms Script
Table of Contents
Part I Introduction 1
1 Welcome
...................................................................................................................................
topic 1
I
II TMS Script Manual
System library.......................................................................................................................................................... 14
.......................................................................................................................................................... 16
VBScript library
..........................................................................................................................................................
UPA-USB Device Programmer library - UUPROG 17
.......................................................................................................................................................... 19
Hex Editor Component
Other Libraries.......................................................................................................................................................... 20
2 Declaring
...................................................................................................................................
forms in script 22
Index 0
1 Introduction
1.1 Welcome topic
2 Language Features
2.1 Pascal syntax
2.1.1 Overview
Pascal syntax supports:
· begin .. end constructor
· procedure and function declarations
· if .. then .. else constructor
· for .. to .. do .. step constructor
· while .. do constructor
· repeat .. until constructor
· try .. except and try .. finally blocks
· case statements
· array constructors (x:=[ 1, 2, 3 ];)
· ^ , * , / , and , + , - , or , <> , >=, <= , = , > , < , div , mod , xor , shl , shr operators
· access to object properties and methods ( ObjectName.SubObject.Property )
SCRIPT 1:
procedure DoSomething;
begin
CallSomething;
end;
begin
CallSomethingElse;
end;
SCRIPT 2:
begin
CallSomethingElse;
end;
SCRIPT 3:
function MyFunction;
begin
result:='Ok!';
end;
SCRIPT 4:
CallSomethingElse;
Like in pascal, statements should be terminated by ";" character. Begin..end blocks are allowed to
group statements.
2.1.3 Identifiers
Identifier names in script (variable names, function and procedure names, etc.) follow the most
common rules in pascal : should begin with a character (a..z or A..Z), or '_', and can be followed by
alphanumeric chars or '_' char. Cannot contain any other character os spaces.
Valid identifiers:
VarName
_Some
V1A2
_____Some____
Invalid identifiers:
2Var
My Name
Some-more
This,is,not,valid
2.1.6 Comments
Comments can be inserted inside script. You can use // chars or (* *) or { } blocks. Using // char the
comment will finish at the end of line.
//This is a comment before ShowMessage
ShowMessage('Ok');
(* This is another comment *)
ShowMessage('More ok!');
{ And this is a comment
with two lines }
ShowMessage('End of okays');
2.1.7 Variables
There is a need to declare variable types in script. The compiler will raise an error if a variable is
used but not declared in
script. Examples:
SCRIPT 1:
procedure Msg;
var S;
begin
S:='Hello world!';
ShowMessage(S);
end;
SCRIPT 2:
var A;
begin
A:=0;
A:=A+1;
end;
SCRIPT 3:
var S: string;
begin
S:='Hello World!';
ShowMessage(S);
end;
2.1.8 Indexes
Strings, arrays and array properties can be indexed using "[" and "]" chars. For example, if Str is a
string variable, the expression Str[3] returns the third character in the string denoted by Str, while
Str[I
+ 1] returns the character immediately after the one indexed by I. More examples:
MyChar:=MyStr[2];
MyStr[1]:='A';
MyArray[1,2]:=1530;
Lines.Strings[2]:='Some text';
2.1.9 Arrays
Script support array constructors and support to variant arrays. To construct an array, use "[" and
"]"
chars. You can construct multi-index array nesting array constructors. You can then access arrays
using indexes. If array is multi-index, separate indexes using ",".
If variable is a variant array, script automatically support indexing in that variable. A variable is a
variant
array is it was assigned using an array constructor, if it is a direct reference to a Delphi variable
which
is a variant array (see Delphi integration later) or if it was created using VarArrayCreate procedure.
Arrays in script are 0-based index. Some examples:
NewArray := [ 2,4,6,8 ];
Num:=NewArray[1]; //Num receives "4"
MultiArray := [ ['green','red','blue'] , ['apple','orange','lemon'] ];
Str:=MultiArray[0,2]; //Str receives 'blue'
MultiArray[1,1]:='new orange';
2.1.10 If statements
There are two forms of if statement: if...then and the if...then...else. Like normal pascal, if the if
expression is true, the statement (or block) is executed. If there is else part and expression is false,
statement (or block) after else is execute. Examples:
if J <> 0 then
Result := I/J;
if J = 0 then
Exit
else
Result := I/J;
if J <> 0 then
begin
Result := I/J;
Count := Count + 1;
end
else
Done := True;
while I > 0 do
begin
if Odd(I) then Z := Z * X;
I := I div 2;
X := Sqr(X);
end;
repeat
Write('Enter a value (0..9): ');
Readln(I);
until (I >= 0) and (I <= 9);
for c:=1 to 10 do
a:=a+c;
SCRIPT 2:
for i:=a to b do
begin
j:=i^2;
sum:=sum+j;
end;
procedure UpcaseMessage(Msg);
begin
ShowMessage(Uppercase(Msg));
end;
function TodayAsString;
begin
result:=DateToStr(Date);
end;
function Max(A,B);
begin
if A>B then
result:=A
else
result:=B;
end;
SCRIPT 2:
CallSomethingElse
SCRIPT 3:
FUNCTION MyFunction
MyFunction = "Ok!"
END FUNCTION
Like in normal basic, statements in a single line can be separated by ":" character.
2.2.3 Identifiers
Identifier names in script (variable names, function and procedure names, etc.) follow the most
common rules in basic : should begin with a character (a..z or A..Z), or '_', and can be followed by
alphanumeric chars or '_' char. Cannot contain any other character or spaces.
Valid identifiers:
VarName
_Some
V1A2
_____Some____
Invalid identifiers:
2Var
My Name
Some-more
This,is,not,valid
2.2.7 Comments
Comments can be inserted inside script. You can use ' chars or REM. Comment will finish at the
end of
line. Examples:
' This is a comment before ShowMessage
ShowMessage("Ok")
REM This is another comment
ShowMessage("More ok!")
' And this is a comment
' with two lines
ShowMessage("End of okays")
2.2.8 Variables
There is a need to declare variable types in script. The compiler will raise an error if a variable is
used but not declared in
script. Examples:
SCRIPT 1:
SUB Msg
DIM S
S = "Hello world!"
ShowMessage(S)
END SUB
SCRIPT 2:
DIM A
A = 0
A = A+1
ShowMessage(A)
You can also declare global variables as private or public using the following syntax:
SCRIPT 3:
PRIVATE A
PUBLIC B
B = 0
A = B + 1
ShowMessage(A)
Variable declared with DIM statement are public by default. Private variables are not accessible from
other scripts.
Variables can be default initialized with the following syntax
DIM A = "Hello world"
DIM B As Integer = 5
2.2.9 Indexes
Strings, arrays and array properties can be indexed using "[" and "]" chars. For example, if Str is a
string variable, the expression Str[3] returns the third character in the string denoted by Str, while
Str[I
+ 1] returns the character immediately after the one indexed by I. More examples:
MyChar = MyStr[2]
MyStr[1] = "A"
MyArray[1,2] = 1530
Lines.Strings[2] = "Some text"
2.2.10 Arrays
Script support array constructors and support to variant arrays. To construct an array, use "[" and
"]"
chars. You can construct multi-index array nesting array constructors. You can then access arrays
using indexes. If array is multi-index, separate indexes using ",".
If variable is a variant array, script automatically support indexing in that variable. A variable is a
variant
array is it was assigned using an array constructor, if it is a direct reference to a Delphi variable
which
is a variant array (see Delphi integration later) or if it was created using VarArrayCreate procedure.
Arrays in script are 0-based index. Some examples:
NewArray = [ 2,4,6,8 ]
Num = NewArray[1] //Num receives "4"
MultiArray = [ ["green","red","blue"] , ["apple","orange","lemon"] ]
Str = MultiArray[0,2] //Str receives 'blue'
MultiArray[1,1] = "new orange"
2.2.11 If statements
There are two forms of if statement: if...then..end if and the if...then...else..end if. Like normal basic,
if
the if expression is true, the statements are executed. If there is else part and expression is false,
statements after else are executed. Examples:
IF J <> 0 THEN Result = I/J END IF
DO UNTIL I >= 0
Write("Enter a value (0..9): ")
Readln(I)
LOOP
DO
K = I mod J
I = J
J = K
DO WHILE I < 0
Write("Enter a value (0..9): ")
Readln(I)
LOOP
SCRIPT 2:
FOR I = a TO b
j = i ^ 2
sum = sum + j
NEXT
SUB UpcaseMessage(Msg)
ShowMessage(Uppercase(Msg))
END SUB
FUNCTION TodayAsString
TodayAsString = DateToStr(Date)
END FUNCTION
FUNCTION Max(A,B)
IF A>B THEN
MAX = A
ELSE
MAX = B
END IF
END FUNCTION
SUB SwapValues(BYREF A, B)
DIM TEMP
TEMP = A
A = B
B = TEMP
END SUB
You can also declare subs and functions as private or public using the following syntax:
PRIVATE SUB Hello
END SUB
PUBLIC FUNCTION Hello
END FUNCTION
Subs and functions are public by default. Private subs and functions are not acessible from other
scripts.
You can use Return statement to exit subs and functions. For functions, you can also return a valid
value. Examples:
SUB UpcaseMessage(Msg)
ShowMessage(Uppercase(Msg))
Return
'This line will be never reached
ShowMessage("never displayed")
END SUB
FUNCTION TodayAsString
Return DateToStr(Date)
END FUNCTION
Longword
Single
Byte
Shortint
Word
Smallint
Double
Real
DateTime
Comp
Others types (records, arrays, etc.) are not supported yet. Arguments of above types can be
passed by
reference, by adding var (Pascal) or
byref (Basic) in param declaration of function.
When you execute the first script, it "uses" Script2, and then it is able to read/write global variables
and
call procedures from Script2.
The only issue here is that script 1 must "know" where to find Script2.
When the compiler reaches an identifier in the uses clause, for example:
uses Classes, Forms, Script2;
Then it tries to "load" the library in several ways. This is the what the compiler tries to do, in that
order:
1. Tries to find a registered Delphi-based library with that name.
This is the case for Classes, Forms, Windows, System and other units.
2. Tries to find a script in project scripts collection where UnitName matches the library
name
In the example above, the script1 could find the script2 as a library and use its variables and
functions.
Interpret (*)
IntToHex
IntToStr
IsLeapYear
IsValidIdent
Length
Ln
Low
LowerCase
Machine (*)
Now
Odd
Ord
Pos
Raise
Random
ReadLn
Reset
Rewrite
Round
Scripter (*)
SetOf (*)
ShowMessage
Sin
Sqr
Sqrt
StrToDate
StrToDateTime
StrToFloat
StrToInt
StrToIntDef
StrToTime
Time
TimeToStr
Trim
TrimLeft
TrimRight
Trunc
UpperCase
VarArrayCreate
VarArrayHighBound
VarArrayLowBound
VarIsNull
VarToStr
Write
WriteLn
All functions/procedures added are similar to the Delphi ones, with the exception of those marked
with
a "*", explained below:
procedure Interpret(Ascript: string);
Executes the script source code specified by Ascript parameter
function Machine: TatVirtualMachine;
Returns the current virtual machine executing the script.
LTrim
Mid
Minute
Month
MonthName
MsgBox
Replace
Right
Rnd
69 Scripter Studio Pro Manual
© 2002-2010 - TMS Software
RTrim
Second
Sgn
Space
StrComp
String
Timer
TimeSerial
TimeValue
UBound
UCase
Weekday
WeekdayName
Year
function GetSwVersion: integer; //returned AABCDD - AA major ver, B minor ver, C release.DD
Build; UUPROG: 0ABCDD; UUPROG-S: 1ABCDD
procedure GetUserDetails( var Name, Email, Company, Licenses: String )
procedure StopOnError( Enable: boolean )
procedure Select5VPowerSupply
procedure Select3VPowerSupply
procedure SelectPowerSupply( Voltage: single )
function GetPage: TForm
procedure PrevCell()
procedure ScrollLineNext()
procedure ScrollLinePrev()
function GetFileName(): string
procedure PrintFile()
function ToggleBytesPerLine(): BYTE
function GetCurrentAdr(): integer
function IntToBin( d: integer ): string
function IntToOctal( Value: Integer; Digits: byte): string
function OctalToInt( Value: string; var code: integer ): integer
function BinToInt( s: string ): integer
function GetSelection( var selStart: integer; var selEnd: integer ): boolean
procedure SetSelection( bSel: boolean; selStart, selEnd: integer )
procedure ClearSelection()
procedure DrawGrid()
procedure DrawCell( x, y: integer; size: TSize; str: string; c: TCanvas )
procedure SetDataSize( newAdr: integer )
procedure FillIn( Value: Byte )
procedure FillInCounter
procedure FillInRandom
procedure SwapBytes()
procedure MoveSelection( offset: integer )
procedure SetUpFont()
function MouseToOffset( x, y: integer ): integer
DevClass: string
ID: string
Name: string
InheritedDevName: string
e2len: byte; // length opcode
e2cap: cardinal; // EEPROM capacity in bytes
e2org: byte;
Descr: string;
e2Opr: TE2Opr; // Avalable Operations
GroupFilter: TDevGroup
DevFilter: TDevGroup
e2Tw: cardinal; // Write Time [us]
e2Tc: cardinal; // ClockTime [us]
e2Tera: cardinal; // Chip Erase Time [us]
e2Tfw: cardinal; //Flash Write Time
e2Tres: cardinal; //Reset Time [us]
e2Start: cardinal; //EEPROM Offset address
MemCap: cardinal; // All memory capacity
prStart: cardinal; // Program offset address
prCap: cardinal; // Program Capacity
confStart: cardinal; // Config Register Offset
idStart: cardinal; // ID word
idCap: cardinal; // ID Capacity
calibrStart: cardinal; // Oscilattor Calibrarion Location
BPSector: word; // Byte per Sector reprogramming
XFreq: cardinal; // Working Frequency [ kHz ]
SoftProtectA1: cardinal; //Software protection address1
SoftProtectA2: cardinal; //Software protection address2
ConfigOption: word; //Configuration Bits Form
Pin7: byte; //Pin7 = 1 -> 5V; Pin7 = 0 -> 0V
Alg: integer; //Algorithm
Package: byte; //24-28-32 pins
I2CSlave: byte;
Settings: word; //Settings No
ResetTime0: word; //ms
ResetTime1: word; //ms
PowerSetupTime: word; //ms the time that programmer will wait, before to start operation
EEWC: word; //nec EEPROM Write Control Register
LockBitsOption: word;
FuseBitsOption: word;
ChipEraseAlg: word;
TMS_WDRST: byte; //TMS Watchdog Reset Register
TMS_WDPrescaleAdr: byte; //TMS Watchdog Prescale Register
TMS_WDPrescaleData: byte;//TMS Watchdog Prescale Data
XHexEdit: TXHexEdit;
function GetDevInfo: TDevInfo;
procedure SetDevInfo( DevInfo: TDevInfo );
function ProgramDev: TTaskResult;
function DeviceProgram: TTaskResult
function DeviceRead: TTaskResult
function DeviceVerify: TTaskResult
function DeviceBlankCheck: TTaskResult
4 Script IDE