Vous êtes sur la page 1sur 57

QPScript Language

(The QPScript language is supported only on QuickPanel targets.)

Scripts are short executable programs that are a series of statements


describing various operations to be performed in sequential order. In
QuickPanel applications, these statements are written in a language called
QPScript.
Statements: There are three general kinds of statements in a QPScript
script:

Assignment statements set a variable's value to the result of an


expression.
Function calls execute one of the QPScript functions to perform a
specific operation.
Branching statements change the flow of script execution.

Keywords: The elements that make up these statements can be broken


down into the following categories:

Operators are used in mathematical expressions and conditional


expressions.
Functions are predefined routines that perform various operations in
the QuickPanel application.
Keywords are other reserved words used in the QPScript language.

Expressions: There are two general kinds of expressions in QPScript:

Mathematical expressions

Conditional expressions

In some cases, you can use Constant values or Variable References in place
of expressions.
Warning: Script execution is not as fast as other parts of QuickPanel applications, especially
scripts that access and change large amounts of variable data. NEVER use QPScript scripts for
the control of machines or actions that can result in either operator injury or damage to equipment.

QPScript Language Syntax

QPScript syntax: Assignment statements


Assignment statements set the values of variables in the application's
variable database. An assignment statement looks like the following:
[Variable Name] = [Expression]
[Variable Name] can be any variable accessible to the target. The Variable
Name must be the full name of the variable as it appears in the Variable List,
without the "TargetName." prefix. Only variables on the script's target can be
used.
Note: QPScript does not support references to array elements.

[Expression] can be any Mathematical Expression that resolves to a value


whose data type matches the data type of the variable. For BOOL variables,
the result must evaluate to 1 (True) or 0 (False).
Tip: To set the value of a specific bit of an integer variable, use the Set, Reset, or Neg functions.

Examples:
MyINT1 = 3
MyINTSum = MyINT1 + MyINT2
MyBOOL = 1
MyBOOLResult = MyBOOL1 XOR MyBOOL2

QPScript Language Syntax

QPScript syntax: Branching statements


IF clauses | LOOP clauses

Branching statements let you change the execution flow of a script. Normally,
statements in a script are executed sequentially starting from the beginning.
Branching statements let you change this, to a limited extent.
There are two methods of program branching in QPScript: IF clauses and
LOOP clauses.
IF clauses
An IF Clause lets you execute certain statements only when some condition is
met. An IF Clause uses the if, else, and endif keywords. The syntax for an
IF Clause is as follows:
if ([Conditional Expression])
[True Statement block]
else
[False Statement block]
endif
[Conditional Expression] is a conditional expression, which evaluates to True
or False.
[True Statement block] is a block of statements to execute if the condition
evaluates to True. When the else keyword is reached, execution continues
after the matching endif keyword.
[False Statement block] is a block of statements to execute if the condition
evaluates to False. The "else" and "[False Statements]" portions are optional.
Regardless, after statements in [True Statements] or [False Statements] are
executed, execution continues after "endif".
For more complicated cases, you can nest additional IF clauses within other
IF clauses. For example:
if (MyDINT > 5)
[Statement block A]

if (MyDINT == 9)
[Statement block B]
endif
else
[Statement block C]
endif
In the above example:

if MyDINT is 9, both statement block A and statement block B are


executed.
If MyDINT is greater than 5 but not equal to 9, statement block A is
executed.
Otherwise, statement block C is executed.

You can nest up to three IF clauses at a time. Additional attempts to next an


IF clause will result in an error.
Tip: Nested IF clauses can get quite confusing. You will find it easier to keep track of which "endif"
applies to which "if" and "else" if you create an indentation style and use it consistently.

LOOP clauses
Note: LOOP clauses are not supported by QuickPanel 2 models.

A loop clause lets you repeat a series of statements a specified number of


times. The syntax for a loop clause is as follows:
loop([Iterator Variable Name])
[Statement block]
break
[Statement block]
endloop
[Iterator Variable Name] can be any integer variable with an Internal data
type. You must use the full name of the variable as it appears in the Variable

List, without the "TargetName." prefix. This variable will be used as an


