BOA Spot Scripting Guide v1.5
BOA Spot Scripting Guide v1.5
Scripting Guide
All copyrights in this manual, and the hardware and software described in it, are the
exclusive property of Teledyne Imaging and its licensors. Claim of copyright does not imply
waiver of Teledyne Imaging or its licensors other rights in the work. See the following
Notice of Proprietary Rights.
The information in this document is subject to change without notice. Teledyne Imaging
makes no representations or warranties with respect to the contents of this manual and
specifically disclaims any implied warranties of merchantability or fitness for a particular
purpose. Teledyne Imaging assumes no responsibility for errors or omissions in this
document.
Support
In addition to this user manual, help with scripting is available from the following:
1. Online help: Fingertip help is available on every screen (panel) of the BOA Spot
User Interface
2. Self help material and sample job files are included on the BOA Spot CD
3. Call, fax or email your local Teledyne Imaging representative who sold you the
product
4. Factory support is available at [email protected]
Inside the script panel there are 3 sections. The control panel on the left side contains a
variable tree list and function list. On the right side below the image window is the Script
Function manager.
To edit a function, select it in the function list. In the bottom panel click the Edit button to
open a separate Edit window.
The “Check Syntax” button checks the “programmatic grammar” of the individual
strings, but cannot parse the statements for runtime context errors that may occur
outside this window. The bottom pane may show syntax error messages. You can
click on a message to highlight the related line of code in the upper pane.
Equations associated with a function can be exported to a user defined text file by
clicking the “Export” button. Similarly, equations stored in a local text file can be
imported into a selected function by clicking the “Import” button. This is a convenient
method of sharing scripts or script snippets (application specific code) across
solutions.
Persistent Variables
When a solution is saved, any associated variables are saved also. When a solution is
loaded, only its associated variables are loaded. This means that variables associated
with the previous solution will be deleted unless they are also saved in the new solution.
The exception to this rule is Persistent Variables. These special variables will persist
even if the solution that created them is replaced by a different solution. Persistent
variables are therefore used more for system (BOA Spot) variables as opposed to
solution specific variables. Persistent variables will persist until the BOA Spot camera is
power cycled. Persistent variables are defined with a Prog prefix and can also be saved
in a solution file (i.e. Prog.myvariable)
Variable Basics
1. Use square brackets for variable names, especially names with spaces in them.
Notice that variable names inserted or dragged into a field, are enclosed in brackets.
2. All of your expressions, equations, and variables are saved in the Solution file, and
persist when the Solution file is reloaded.
3. User added variables belong to the current Solution. Loading a different Solution will
cause your user variable set to be replaced with the set belonging to that new
Solution.
4. There are many pre-defined variables with special meaning for use in scripts. You can
also create your own variables. Referencing a variable automatically creates or
instantiates that variable. A separate step for creating or declaring, is not necessary.
5. A complete listing of predefined variables follows on the next page.
Pre-Ordered Functions
Every solution has 3 pre-ordered functions which execute in the order below:
Periodic Function
In addition, there is the Periodic function which executes in a background thread.
Periodic: 200 ms – called every 200 milliseconds. Can be used to check for
communication from external devices, or physical inputs.
Pre-Ordered Functions
time
start end
The above diagram depicts the timing associated with functions. Pre-ordered functions
are synchronized to the start and of end of each inspection. The Periodic function
shown in the blue box may be used to control asynchronous events.
The string editor simplifies construction of output strings. The GUI is accessed through
the “Edit” script tool and allows users to define strings without writing code. Each string
is composed of user text, formatted program variables and delimiting characters.
Strings can be written to the function being edited and attached directly to a predefined
communication port:
Strings are constructed by entering text or dragging variables into the string command
line. The above example generates the following 2 lines of code in the function being
edited (typically the Post Image Process function):
str1 = “Intensity = [IntenAvg%.6f] Pass Count = [Global.PassCount%d]”
WriteFormatString(TcpP5024, str1)
• Type
A required character that determines whether the associated argument is interpreted
as a character, a string, or a number. Supported character types:
c specifies a single-byte character.
d Signed decimal integer.
i Signed decimal integer
u Unsigned decimal integer.
x Unsigned hexadecimal integer, using "abcdef".
X unsigned hexadecimal integer, using "ABCDEF".
e Signed value having the form [–]d.dddd e [sign]dd[d[ where d is a single decimal
digit, dddd is one or more decimal digits, dd[d] is two or three decimal digits
depending on the output format and size of the exponent, and sign is + or -.
f Signed value having the form [–]dddd.dddd, where dddd is one or more decimal
digits. The number of digits before the decimal point depends on the magnitude of the
number, and the number of digits after the decimal point depends on the precision.
• width
Optional number that specifies the minimum number of characters output.
The width argument is a nonnegative decimal integer controlling the minimum number
of characters printed. If the number of characters in the output value is less than the
specified width, blanks are added to the left until the minimum width is reached. If
width is prefixed with 0, zeros are added until the minimum width is reached.
• precision
Optional number that specifies the maximum number of characters printed for all or
part of the output field, or the minimum number of digits printed for integer values.
For types: d, i, u, o, x, X
The precision specifies the minimum number of digits to be printed. If the number of
digits in the argument is less than precision, the output value is padded on the left
with zeros. The value is not truncated when the number of digits exceeds precision.
The default precision is 1.
For types: e, E
The precision specifies the number of digits to be printed after the decimal point. The
last printed digit is rounded.
The default precision is 6. If precision is 0 or the period (.) appears without a number
following it, no decimal point is printed.
For types: f
The precision value specifies the number of digits after the decimal point. If a decimal
point appears, at least one digit appears before it. The value is rounded to the
appropriate number of digits.
The following examples demonstrate usages of the script tool. Each example has a
brief description of the application and associated code snippets from the relevant
functions. These examples cover basic scripting concepts only that apply to typical
applications.
Note: This manual was written for all models of the BOA Spot: SL, EL, IDS, IDE. The
examples may use tools that are not available on all models.
Manipulating Outputs
Many applications require some sort of output manipulation. By default BOA Spot
outputs are set to the “soft pulse” setting which automatically generates output pulses
on GPO[0] and GPO[1] for pass and fail results. Below we’ll show at how to generate
pulses or levels using the script tool.
The above equation outputs a 400 ms active high pulse on GPO[1] (no delay) if the
MS1 match tool fails (Result=3). The equation below generates the same pulse if the
MS1 match tool is not a pass (Result = 2 or 3)
MS1 is the measured value of the match. You can use the measured value in
statements, in place of the result of a measurement as shown below. Output a 50 ms
active high pulse on GPO[1] (5 ms delay) if the MS1 match score is less than 90
Similarly, if the Distance measurement L1 is less than 400, output a 50 ms active high
pulse on GPO[1] (5 ms delay).
Set the GPO(1) to logic 1 if MS1 match tool does not pass; set GPO[1] to logic 0 if MS1
match tool passes.
Note: If you set an output to a level, it will stay that way until you change it. For example
you could set an output to “1” as above and then reset it to “0” before processing the
next image using the “Image Pre Process Function”.
Use the variable’s name, with the “Disable” switch. Disable=1 will hide the variable.
Disable=0 will show the variable. For example, you have a variable named “MyVar1”.
But you can also disable a tool in scripts. That means you could enable or disable a tool
based on a variable or on an input.
Use the tool name, with the “Disable” switch. Disable=1 will hide the tool and disable its
results. Disable=0 will show the tool and enable its results once again. The Tool remains
disabled if you do not re-enable it.
if(GPI[3]=1)
MS1.Disable=1 // disable & hide Match tool if the input is 1
else
MS1.Disable=0 // enable & show Match tool if the input is 0
endif
Function used:
• ChangeSolution(requestedSolutionID) - loads a new solution number
Function used:
• ChangeSolution(requestedSolutionID) - loads a new solution number
• GetSolutionID() – returns the current Solution number
This simple example shows how to software trigger inspections using scripting.
Predefined functions:
• trigger( ) - generate an image trigger signal. The Sensor Trigger must be set to
“SoftwareTrigger" when using this function.
• TriggerSource(source) - set the trigger source or trigger mode. Do not use in
Solution Initialize function. It gets over-written by the Solution settings.
source –1=internal timer, 2=external trigger, 3=software
Note: In general, software triggers are held off during an active acquisition cycle.
Example 2 WriteImageTools
Predefined function:
• WriteImageTools(fileName, camID) - writes an image file including the tool graphics.
fileName – full path of file to save.
User name “Joe”, password “bananas”. The image file name becomes “tool#.bmp”.
In the “Post Image Process” function:
x=x+1
fn = “ftp://[email protected]/images/tool” + x + “.bmp”
WriteImageTools(fn, 0)
Delay(50) // 50 milliseconds
//Note: if SolutionNumber is different than current solution running, change will start
//immediately and the following code will be ignored. If they are the same, the following code
//will be executed
if(CommandCharacter = "T") // look for trigger command
trigger( ) // call trigger function
endif
endif // close main IF statement
Note: This example uses ReadString() for TCP/IP communication. Use GetPortString()
for Serial Port communication.
The font size in the text window is not user selectable, but rather scales according to
how much text is being displayed. The font type is also not selectable.
The following script commands will display the messages ‘2D Code read” for pass
inspections and “Failed to Read” for fail inspections (BOA Spot-ID 2D Code tool):
if(Result=1)
SetDisplayStatus(“2D Code Read”, “green”) // post pass message
else
SetDisplayStatus(“Failed to Read”, ”red”) // post fail message
endif
An example of how to define multiple lines of text in the “Post Image Process” function
is as follows:
if(Result=1)
SetDisplayStatus(Str1+N.Result+Str2+Str3+Global.PassCount, "darkgreen")
else
SetDisplayStatus(Str1+N.Result+Str4+Str5+Global.FailCount, "darkred")
endif
A pass result would produce the following text on the monitor screen:
Array Example 1:
This simple example shows how to parse an array of blob areas (Area.[x]) from the
count tool to find the biggest blob (Note: in practice this can easily be done using the
“max” feature of the count tool without writing any script):
Input Array (entries 3 and 4 differ by 25%): ds[0:5]=90, 90, 90, 100, 80, 90
idx = 0
i=0
while( i < 4 ) // Find array entry to compare
idx = idx | (Global.GPI[i] << i) // Based on 3 GP inputs
i = i+1
endwhile
CodeMatch = CodeList[idx] // Compare string
Example:
This example shows how to send the X, Y and Z coordinates to a robot in one Modbus
multiple register transaction. With variable MB92HRs16 attached to a Modbus holding
register, the following will update the Modbus device coordinates in a single transaction.
cmd[0] = x // X coordinate
cmd[1] = y // Y coordinate
cmd[2] = z // Z coordinate
copy (cmd, MB92HRs16, 3) // Send coordinates
Similarly, you can store results from multiple tools in a single array and transfer them
efficiently using the WriteBytes function: