Cautions as to operation that can be easily performed incorrectly
are shown.
Matters that will help the user improve understanding of the text and
useful information are shown.
The items and pages to be referred to in this document are shown.
Introduction
This manual explains the script language described when using the edit read data
function and the edit image file name function on the SR-1000/D100/750/700
Series.
For information on the basic functions of the SR-1000/D100/750/700 Series, refer
to the corresponding user's manual.
This manual is written for users with basic knowledge of PC and programming
experience.
SR-1000/D100/750/700 related manuals
z Included in CD-ROM
• SR-1000 User's Manual
• SR-D100 User's Manual
• SR-750 User's Manual
• SR-700 User's Manual
z Download from KEYENCE homepage
Download the latest manual from the following web page.
BarcodeReader.com
http://www.barcodereader.com/
General cautions
• KEYENCE does not guarantee the results if it is used in a manner that differs
from the descriptions in this manual.
• It is prohibited to use or copy all or any part of this manual without prior approval.
• The information contained in this manual is subject to change without notice.
• The company names and product names described in this manual are registered
trademarks or trademarks of each company.
1
E SR SCRIPT RM
1-1Overview
[1] Creating the script file
[2] Changing the script execution setting
[3] Transferring the script file
SR
1000
SEL
MENU
[1] Reading a code
[2] Executing the script when reading.[3] Sending the script execution result
12345678901 2 3456789
Header 1239 Terminator
The header and the terminator
are appended to the script
execution result and data is
output.
SR
1000
SEL
MENU
SR
1000
SEL
MENU
1-3What Script can do
Definition of Script file
The Script explained in this manual is a simple programming language operating
on the SR-1000/D100/750/700 Series.
Compared to using the setting software (AutoID Network Navigator), using the
script enables more flexible operations for the (1) Edit output data, (2) Edit image
file name, and (3) Control output terminals functions.
Related software
AutoID Network Navigator
Software to set the SR-1000/D100/750/700 Series
FileView
Use this to send/receive the script file to/from the SR-1000/D100/750/700 Series.
* For detailed operation procedures for the AutoID Network Navigator and
FileView, refer to the corresponding user's manual.
1-2Script execution flow
Steps before executing the script
SEL
MENU
SR
1000
Examples of what the script can do
• Extracting arbitrary portion of read data
• Appending arbitrary character strings to read data
• Comparing data and outputting result data
• Four arithmetic operations
• Changing image file names for FTP transmission
• Comparing data and generating output from the output terminals
* "Additional information" set with AutoID Network Navigator cannot be used in
combination with the script.
1-4Script file configuration
This describes the configuration of the script file (FmtSet.lua).
Script file configuration
FmtSet.lua file, the script program handled by SR-1000/D100/750/700 consists of
the following 3 parts.
(1) function readformatEvent()……………… Edit read data
(2) function nameformatEvent( idx ) ……… Edit image file name
(3) User-defined function …………………… User-defined function that can
be called for (1) and (2)
The process is written in the above parts in combination with variables or functions
provided by the SR-1000/D100/750/700 system.
FmtSet.lua file
[1] Creating the script file
Create the script file (FmtSet.lua) and write the program using a text editor such
as notepad.exe. (This manual describes writing methods for programming.)
[2] Changing the script execution setting
Using the AutoID Network Navigator, set the script execution setting of the
SR-1000/D100/750/700 Series to "Enable".
[3] Transferring the script file
Transfer the script file (FmtSet.lua) to the SR-1000/D100/750/700 Series.
For setting procedures for the AutoID Network Navigator, refer to the
corresponding user's manual.
Operations when executing the script
The script is executed when a code is read.
SCPVERSION="1.00"
function readformatEvent()
Process
end
function nameformatEvent( idx )
Process
end
function User-defined function
Process
end
--Comment
The file version can be determined
User-defined function that can be called
for (1) and (2) (Can be omitted.)
Putting 2 hyphens at the beginning
arbitrarily.
(Can be omitted.)
(1) Edit read data
(control output terminals)
(2) Edit image file name
enables writing comment.
*1
*1 Multiple user-defined functions can be written as necessary. Skip this if not
used.
For writing procedure of user-defined functions, refer to "5-5 User-defined
function" (Page 12).
• The SR-700 Series is not equipped with a function for transmitting
Reference
images to FTP servers, so the "(2) Edit image file name" function
cannot be used.
• The "Control output terminals" function is only supported by the
SR-1000/700 Series.
E SR SCRIPT RM
2
(1) Edit read data function readformatEvent()
Reference
This operates when "Edit data by script" is enabled on the code reader setting.
Format
function readformatEvent()
Variable declaration
Process
return(variable)
end
Example
function readformatEvent()
local aDeclares variable a.
a="successful reading!"Assigns "successful reading !" to variable a.
return(a)The value stored in a is output as "Read data".
end
* Up to 9990 characters can be assigned to return.
The value entered into return is output as "Read
data".
Comment description
Format
z 1-line comment
-- CommentCharacter strings written after -- are treated as the comment.
z Multiple-line comment
-- [[
Comment
Comment
]]
Character strings surrounded with --[[ ]] are treated as the
comment.
(2) Edit image file name
function nameformatEvent(idx)
This operates when "Edit image file name by script (FTP transmission only)" is
enabled on the code reader setting.
Format
function nameformatEvent()
Variable declaration
Process
return(variable)
end
Example
function nameformatEvent( idx )
local bDeclares variable b.
b="image file"Assigns "image file" to variable b.
return(b)
end
Up to 180 characters can be assigned to return.
File names are restricted by the FTP server and OS activating the FTP server. Use
the following characters for file names. If characters other than these are used, test
to check if operation is normal under the operation environment.
The value entered into return is output as "Image
file name".
The value stored in b is output as "Image file
name".
• More than one "Variable" and "Process" can be written. For how to
define variables, refer to "2-1 Naming rules" (Page 4).
• A different function among functions can be called. "Calling the
function" (Page 12)
• Directories can be specified in file names.
To put a image file named "a" into the folder named [image] in the
root folder, specify the value such as image\\a in return.
Note if the applicable folder does not exist in the root folder, it does
not operate normally.
• On the SR-700 Series, "function nameformatEvent" cannot be used.
3
E SR SCRIPT RM
2-1Naming rules
3
a
Vari able name
Stores numerical value 3 in variable a.
This describes naming rules for variables, etc. used in the script.
Naming methods
Script file name
The script file name handled by SR-1000/D100/750/700 is FmtSet.lua only.
Names defined in the script program
Types of Name defined in the script program are as follows.
• Variable name, array variable name
• Function name
Definitions of variable name and table name
Start the name with a 1-byte alphanumeric character.
1-byte alphanumeric characters and "_" (underscore) can be used.
Do not use reserved words.
For reserved words, "8-2 Reserved words/Language elements" (Page 18).
Do not use "_" (underscore) at the beginning of the name.
NOTICE
It may not operate normally.
2-2Variables
Character strings and numerical values used in the script are stored in containers
called variables to be handled.
Characters and numerical values that can be assigned to variables
3 types of values can be assigned to variables: character string, numerical value
and logical value
Text notation: "ABC", "keyence"
character string
Numerical value
Logical value
* The condition that no value is assigned to the variable is called nil. If it is referred,
an error will occur. Be sure to assign a value before referring to the variable.
Character code (decimal number) notation : "¥013¥010"
Expresses with the text surrounded with "". Numerical values, symbols and
character strings can be written in "".
z Character code (decimal number) notation
Expresses the character string by specifying the ASCII code decimal number after
¥.
z Escape sequence
Expresses control characters and symbols using escape characters (¥).
Example
a = "ABC"Assigns character string "ABC" to variable a.
b = "¥013¥010"
c = ¥r
Assigns character code (decimal number)
notation "¥013¥010"([CR][LF]) to variable b.
Specifies line break (¥r) to variable c with escape
sequence.
Definition of variable
Values such as numerical values, character strings or calculated results can be
assigned to variables.
Declaration of variable
Format
local "variable name"
Example
local a Declares variable a.
Assignment and initialization of variable
Storing a value in a variable is called "assignment".
Assigning a value at the time of variable declaration is called "Initialization".
Example
local a=0Initializes with 0 when declaring variable a.
a=1Assigns 1 to variable a.
If this is referred with no value assigned to the variable, an error will occur when
executing the script.
Numerical value
z Positive and negative integer (decimal number notation)
This expresses positive integer and negative integer as decimal number.
z Positive and negative decimal (decimal number notation)
This expresses positive decimal and negative decimal as decimal number.
Important
Decimal uses double-precision floating-point number, which may
have a margin of error.
z Hexadecimal number notation
This expresses 0 or positive integer by adding a hexadecimal number after 0x.
The hexadecimal number notation cannot express decimal and negative integer.
Example
a= 123
b = -1.5
c = 0x0fAssigns hexadecimal number f to variable c.
Assigns decimal number integer 123 to variable a.
Assigns decimal number integer -1.5 to variable b.
Logical value
Logical value shows True or False to processed results.
Escape sequence
PatternMeaning
¥r[CR](0x0D)
¥n[LF](0x0A)
¥a[BEL](0x07)
¥b[BS](0x08)
¥f[CL](0x0c)
¥t[HT](0x09)
¥v[VT](0x1B)
¥¥Ye n s ign
¥"Double quotation
¥'Single quotation
¥000Specifies an arbitrary character code as decimal number.
E SR SCRIPT RM
4
2-3Table
123
LotNo
1001
SerialNo
“camera”
name
Product
Tab le
Data (fields) such as LotNo, SerialNo and name are c ollected in the table (Product).
3
b[1]4b[2]5b[3]6b[4]7b[5]
b
Tab le
Numerical values 3,4,5,6,7 are stored in table b.
2-4Array
The table is the data configuration to collect multiple data.
Definition of table
The table can store multiple data (fields).
Fields can store numerical values and character string data as variables do.
Declaration of table
Format
local “table name” ={field 1, field 2, field 3}
Reference to data within the table
Table name.field name
Example 1) Table declaration and initialization
Declares table Product.
local
Product ={ LotNo=123 , Serial No=1001 , name="camera"}
LotNo=123
Serial No =1001
name ="camera"
The array is a type of table and a data column that can store multiple values.
Similar to normal variables, reference and assignment can be made.
Definition of array
Values such as numerical values, character strings or calculated results can be
assigned to arrays.
Naming rules for array
Array names must start with a 1-byte alphanumeric character for the first character.
For the second character and after, 1-byte alphanumeric characters and "_"
(underscore) can be used. Array elements start from [1].
Declaration of array
Format
local“arrayname” ={}
Example
local b ={}Declares array b.
Example 2) Reference to data variables within the table
local a = 0Declares variable a.
local
Product ={ LotNo=123 , Serial No=1001 , name="camera"}
a = Product.name
Declares table Product.
Stores the name field of
the table Product in a.
Assignment and initialization of array variable
Assign values to array valuables using { } and values. Specify multiple values by
dividing "," (comma).
Example
local a={}Declares array a.
a = {3,4,5,6}Assigns the 4 values 3, 4, 5, and 6 to array a.
local b ={16,51,55}
local b[3] = 10Assigns 10 to the third value of array b.
local b[4] = 11
Declares array b and initializes it with the 3
values 16, 51, 55.
Assigns 11 to the fourth value of array b (adds 1
element).
5
E SR SCRIPT RM
3-1Calculation
Important
Reference
Important
Examples of calculations and results (a=5.5, b=2)
Arithmetic expression
Result
a+b7.5
a-b3.5
a*b11
a/b2.75
a%b1.5
a^b30.25
Examples of calculations and results (a=10, b=1)
Arithmetic expression
Result
a >btrue
a <bfalse
a == 10true
a~=10false
Examples of calculations and results
Arithmetic expression
Result
true and truetrue
true or truetrue
true and falsefalse
true or falsetrue
not falsetrue
not truefalse
10 or 3010
nil or 3030
false or nilnil
3-3Combination of condition
This describes arithmetic operators used for general calculations.
Arithmetic operator
Format
Arithmetic
operator
+Addition
-Subtraction
*Multiplication
/Division
%Remainder (from division)
^Power
On the left-hand side and the right-hand side of each operator, write an expression
using numerical values or variables of numerical values.
Example
A = B + 1
Example
Meaning
Assigns the result of variable B plus 1 to variable A.
This describes logical operators used when combining conditions.
Logical operator
Format
Logical operatorMeaning
and
or
not
Example
Logical AND operator: If the first argument is false or nil, the value is returned.
Logical OR operator: If the first argument is different from false or nil, the
Logical NOT operator:If the next value is false or nil, true is returned. If not,
If not, the second argument is returned.
first argument is returned. If not, the second
argument is returned.
false is returned.
If character strings are assigned to variables and they cannot be
converted to numerical values during calculation, an error will
occur on execution.
To obtain only the integer part of division result, use arithmetic function
math.floor.(Page 11)
3-2Comparison
This describes comparative operators used when comparing numerical values or logical values.
Comparative operator
Format
Comparative operator
<smaller
<=smaller or equal
>greater
>=greater or equal
==equal
~=different
On the left-hand side and the right-hand side of each operator, write numerical
values, variables of numerical values or arithmetic expression.
Example
Meaning
3-4Character string
concatenation
This describes concatenation operators used to connect one character string to
another.
Concatenation operator
Format
variable 1..variable 2
Example
local a = "Keyence"
local b = "Auto-ID"
local cDeclares variable c.
c = a..bAssigns values after a and b are connected.
Value of c: "KeyenceAuto-ID"
Expresses using 2 periods ".." between
variables.
Declares variable a and initializes with character
string "Keyence".
Declares variable b and initializes with character
string "Auto-ID".
E SR SCRIPT RM
Comparison is also possible by assigning character strings to
variables. However, when variables are evaluated by conditional
expression, and if they cannot be converted to numerical values,
an error will occur on execution.
6
Loading...
+ 14 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.