"iterator" during execution of the loop.
Before the loop statement, you must set the value of the iterator variable to
the number of times you want statements within the LOOP clause to execute.
If the value of the interator variable is 0 or less, statements within the LOOP
clause are not executed.
When execution of the LOOP clause reaches the endloop statement, the
value of the iterator variable is decremented by 1. If its value is 0 or less, the
loop ends and execution continues after the endloop statement. Otherwise,
execution returns to the beginning of the loop, just after the loop statement.
Thus, if no break statements are used, when the loop exits, the value of the
iterator variable will be 0.
The break statement is an optional statement, used to exit (or "break out
of") a loop early. It should be used in one of the True or False blocks in an IF
clause. Typically, break is used to exit the loop when a search for something
is successful, when a user has triggered an emergency stop variable, or when
some error condition occurs:
loop(MyIndex)
[Statement block]
if (MyErrorState == 1)
break
endif
endloop
Note: Unlike if-else-endif clauses, loop clauses cannot be nested.

QPScript Language Syntax

QPScript syntax: Function Calls


A function call executes a special predefined subroutine to perform some
operation. For example, calling the DrawCircle function draws a circle with a
specified radius on the graphical panel. A function call generally looks like the
following:
[Function Name]([Parameter List])
[Function Name] is the name of the function you want to call. This can be any
of the functions in the QPScript Functions list.
[Parameter List] is a comma-separated list of values for each of the function's
parameters. Each function has its own list of required parameters. Complete
syntax and examples are given in the description of each function.
Note: No spaces should exist between the function name and the first parenthesis ("(").

QPScript Language Syntax

QPScript syntax: Conditional expressions


Simple conditional expressions | Precedence rules

in QPScripts, conditional expressions are used in IF statements. Conditional


expressions perform a test or comparison between values. A conditional
expression can only evaluate to 1 (True) or 0 (False).
Conditional expressions with more than one operator are evaluated in a
specific order. For details, see Precedence rules below.
Notes
In QPScript, conditional expressions are only used in if statements, and are always enclosed in
parentheses ("(" and ")").

Simple Conditional expressions


[Expression 1] [Conditional operator] [Expression 2]
[Conditional operator] is one of the supported QPScript Conditional
Operators, specifying the operation to perform on the two operands. For
example, The > operator indicates a "greater than" comparsion.
[Expression 1] and [Expression 2] , are expressions that evaluate to the
values to be compared. They can be constant values, variables, or other
Mathematical Expressions.
For example:
MyINT > 6
MyINT == 3 +
MyINT2

Evaluates to 1 if MyINT is greater than 6; 0 otherwise


Evaluates to 1 if MyINT is equal to three plus MyINT2; 0
otherwise

Precedence rules for conditional expressions


Multiple operators in an expression are evaluated in the following order.
Expressions with the same priority will be executed in order, from left to
right:
First NOT
*/%

+<< >>
AND OR XOR
Last < > <= >= == <>
Notes

In QScript, The NOT, AND, OR, and XOR operators are treated as mathematical bitwise
operators between integer values. They are not treated as boolean operators.
In QPScript, a conditional expression can have only one conditional operator (<, <, <=, >=.
==, <>).

For example:
(3 > 1) OR (8 < Invalid. In QPScript, OR is used only as a bitwise operator
7)
and there can be only one conditional operator in a
conditional expression.
3 > 1 OR 8
"1 OR 8" evaluates to 9 (0001 OR 1000 = 1001); the whole
expression therefore evaluates to 3 > 9 or 0.

QPScript Language Syntax

QPScript syntax: Mathematical Expressions


Bit shift expressions | Precedence rules

In QPScript scripts, mathematical expressions evaluate to a 16-bit integer


value. Simple mathematical expressions are single items:

A numerical constant (an integer or real number)

A reference to an integer, real, or boolean variable.


Notes

The value of a boolean variable is either 0 (False) or 1 (True).

QPScript does not support references to array elements.

In general, mathematical expressions are written using infix notation:


[Expression 1] [Operator] [Expression 1]
[Operator] is a Mathematical Operator, indicating the operation to perform on
the two operands. For example, The + operator indicates addition.

When using the subtraction operator, make sure you add a space
between the "-" and the second operand. Otherwise, the dash will be
treated as a negation operator for the second operand:
MyINT1 = MyINT2 - Interpreted as "MyINT2" and "negative 3",
3
resulting in a syntax error.
MyINT1 = MyINT2-3
MyINT1 = MyINT2- Interpreted as "MyINT2 minus 3", a valid
3
expression.

When using the AND, OR, XOR, and NOT operators, the indicated
operation is performed in a bitwise mannerthat is, on each bit of the
operands' values. For example, 6 AND 3 (0110 AND 0011 in binary
notation) evaluates to 2 (0010 in binary).

[Expression 1] and [Expression 2] are expressions that indicate the two


operands on which the operation is to be performed. They can be constant

values, variables, or other mathematical expressions.


Exceptions to the above syntax are the NOT operator and the bit shift
operators (<< and >>)

Expressions using the bit shift operators have additional restrictions.


See Bit shift expressions below.
The NOT operator has only a single operand following the NOT keyword,
as in
NOT 35

More complex expressions with more than one operator are evaluated in a
specific order. This order is called precedence. See precedence rules below.
Notes

The order of expressions for the - (subtraction), / (division) and % (modulo division)
operators is important. "8 - 5" evaluates to a different value than "5 - 8".
The results of all expressions are 16-bit integer values. In the case of the division operator
(/), the fractional portion is discarded.
You cannot use conditional operators (such as "<" or "==") in a mathematical expression.

Bit shift expressions


You can also use the >> and << operators to perform shifting operations on
integer variables. Bit shift operations shift the bits of an integer variable's
value to the left (<<) or to the right (>>).
To shift a variable's value to the right, use the following expression:
[exprValue] >> [exprShiftSpaces]
To shift a variable's value to the left, use the following expression;
[exprValue] << [exprShiftSpaces]
[exprValue] is an expression that evaluates to the integer value that you
want to shift.
[exprShiftSpaces] is an integer expression indicating the number of places
that you want to shift the variable. It should evaluate to an integer from 1
through 15.
Bit shift operators are evaluated after most other mathematical operators.

See Precedence Rules below. To calculate the desired results, you may need
to enclose bit shift expressions within parentheses:
MyINT1 = (MyINT2 << 3) + (MyINT3 >> 2)
MyINT1 = (MyINT2 >> 8) * 2
If [exprValue] is the name of an integer variable and the expression appears
as a separate statement (that is, it is not part of an assignment statement or
conditional expression), the result of the shifting operation is stored in the
same variable value that it was applied to. For example, the following two
statements are functionally identical:
MyINT = MyINT << 3
MyINT << 3
Note: The above syntax is valid only if [exprValue] is an integer variable. Any other kind of
expression results in a validation error.

Precedence rules for Mathematical expressions


Multiple operators in an expression are evaluated in the following order.
Expressions with the same precedence will be executed in order, from left to
right:
First (highest
precedence):

NOT
*/%
+<< >>
AND OR XOR

Last (lowest
precedence):
You can override this order by enclosing sub-expressions in parentheses, "("
and ")".
For example:
2+5*6
(2 + 5) * 6
6 AND 3 OR
8

Evaluates to 2 + 30 = 32.
Evaluates to 7 * 6 = 42.
Evaluates first to 2 (0010, the result of 0110 AND 0011) OR 8
(1000), which itself evaluates to 10 in decimal (1010 in binary)

6 AND (3 OR Evaluates first to 6 (0110) AND 11 (1011, the result of 0011 OR


8)
1000), which itself evaluates to 2 (0010).
Any interim results of sub-expressions are stored as 16-bit integers:

If the result of a sub-expression is greater than 65535, the upper-word


portion of the result is discarded before evaluating the rest of the
expression.
If a sub-expression uses the division operator, the fractional portion of
its result is discarded before evaluating the rest of the expression.

For example, the result of


3 * (15 / 7)
is 3 * 2, or 6. The fractional portion of 15 / 7 is discarded before the rest of
the expression is evaluated.

QPScript syntax: Constants


(This topic applies only to scripts written in QPScript for QuickPanel applications.)

Constants in a script or program refer to literal values, such as 24 or 336.


Scripts written in QPScript can use integer, boolean, or floating point
constants.
Integer constants
Integer constant values are written as Decimal numbers. Octal, Hexadecimal,
and binary notation are not supported.
Right Wrong
235
16#EB
22
8x26
65,535 65,535
Boolean constants
Boolean constants are typically used when assigning values to BOOL
variables. Boolean constant values are written as integers. For False (OFF),
use 0. For True (ON), use 1. For example, to set the boolean variable
MyBOOL to "True" or "ON", use:
MyBOOL = 1
MyBOOL2 = 0
Floating point constants
Floating point constants are typically used when assigning values to REAL
variables. Floating point constant values are written in decimal notation (not
exponential).
Right
Wrong
0.314159 3.14159E-1
120000.5 1200005E6

QPScript Language

QPScript Keyword list


(This topic applies only to QuickPanel applications.)

Reserved keywords used in the QPScript language are as follows:


break

(Not supported on QuickPanel 2 models.) Can be used within a


LOOP Clause to exit the loop early.

else

Used with an IF Clause.

endif

Indicates the end of an IF Clause.

endloop (Not supported on QuickPanel 2 models.) Indicates the end of a


series of statements that are to be executed multiple times.
if

Tests a condition and performs different statements based on the


result.

loop

(Not supported on QuickPanel 2 models.) Indicates the beginning of


a series of statements that are to be executed multiple times.

QPScript Language

QPScript Operators list


(This topic applies only to QuickPanel applications.)
Mathematical Operators | Bit Shift Operators | Conditional Operators

Mathematical Operators
Mathematical operators are used in mathematical expressions. Supported
mathematical operators are as follows:
+
*
/
%
AND
OR
XOR
NOT

Addition.
Subtraction.
Multiplication.
Division. All results are truncated to the nearest integer.
Modulo division. That is, the remainder of a division operation.
AND (boolean or bitwise).
OR (boolean or bitwise).
Exclusive-OR (boolean or bitwise).
NOT (boolean or bitwise).

Bit Shift Operators


Bit shift operators perform a shift operation on a variable (see Bit Shift
Expressions). Supported bit shift operators are as follows:
<<
>>

Bit shift left.


Bit shift right.

Conditional Operators
Conditional operators are used in conditional expressions, in IF statements.
Supported conditional operators are as follows.
<
>
<>
==

Less than.
Greater than.
Not equal to.
Equal to.

<=
>=

Less than or equal to.


Greater than or equal to.

QPScript Language

QPScript Functions list


(This topic applies only to QuickPanel applications.)

Functions are predefined routines that perform various operations in a


QuickPanel script. For the general syntax for calling a function, see QPScript
syntax: Function Calls; more details are given in topics on each specific
function.
Functions that can be used in the QPScript language are as follows:
DrawCircle (Not supported by QuickPanel 2 models or in Application scripts.)
Draws a circle on the panel display.
DrawDot

(Not supported by QuickPanel 2 models or in Application scripts.)


Draws a dot on the panel display.

DrawLine (Not supported by QuickPanel 2 models or in Application scripts.)


Draws a line on the panel display.
DrawRect (Not supported by QuickPanel 2 models or in Application scripts.)
Draws a rectangle on the panel display.
Reset

Sets a bit of an integer variable to 0.

Set

Sets a bit of an integer variable to 1.

Neg

Inverts a bit of an integer variable.

QPScript Language Keywords

break
Immediately exits a loop, before the iterator variable reaches 0 and before
the endloop statement is reached.
Supported by: QuickPanel targets; not supported by QuickPanel 2 models
QPScript syntax
break
See Also: loop, endloop
Comments
The break statement is typically used to exit a loop early due to some error
message, or because a particular value in a series of values are found. It is
used in the middle of a LOOP clause. You can use as many break statements
within a LOOP clause as you want.
LOOP Clauses are not supported by QuickPanel 2 models. For more
information, see LOOP Clauses.
Example
The following example searches through the bits of the variable ErrorStatus,
exiting as soon as it finds the first bit that is set to 1. When the loop ends,
the variable BitErrorNumber either indicates which bit was set, or is -1 if no
set bits were found. All variables in this example are INT variables.
BitErrorNumber = -1
MyIndex = 16
loop (MyIndex)
BitIndex = 16 - MyIndex
MyTemp1 = 0
Set(MyTemp1, BitIndex)
MyTemp2 = MyTemp1 AND ErrorStatus
if ((MyTemp1 AND ErrorStatus) > 0)
BitErrorNumber = BitIndex
break
endif
endloop

QPScript Language Keywords

else
Indicates the beginning of the else section of an IF Clause, which is executed
when the if statement's conditional expression evaluates to 0 (False).
Supported by: QuickPanel targets
QPScript syntax
else
See Also: if, endif
Parameters
CondExpression: Conditional Expression that evaluates to 1 (True) or 0
(False).
Comments
For the complete syntax for if, else, and endif statements, see IF Clause.
In summary:

If the result of CondExpression is 1, execution continues just after the


if statement, up until the matching else statement. Execution then
jumps to the matching endif statement.
If the result of CondExpression is 0, execution continues just after the
else statement if it exists, or just after the endif statement if there is
no else statement.

Each if statement must have a matching endif statement, indicating the end
of the IF clause. You can nest up to three levels of IF clauses within one
another. Using "else" is optional, but each if statement can have only one
matching else statement.
Example
The following example tests the value of MyINT. If MyINT is greater than 100,
MyBOOL is set to 1. Otherwise, MyBOOL is set to 0.

if (MyINT > 100)


MyBOOL = 1
else
MyBOOL = 0
endif

QPScript Language Keywords

endif
Indicates the end of an IF Clause. Execution continues after the endif
statement, regardless of the results of the if statement's conditional
expression.
Supported by: QuickPanel targets
QPScript syntax
if(exprCondition)
See Also: else, if
Parameters
exprCondition: Conditional Expression that evaluates to 1 (True) or 0 (False).
Comments
For the complete syntax of if, else, and endif statements, see IF Clause. In
summary:

If the result of exprCondition is 1, execution continues just after the if


statement, up until the matching else statement. Execution then jumps
to the matching endif statement.
If the result of exprCondition is 0, execution continues just after the
else statement if it exists, or just after the endif statement if there is
no else statement.

Each if statement must have a matching endif statement, indicating the


end of the IF clause. You can nest up to three levels of IF clauses.
Example
The following example tests the value of MyINT. If MyINT is greater than 100,
MyBOOL is set to 1. Otherwise, MyBOOL is set to 0.
if (MyINT > 100)

MyBOOL = 1
else
MyBOOL = 0
endif

QPScript Language Keywords

endloop
Indicates the end of a LOOP Clause.
Supported by: QuickPanel targets; not supported by QuickPanel 2 models
QPScript syntax
endloop
See Also: break, loop
Comments
When execution reaches the endloop statement, the value of the iterator
variable (as specified in the initial loop statement) is decremented by 1. If the
resulting value is 0 or less, the loop ends and execution continues with the
next statement after endloop. Otherwise, execution returns to the beginning
of the loop.
Each loop statement must have a matching endloop statement, indicating
the end of the LOOP Clause. You cannot nest a loop inside another.
A loop can exit early with the break statement.
LOOP Clauses are not supported by QuickPanel 2 models. For more
information, see LOOP Clauses.
Example
The following example searches through the bits of the variable ErrorStatus,
exiting as soon as it finds the first bit that is set to 1. When the loop ends,
the variable BitErrorNumber either indicates which bit was set, or is -1 if no
set bits were found. All variables in this example are INT variables.
BitErrorNumber = -1
MyIndex = 16
loop (MyIndex)
BitIndex = 16 - MyIndex
MyTemp1 = 0
Set(MyTemp1, BitIndex)
MyTemp2 = MyTemp1 AND ErrorStatus
if ((MyTemp1 AND ErrorStatus) > 0)

BitErrorNumber = BitIndex
break
endif
endloop

QPScript Language Keywords

if
Indicates the beginning of an IF Clause, which performs a test or comparison,
branching execution based on the result.
Supported by: QuickPanel targets
QPScript syntax
if (exprCondition)
See Also: else, endif
Parameters
exprCondition: Conditional Expression that evaluates to 1 (True) or 0 (False).
Comments
For the complete syntax of if, else, and endif statements, see IF Clause. In
summary:

If the result of exprCondition is 1, execution continues just after the if


statement, up until the matching else statement. Execution then jumps
to the matching endif statement.
If the result of exprCondition is 0, execution continues just after the
else statement if it exists, or just after the endif statement if there is
no else statement.

Each if statement must have a matching endif statement, indicating the


end of the IF clause. The else portion is optional; however, each if
statement can have only one corresponding else statement. You can nest up
to three levels of IF Clauses.
Example
The following example tests the value of MyINT. If MyINT is greater than 100,
MyBOOL is set to 1. Otherwise, MyBOOL is set to 0.

if (MyINT > 100)


MyBOOL = 1
else
MyBOOL = 0
endif

QPScript Language Keywords

loop
Indicates the beginning of a LOOP Clause, which repeats a set of statements
a specified number of times.
Supported by: QuickPanel targets; not supported by QuickPanel 2 models
QPScript syntax
loop(varIterator)
See Also: break, endloop
Parameters
varIterator: Integer variable to use as the Iterator variable. Before the loop
statement, this variable should be set to the number of times you
want to execute the LOOP Clause. If 0 or less, statements within
the LOOP Clause are not executed at all.
Note: varIterator must be an integer variable with an Internal data source. It cannot
be a constant value or the result of an expression.

Comments
Each loop statement must have a matching endloop statement, indicating
the end of the loop clause. You cannot nest a loop inside another.
You can exit a loop early with the break statement.
Upon each iteration, the value of the iterator variable is decreased by 1.
Assuming that a break statement was not used, when the loop exits, the
value of the iterator variable will be 0.
LOOP Clauses are not supported by QuickPanel 2 models. For more
information, see LOOP Clauses.
Example
The following example searches through the bits of the variable ErrorStatus,
exiting as soon as it finds the first bit that is set to 1. When the loop ends,
the variable BitErrorNumber either indicates which bit was set, or is -1 if no

set bits were found. All variables in this example are INT variables.
BitErrorNumber = -1
MyIndex = 16
loop (MyIndex)
BitIndex = 16 - MyIndex
MyTemp1 = 0
Set(MyTemp1, BitIndex)
MyTemp2 = MyTemp1 AND ErrorStatus
if ((MyTemp1 AND ErrorStatus) > 0)
BitErrorNumber = BitIndex
break
endif
endloop

QPScript Language Mathematical Operators

+ (Addition)
Indicates an addition operation in a mathematical or conditional expression.
Supported by: QuickPanel targets
See Also: - (Subtraction operator)
Comments
The + and - operators have the same precedence within expressions. For a
complete description of the syntax for mathematical expressions, see
Mathematical expressions.
Warning: In QPScript, operands and expression results are 16-bit integers. If the result of the
expression is greater than 65535, the high word is discarded.

Example
The following example sets the value of MyINT1 to 3 more than the value of
MyINT2.
MyINT1 = MyINT2 + 3

QPScript Language Mathematical Operators

AND
Performs a bitwise AND operation on the bits of two integer values.
Supported by: QuickPanel targets
See Also: OR, NOT, XOR
Comments
The results of an AND operation for each bit position are as follows:
1 (True) AND 1
=1
(True)
1 (True) AND 0
=0
(False)
0 (False) AND 1
=0
(True)
0 (False) AND 0
=0
(False)
The AND, OR, and XOR operators have the same precedence within
expressions. For a complete description of the syntax for mathematical
expressions, see Mathematical expressions.
Example
The following example sets the value of MyINT1 to the result of 5 (0101) AND
12 (1100), that is, 4 (0100).
MyINT = 5 AND 12

You can also perform bitwise operations on variables or the results of


subexpressions:
MyINTresult = MyINT1 AND (5 + MyINT2)

QPScript Language Bitwise Operators

<< (Bit shift left)


Performs a leftwards bit shift operation on the value of an integer variable.
Supported by: QuickPanel targets
See Also: >> (Bit shift right)
Comments
Bit shift operations work on the binary representation of a value. All digits in
the binary representation are shifted the indicated number of positions. Digits
that "fall off" one side are lost. Digits on the opposite side are filled with 0s.
Both bit shift operators (<< and >>) differ from other operators in that the
operands are much more restrictive.

The left side of the operator must be a variable name.


The expression on the right side of the operator must evaluate to an
integer between 1 and 15.

For more details, see Bit shift expressions.


Warning: In QPScript, operands and expression results are 16-bit integers. If the result of the
expression is greater than 65535, the high word is discarded.

Example
The following shifts the variable MyINT to the left by 2 binary places. If its
original value were 3 (11 in binary), its value would be changed to 12 (1100
in binary).
MyINT << 2

QPScript Language Bitwise Operators

>> (Bit shift right)


Performs a rightwards bit shift operation on the value of an integer variable.
Supported by: QuickPanel targets
See Also: << (Bit shift left)
Comments
Bit shift operations work on the binary representation of a value. All digits in
the binary representation are shifted the indicated number of positions. Digits
that "fall off" one side are lost. Digits on the opposite side are filled with 0s.
Both bit shift operators (<< and >>) differ from other operators in that the
operands are much more restrictive.

The left side of the operator must be a variable name.


The right side of the operator must be expression that evaluates to an
integer from 1 through 15

For more details, see Bit shift expressions.


Example
The following shifts the variable MyINT to the right by 2 binary places. If its
original value were 12 (1100 in binary), its final value would be 3 (11 in
binary). Similarly, if its original value were 2 (10 in binary), its final value
would be 0 (The 1 digits would be lost when shifted off the "edge" of the
number).
MyINT >> 2

QPScript Language Mathematical Operators

/ (Division)
Performs a division operation within a mathematical or conditional
expression.
Supported by: QuickPanel targets
See Also: * (Multiplication operator), % (Modulo Division operator)
Comments
In QuickPanel scripts, all mathematical operations are performed on 16-bit
integer values. This means that any fractional results of a division operation
will be lost. You can determine the remainder of a division operation with the
% (modulo division) operator. For example:
17 / 7 resolves to 2
17 % 7 resolves to 17 - (7*2), that is, 3
The *, /, and % operators have the same precedence within expressions. For
a complete description of the syntax for mathematical expressions, see
Mathematical expressions.
Warnings: Before performing the division operation, ensure that the second operand is not 0. If
a divide-by-zero error occurs in a script, the QuickPanel application will stop working and must be
restarted; no indication of the divide-by-zero error will be provided. It is the responsibility of the
application developer to ensure that a divide-by-zero condition does not occur.

Example
The following example sets the value of MyINT1 to the value of MyINT2
divided by 2, discarding any fractional remainder.
MyINT1 = MyINT2 / 2

QPScript Language Conditional Operators

== (Equal to)
Performs an equality comparison between the results of two mathematical
expressions.
Supported by: QuickPanel targets
See Also: < (less than), > (greater than), <= (less than or equal to), >=
(greater than or equal to), <> (not equal to)
Comments
The == operator is used only in conditional expressions. It compares two
values, the results of two mathematical expressions. If the values are equal,
the result of the conditional expression is 1 (True); otherwise, the result is 0
(False).
The operands are not affected by the comparison.
Example
The result of the following if statement is True only if MyINT is equal to 5.
if (MyINT == 5)

QPScript Language Conditional Operators

> (Greater than)


Performs a greater than comparison between the results of two mathematical
expressions.
Supported by: QuickPanel targets
See Also: < (less than), == (equal to), <= (less than or equal to), >=
(greater than or equal to), <> (not equal to)
Comments
The > operator is used only in conditional expressions. It compares two
values, the results of two mathematical expressions. If the first value is
greater than the second value, the result of the conditional expression is 1
(True); otherwise, the result is 0 (False).
The operators are not affected by the comparison.
Example
The condition of the following if statement is True only if MyINT is greater
than 5.
if (MyINT > 5)

QPScript Language Conditional Operators

>= (Greater than or equal to)


Performs a greater than or equal to comparison between the results of two
mathematical expressions.
Supported by: QuickPanel targets
See Also: < (less than), > (greater than), == (equal to), <= (less than or
equal to), <> (not equal to)
Comments
The >= operator is used only in conditional expressions. It compares two
values, the results of two mathematical expressions. If the first value is
greater than or equal to the second value, the result of the conditional
expression is 1 (True); otherwise, the result is 0 (False).
The operators are not affected by the comparison.
Example
The condition of the following if statement is True only if MyINT is greater
than or equal to 5.
if (MyINT >= 5)

QPScript Language Conditional Operators

< (Less than)


Performs a less than comparison between the results of two mathematical
expressions.
Supported by: QuickPanel targets
See Also: > (greater than), == (equal to), <= (less than or equal to), >=
(greater than or equal to), <> (not equal to)
Comments
The < operator is used only in conditional expressions. It compares two
values, the results of two mathematical expressions. If the first value is less
than the second value, the result of the conditional expression is 1 (True);
otherwise, the result is 0 (False).
The operators are not affected by the comparison.
Example
The condition of the following if statement is True only if MyINT is less than
5.
if (MyINT < 5)

QPScript Language Conditional Operators

<= (Less than or equal to)


Performs a less than or equal to comparison between the results of two
mathematical expressions.
Supported by: QuickPanel targets
See Also: < (less than), > (greater than), == (equal to), >= (greater than or
equal to), <> (not equal to)
Comments
The <= operator is used only in conditional expressions. It compares two
values, the results of two mathematical expressions. If the first value is less
than or equal to the second value, the result of the conditional expression is 1
(True); otherwise, the result is 0 (False).
Example
The condition of the following if statement is True only if MyINT is less than
or equal to 5.
if (MyINT <= 5)

QPScript Language Mathematical Operators

% (Modulo division)
Indicates an integral division (modulus) operation within a mathematical or
conditional expression.
Supported by: QuickPanel targets
See Also: * (Multiplication operator), / (Division operator)
Comments
The result of a modulo division operation is the integer remainder of the
division result. Since regular division operations are performed only on
integers, the modulo operator can be used to determine the true results of a
division. For example:
17 / 7 resolves to 2
17 % 7 resolves to 17 - (7*2), that is, 3
The *, /, and % operators have the same precedence within expressions. For
a complete description of the syntax for mathematical expressions, see
Mathematical expressions.
Example
The following example sets the value of MyINT1 to the remainder of MyINT2
divided by 7.
MyINT1 = MyINT2 % 7

QPScript Language Mathematical Operators

* (Multiplication)
Performs a multiplication operation within a mathematical or conditional
expression.
Supported by: QuickPanel targets
See Also: / (Division operator), % (Modulo Division operator)
Comments
The *, /, and % operators have the same precedence within expressions. For
a complete description of the syntax for mathematical expressions, see
Mathematical expressions.
Warning: In QPScript, operands and expression results are 16-bit integers. If the result of the
expression is greater than 65535, the high word is discarded.

Example
The following example sets the value of MyINT1 to 6 times than the value of
MyINT2.
MyINT1 = MyINT2 * 6

QPScript Language Mathematical Operators

NOT
Performs a bitwise NOT operation (an "inversion") on the bits of an integer
value.
Supported by: QuickPanel targets
See Also: AND, XOR, OR
Comments
The results of a NOT operation on each bit position are as follows:
NOT 1 (True) = 0
NOT 0
=1
(False)
Note that, unlike AND, XOR, and OR, the NOT operator works on a single
value or result. For a complete description of the syntax for mathematical
expressions, see Mathematical expressions.
Example
The following example sets the value of the 16-bit INT variable MyINT1 to the
result of NOT 5 (0000 0000 0000 0101), or 65530 (1111 1111 1111 1010).
MyINT = NOT 5

QPScript Language Conditional Operators

<> (not equal)


Performs an inequality comparison between the results of two mathematical
expressions.
Supported by: QuickPanel targets
See Also: < (less than), > (greater than), == (equal to), <= (less than or
equal to), >= (greater than or equal to)
Comments
The <> operator is used only in conditional expressions. It compares two
values, the results of two mathematical expressions. If the first value is not
equal to the second value, the result of the conditional expression is 1 (True);
otherwise, the result is 0 (False).
Example
The condition of the following if statement is True only if MyINT is not equal
to 5.
if (MyINT <> 5)

QPScript Language Mathematical Operators

OR
Performs a bitwise OR operation on the bits of two integer values.
Supported by: QuickPanel targets
See Also: AND, NOT, XOR
Comments
The results of an OR operation for each bit position are as follows:
1 (True) OR 1 (True) = 1
1 (True) OR 0 (False) = 1
0 (False) OR 1 (True) = 1
0 (False) OR 0 (False) = 0
The AND, OR, and XOR operators have the same precedence within
expressions. For a complete description of the syntax for mathematical
expressions, see Mathematical expressions.
Example
The following example sets the value of MyINT1 to the result of 5 (0101) OR
12 (1100), that is, 13 (1101).
MyINT = 5 OR 12

You can also perform bitwise operations on variables or the results of


subexpressions:
MyINTresult = MyINT1 OR (5 + MyINT2)

QPScript Language Mathematical Operators

- (Subtraction)
Performs a subtraction operation in a mathematical or conditional expression.
Supported by: QuickPanel targets
See Also: + (Addition operator)
Comments
The + and - operators have the same precedence within expressions. For a
complete description of the syntax for mathematical expressions, see
Mathematical expressions.
When using the subtraction operator, make sure you add a space between
the "-" and the second operand. Otherwise, the dash will be treated as a
negation operator for the second operand:
MyINT1 = MyINT2 -3
MyINT1 = MyINT2-3
MyINT1 = MyINT2- 3

Interpreted as "MyINT2" and "negative 3", resulting


in a syntax error.
Interpreted as "MyINT2 minus 3", a valid
expression.

Example
The following example sets the value of MyINT1 to 3 less than the value of
MyINT2.
MyINT1 = MyINT2 - 3

QPScript Language Mathematical Operators

XOR
Performs a bitwise XOR (exclusive-OR) operation on the bits of two integer
values.
Supported by: QuickPanel targets
See Also: AND, NOT, OR
Comments
The results of an XOR operation on each bit position are as follows:
1 (True) XOR 1 (True) = 0
1 (True) XOR 0 (False) = 1
0 (False) XOR 1 (True) = 1
0 (False) XOR 0 (False) = 0
The AND, OR, and XOR operators have the same precedence within
expressions. For a complete description of the syntax for mathematical
expressions, see Mathematical expressions.
Example
The following example sets the value of MyINT1 to the result of 5 (0101) XOR
12 (1100), that is, 9 (1001).
MyINT = 5 XOR 12

You can also perform bitwise operations on variables or the results of


subexpressions:
MyINTresult = MyINT1 XOR (5 + MyINT2)

QPScript Language Functions

DrawCircle
Draws a circle on the QuickPanel display.
Supported by: QuickPanel targets; not supported by QuickPanel 2 models
QPScript syntax
DrawCircle(intHorPos, intVerPos, intRadius, intColor, intAttributes)
See Also: DrawDot, DrawLine, DrawRect
Parameters
intHorPos:

Integer constant or variable, specifying the horizontal pixel


position of the circle's center.
intVerPos:
Integer constant or variable, specifying the vertical pixel
position of the circle's center.
intRadius:
Integer constant or variable, specifying the radius of the circle.
intColor:
Integer constant or variable, specifying the color of the circle.
This can be from 0 through 7. For a list of available colors, see
Comments below.
intAttributes: Integer constant or variable. If 0, the circle is drawn as an
outline. If 1, the circle is drawn as a solid circle.
Comments
This function cannot be used in Application scripts.
Pixel positions are numbered starting from 0. Pixel (0,0) is the top-left
corner. The circle must be entirely contained within the panel's pixel
dimensions. For details, see QuickPanel pixel coordinate system.
Available colors for intColor are as follows:
0:

Black

1:

Blue

2:

Green

3:

Cyan

4:

Red

5:

Magenta

6:

Yellow

7:

White

Example
The following example draws a solid white 10-pixel wide circle at coordinates
(30,30).
DrawCircle(30, 30, 5, 7, 1)

QPScript Language Functions

DrawDot
Draws a circle on the QuickPanel display.
Supported by: QuickPanel targets; not supported by QuickPanel 2 models
QPScript syntax
DrawDot(IntHorPos, IntVerPos, intColor)
See Also: DrawCircle, DrawLine, DrawRect
Parameters
IntHorPos: Integer constant or variable, specifying the horizontal pixel
position of the dot.
IntVerPos: Integer constant or variable, specifying the vertical pixel position
of the dot.
intColor: Integer constant or variable, specifying the color of the dot. This
can be from 0 through 7. For a list of available colors, see
Comments below.
Comments
This function cannot be used in Application scripts.
Pixel positions are numbered starting from 0. Pixel (0,0) is the top-left
corner. The dot's coordinates must fall within the panel's pixel dimensions.
For details, see QuickPanel pixel coordinate system.
Available colors for intColor are as follows:
0:

Black

1:

Blue

2:

Green

3:

Cyan

4:

Red

5:

Magenta

6:

Yellow

7:

White

Example
The following example draws a red dot at coordinates (30,30).
DrawDot(30, 30, 4)

QPScript Language Functions

DrawLine
Draws a straight line on the QuickPanel display.
Supported by: QuickPanel targets; not supported by QuickPanel 2 models
QPScript syntax
DrawLine(intHor1Pos, intVer1Pos, intHor2Pos, intVer2Pos, intColor,
intStyle)
See Also: DrawDot, DrawCircle, DrawRect
Parameters
IntHor1Pos: Integer constant or variable, specifying the horizontal pixel
position of the line's starting position.
IntVer1Pos: Integer constant or variable, specifying the vertical pixel position
of the line's starting position.
IntHor2Pos: Integer constant or variable, specifying the horizontal pixel
position of the line's ending position.
IntVer2Pos: Integer constant or variable, specifying the vertical pixel position
of the line's ending position.
intColor:
Integer constant or variable, specifying the color of the line. This
can be from 0 through 7. For a list of available colors, see
Comments below.
intStyle:
Integer constant or variable, specifying the style of the line. This
can be one of the following:

0: a solid line.

1: a line with an arrowhead at the ending position.

2: a line with an arrowhead at both the starting and ending


positions.

Comments
This function cannot be used in Application scripts.
Pixel positions are numbered starting from 0. Pixel (0,0) is the top left corner.

Both the line's starting coordinates and ending coordinates must fall within
the panel's pixel dimensions. For details, see QuickPanel pixel coordinate
system.
Available colors for intColor are as follows:
0:

Black

1:

Blue

2:

Green

3:

Cyan

4:

Red

5:

Magenta

6:

Yellow

7:

White

Example
The following example draws a red diagonal arrow from the top left corner to
coordinates (30,30).
DrawLine(0, 0, 30, 30, 4, 1)

QPScript Language Functions

DrawRect
Draws a rectangle on the QuickPanel display.
Supported by: QuickPanel targets; not supported by QuickPanel 2 models
QPScript syntax
DrawRect(intHor1Pos, intVer1Pos, intHor2Pos, intVer2Pos, intColor,
intAttributes)
See Also: DrawDot, DrawLine, DrawCircle
Parameters
intHor1Pos: Integer constant or variable, specifying the horizontal pixel
position of the top-left corner of the rectangle.
intVer1Pos: Integer constant or variable, specifying the vertical pixel
position of the top-left corner of the rectangle.
intHor2Pos: Integer constant or variable, specifying the horizontal pixel
position of the bottom-right corner of the rectangle.
intVer2Pos: Integer constant or variable, specifying the vertical pixel
position of the bottom-right corner of the rectangle.
intColor:
Integer constant or variable, specifying the color of the line.
This can be from 0 through 7. For a list of available colors, see
Comments below.
intAttributes: Integer constant or variable. If 0, the rectangle is drawn as an
outline. If 1, the rectangle is drawn as a solid rectangular block.
Comments
This function cannot be used in Application scripts.
Pixel positions are numbered starting from 0. Pixel (0,0) is the top left corner.
The intHor2Pos parameter must be greater than intHor1Pos; similarly, the
intVer2Pos parameter must be greater than intVer1Pos. Both sets of
coordinates must fall within the panel's pixel dimensions. For details, see
QuickPanel pixel coordinate system.
Available colors for intColor are as follows:
0:

Black

1:

Blue

2:

Green

3:

Cyan

4:

Red

5:

Magenta

6:

Yellow

7:

White

Example
The following example draws a red rectangle from the top left corner to
coordinates (30,30).
DrawRect(0, 0, 30, 30, 4, 1)

QPScript Language Functions

Neg
Toggles (inverts) a bit of an integer variable. If the bit is 0, it is changed to 1;
if the bit is 1, it is changed to 0.
Supported by: QuickPanel targets
QPScript syntax
Neg(varVarName, intBitNumber)
See Also: Reset, Set
Parameters
varVarName: The name of the integer variable whose bit you want to invert.
intBitNumber: Integer constant or variable, indicating the specific bit to invert
This can be from 0 to one less than the number of bits in the
variable value.
Example
The following example toggles the fourth bit of the variable MyStatus.
Neg(MyStatus, 3)

QPScript Language Functions

Reset
Resets the value of a bit of an INT variable to 0.
Supported by: QuickPanel targets
QPScript syntax
Reset(varVarName, intBitNumber)
See Also: Neg, Set
Parameters
varVarName: The name of the INT variable whose bit you want to reset to 0.
Note: varVarName must indicate a variable with an INT data type.

intBitNumber: Integer constant or variable, indicating the specific bit you


want to reset to 0. This can be from 0 to one less than the
number of bits in the variable value.
Example
The following example resets the fourth bit of the INT variable MyStatus to 0.
Reset(MyStatus, 3)

QPScript Language Functions

Set
Sets the value of a bit of an INT variable to 1.
Supported by: QuickPanel targets
QPScript syntax
Set(varVarName, intBitNumber)
See Also: Neg, Reset
Parameters
varVarName: The name of the INT variable whose bit you want to set to 1.
Note: varVarName must indicate a variable with an INT data type.

intBitNumber: Integer constant or variable, indicating the specific bit you


want to set to 1. This can be from 0 to one less than the
number of bits in the variable value.
Example
The following example sets the fourth bit of the INT variable MyStatus to 1.
Set(MyStatus, 3)

QuickPanel pixel coordinate system


In most cases, you will not have to consider how the QuickPanel's pixel
coordinate system works. However, you may find this information useful if
you want to precisely specify the width and location of a graphical object
(using its Position properties); or if you are creating scripts that use the
"Draw" script functions.
Pixels on a QuickPanel display are organized as shown below. In the diagram,
coordinate labels are given in the order [Left, Top]; that is, the number of
pixels from the left edge followed by the number of pixels from the top edge.

Note that this is not a true (X, Y) coordinate system:

Horizontal coordinates are numbered starting from 0 on the left to the


maximum pixel width of the panel on the right.
Vertical coordinates are numbered starting from 0 on the top to the
maximum pixel height on the bottom.

Vous aimerez peut-être aussi