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
Page 2
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
Page 3
(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
Page 4
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
Page 5
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
Page 6
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
Page 7
3-5Pattern matching
This section describes how to search character strings with specific patterns
(Pattern matching) from character strings.
Pattern
Patterns used to search alphabets, numbers, symbols, etc. from character strings.
*1 Specify characters other than alphanumeric characters
Quantifier
*1
Literal character
PatternMeaning
+Matches with 1 or more times repetitions of the previous character.
∗
-
?Matches with 0 or 1 time repetition of the previous character.
Matches with 0 or more times repetitions of the previous character.
(Longest match)
Matches with 0 or more times repetitions of the previous character.
(Shortest match)
Range specification
PatternMeaning
[0-9]Number (0 to 9)
[^0-9]Not number (0 to 9)
[a-z]Alphabet lowercase (a to z)
[A-Z]Alphabet uppercase (A to Z)
[a-zA-Z]Alphabet lowercase and alphabet uppercase (a to z and A to Z)
[0-9a-zA-Z]Number and alphabet (0 to 9, a to z and A to Z)
* If ^ (caret) is added to the beginning of the pattern, the match is fixed to the
beginning of the target character string.
If $ (dollar) is added to the end of the pattern, the match is fixed to the end of the
target character string.
7
E SR SCRIPT RM
Page 8
4-1Conditional branching of
Reference
condition 1
process 1process 2process 3
condition 2
Yes
No
Yes
No
process
To branch processes, use if sentences.
if sentence
Format
z For 1 branch
if condition 1 thenIf "condition 1" is fulfilled, "process 1" is executed.
process 1If "condition 1" is not fulfilled, no process is executed.
end
z For 2 branches (using else)
if condition 1 then
process 1
else
process 2
end
z For 3 branches (using elseif)
if condition 1 then
process 1
elseif condition 2 then
process 2
else
process 3
end
If "condition 1" is fulfilled, "process 1" is executed.
If "condition 1" is not fulfilled, "process 2" is executed.
If "condition 1" is fulfilled, "process 1" is executed.
If "condition 1" is not fulfilled but "condition 2" is fulfilled,
"process 2" is executed.
If both "condition 1" and "condition 2" are not fulfilled, "process
3" is executed.
Conditional expression
For "condition" of if sentences, write conditional expressions using comparative
operators as below.
Comparison typeConditional expressionDescription
Character string
comparison
Numerical value
comparison
Character string
comparison
For details of comparative operators, refer to "3-2 Comparison" (Page 6).
Example 1
if type<10 then
termID=1
end
Example 2
if type<10 then
termID=10
elseif type<20 then
termID=20
else
termID=30
end
if (str == "A") thenIf str is equal to "A"
if (str ~= "A") thenIf str is not equal to "A"
if (i < 10) thenIf i is less than 10
if (i < =10) thenIf i is 10 or less
if (i ==10) thenIf i is equal to 10
if (i > =10) thenIf i is 10 or more
if (i > 10) thenIf i is more than 10
if (i ~=10) thenIf i is a number other than 10
if ( bool == true) thenif bool is true
if ( bool ~= true) thenif bool is not true
If type is less than 10, assign 1 to termID.
If type is less than 10, assign 10 to termID.
If type is 10 or more and less than 20, assign 20 to termID.
If type is 20 or more, assign 30 to termID.
The "elsif condition then process" sentence can be written multiple
times.
Up to 20 nests can be made for the conditional branching.
Reference
E SR SCRIPT RM
8
Page 9
4-2Repeat process
Continuation condition
Process
Yes
No
Final value of counter >= counter
Initialization of
Yes
No
Process
Addition of counter
Continuation condition
Process
Yes
No
No
Conditional expression
This section describes processes when repeating processes.
repeat until sentence
repeat until sentences execute process at least once. After the last condition is
checked, whether to repeat is judged.
while sentence
while sentences perform repeat process by specifying continuation conditions.
Format
while continuation
condition do
Process
end
Example
while (i<=10) do
i = i+1
end
As long as the continuation condition is fulfilled, the process is
repeated.
If the continuation condition is not fulfilled, the repeat process
ends.
If i is 10 or less, the value for i is increased by one.
for sentence
for sentences repeat process using the counter to count the number of repetitions.
Format
Format
repeat
Process
until condition
Example
repeat
a=a+2
i = i+1
until (i<=10)
• After the process is executed once, the process is repeated
until the condition is fulfilled.
Regardless of the i value, the value for a is increased by two,
and the value for i is increased by one.
If i is 10 or less, the value for a is increased by two.
break sentence
Use break when going out in the middle of repeat process of while sentences or of
for sentences.
Format
while continuation
condition do
Conditional expression
Process
break
end
end
z Base
for Initialization expression for counter,
and final value do
Process
end
z Specifying "increment of counter"
for
Initialization expression for counter, final value
and increment of counter
Process
end
do
Example
• Sets the default value to the counter
(variable). The process is repeated until
the value exceeds the final value.
• Each time the process ends, the counter
increases by one.
• Sets the default value to the counter
(variable). The process is repeated until
the value exceeds the final value.
• Each time the process ends, the counter
increases by positive and negative integer
value specified.
* break can be written only just before end.
To call break in the middle of the sentence, write as below.
Example
do
break
end
for i=1,5 do
a=a+2
end
If i is 5 or less, the value for a is increased by two.
9
E SR SCRIPT RM
Page 10
5-1Input/Output functions
Reference
When "Single read" is performed on SR-1000/D100/750/700 by registering 3
parameter banks for which alternate reading is enabled.
• Read OK
When reading is successful with the first bank
When reading is successful with the second and third banks
• Read error
When reading fails
Read error image
readResult(1)
imageResult(1)
readResult(1)
imageResult(1)
readResult(1)
imageResult(1) imageResult(2) imageResult(3)
When 4 "Multi read" are set for "Bank 1 Code Settings" on SR-750/D100 by
registering 1 parameter bank for which alternate reading is enabled.
If 4 codes are read with Multi read set to Enable, the result is 1 image and 4
read data.
as9132Verification()NoneSAE AS9132 verification result
semiT10Verification()None
japanMedicalVerification
()
imageFileNames()NoneImage file name
readingDuration()NoneReading duration [ms]
burstNum()None
errCode()None
outonEvent(n)
*1 The functions of the code reader main unit must be enabled beforehand.
*2 When using the script for the edit image file name, the file name after the image
file is changed is output. When multiple image files exist, the value of the Interdelimiter is the same value set for the SR-1000/D100/750/700.
Argu-
ment
None
n:
Output
terminal
number
Return valueApplicable model
Code type (Refer to "8-3
Code type" (Page 19).)
Symbol identifier (3 characters)
(Refer to "8-3 Code type"
(Page 19).)
Code top coordinates:
"X1/Y1:X2/Y2:X3/Y3:X4/Y4"
Code center coordinates: "X1/
Y1"
Unused error correction (0 to
100)
ISO/IEC15415 verification
*1
result
ISO/IEC TR 29158(AIM DPM-1-
2006) verification result
SEMI T10-070 verification
*1
result
Verification result of the Japan
ethical drug barcode
Burst number when reading is
successful
Detail error code
This is output only for burst.
None
(The corresponding output
terminal turns on.)
1000
1000
1000
1000
1000
1000
1000
1000
*1
*1
*1
*2
1000
1000
1000
*1
1000
1000
1000
1000
1000
1000
*1
1000
750
750
750
750
750
750
750
750
750
750
750
750
750
750
750
750
750
Example 2
• The imageResult function cannot be used with the SR-700 Series.
• The functions that can be used vary depending on the model.
From section 5-2 to section 5-4, the applicable models are listed as
shown below.
: SR-1000 Series
: SR-D100 Series
: SR-750 Series
: SR-700 Series
E SR SCRIPT RM
Functions used when reading the GS1 composite
Function name
readData()NoneRead data
symbolIdentifier()NoneSymbol identifier
cornerCoordinates()None
Argu-
ment
Code top coordinates:
"X1/Y1:X2/Y2:X3/Y3:X4/Y4:
X1/Y1:X2/Y2:X3/Y3:X4/Y4"
Return value
*3
*3
*4
centerCoordinate()NoneCode center coordinates:
matchingLevel()NoneMatching Level (0-100)
readDataCompositeLen
1D()
*3 When reading the GS1 composite (JAN/EAN/UPC), the 1D code and 2D code
are connected with a composite delimiter and then output.
*4 When reading the GS1 composite code, values of the 1D code and 2D code
Data length of the GS1
None
composite 1D code
Applicabl
e model
1000
1000
*4
1000
1000
1000
are obtained separately, connected with a partition mark, and then output.
Functions used in imageResult(idx)
These functions obtain information of captured images. Use as imageResult(n):***
Example) imageResult(1):bankNo()
Function name
Argu-
ment
Return valueApplicable model
bankNo()NoneBank number or nil
burstNum()None
imageFileName()NoneImage file name
readDatas()None
readResultIdx()None
*1 If the script is not used with the SR-D100 Series, information called A:\IMAGE is
appended to the beginning of the image name, however, if imageFileNames()
Burst number of a captured
image
Character string data of the
barcode itself or nil
(Concatenated when multiple
data are present.)
Index table of append data
(readResult(n)) or nil
*1
1000
1000
1000
is used, this information is not appended.
10
750
750
750
750
750
750
750
750
750
Page 11
5-3Common functions (Basic)
1000
750
1000
750
1000
750
1000
750
1000
D100
750
700
1000
750
1000
750
1000
D100
750
700
1000
750
1000
750
1000
750
1000
750
1000
750
D100
700
D100
700
D100
700
1000
D100
750
700
D100
700
D100
700
1000
D100
750
700
D100
700
D100
700
D100
700
D100
700
D100
700
D100
700
D100
700
1000
D100
750
700
D100
700
D100
700
D100
700
D100
700
1000
D100
750
700
D100
700
D100
700
D100
700
D100
700
1000
D100
750
700
D100
700
D100
700
5-4
Common functions (Advanced)
These functions can be used in common.
Character string processing functions
Function nameArgumentReturn valueApplicable model
left (str, m)
mid(str, s, m)
str: character string
m: number of digits
(1 to 9990)
str: character string
s: 1 to 9990
m: 1 to 9990
Character string of m digits
counted from the start of the
character string (str).
Character string of m digits
counted from s digit position
from the start of the character
string (str). If m is not specified,
the range from the start position
(s) to the end is specified. If the
start position is outside the
range of character string data,
D100
D100
700
700
there is no return value.
right(str, m)
field(str, m, sep)
str: character string
m: 1 to 9990
str: character string
m: 1 to 9990
sep: character
(1 character)
Character string of m digits
counted from the end of the
character string (str)
The mth character string after
dividing the character string
(str) with the separator (sep)
D100
D100
700
700
Reader status acquisition functions
Function nameArgumentReturn valueApplicable model
time()NoneTime
readCount()None
Total number of reading
*1
results
imageCount()NoneTotal number of saved images
result()None
Comparison result
0: Comparison OK, 1:
D100
*1
D100
700
Comparison NG, 2: ERROR
stable()None
Matching level judgment result
0: STABLE, 1: UNSTABLE
IP address (delimited by
ipAddress()None
underscore)
ex)192_168_100_001
masterSlaveID() NoneMaster/Slave ID
masterSlaveGroupNa
me()
NoneMaster/Slave group name
D100
D100
D100
D100
700
*1 When the Master/Slave function is used, result data cannot be obtained correctly.
Debug function
Function nameArgumentReturn valueApplicable model
print(str)
str: character
string
Outputs character strings (str)
when debug is executed.
*2
D100
700
*2 The output setting turns ON after the "SCPDBG,1" command is executed."6-1
Debug methods" (Page 13)
These functions can be used in common. Following is the more advanced functions.
Numeric calculation
Function nameArgumentReturn valueApplicable model
math.max(v,…)
math.min(v,…)
math.abs(v)
math.floor(v)
math.ceil(v)
math.pow(a,n)
math.sqrt(v)
math.deg(rad)
math.rad(deg)
math.sin(rad)
math.cos(rad)
math.tan(rad)
math.asin(rad)
math.acos(rad)
math.atan(rad)
v: numerical value
v: numerical value
v: numerical value
v: numerical value
v: numerical value
a: numerical value
n: numerical value
v: positive numerical value
rad: numerical value
deg: numerical value
rad: numerical value
rad: numerical value
rad: numerical value
rad: numerical value
rad: numerical value
rad: numerical value
Maximum value among
arguments
Minimum value among
arguments
Absolute value
Integer with decimals truncated
Integer with decimals rounded
up
n
a
√v
Converts radian values to angular
degrees.
Converts angular degrees to radian
values.
sin
cos
tan
arc sin
arc cos
arc tan
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
750
750
750
750
750
750
750
750
750
750
750
750
Character string operation
Function nameArgumentReturn valueApplicable model
string.len(str)
string.lower(str)
string.upper(str)
string.rep(str,n)
string.reverse(str)
string.sub(str,i,j)
string.byte(str,i)
string.char(c1,c2,
…)
string.find(str,p)
string.match(str,p)
string.gmatch(str,
p)
string.gsub(str,p,r
,n)
str: character string
str: character string
str: character string
str: character string
n: numerical value
str: character string
str: character string
i: numerical value
j: numerical value
str: character string
i: numerical value
c1: numerical value
str: character string
p: character string or
regular expression
str: character string
p: character string or
regular expression
str: character string
p: character string or
regular expression
str: character string
p: character string or
regular expression
r: character string
n:
numerical value
(Can be omitted)
Character string (str) length
Converts the character string
(str) to lowercase characters.
Converts the character string
(str) to uppercase characters.
Character string that repeated
the character string (str) n times
Reverses the alignment
sequence of character string
(str).
Portion of character string from
ith character to jth character of
the character string (str)
Returns the character code for
the ith character of the
character string (str)
Character string for the
character code.
Searches characters that
match p among the character
string (str), and then returns the
digit number at the head and
the digit number at the end.
Returns characters that match
p among the character string
(str).
Used for for loop.
Each time the characters that
match p among the character
string (str) are called, the result
is returned in turn.
Replaces characters that match
p among the character string
(str) with r.
If n is specified, the first n
characters in the character
string are replaced.
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
750
750
750
750
750
750
750
750
750
750
11
E SR SCRIPT RM
Page 12
Array operation
1000
D100
750
700
1000
D100
750
700
1000
750
1000
750
1000
750
1000
750
1000
750
1000
750
1000
750
1000
750
1000
750
Function nameArgumentReturn valueApplicable model
table.concat(tbl,se
p,i,j)
table.insert(tbl,i,v
)
table.maxn(tbl)tbl: array name
table.remove(tbl.i
)
table.sort(tbl)tbl: array name
tbl: array name
sep: character
(1 character)
i: numerical
value
j: numerical
value
tbl: array name
i: numerical
value
v: numerical
value
tbl: array name
i: numerical
value
Character strings combined
after the data from tbl[i] to l[j] in
the array (tbl) is delimited by
sep.
Inserts v into the tbl[i] position
in the array (tbl).
Elements following the ith
position are moved backward
by one.
No return value.
Returns the largest index value
in the array (tbl).
Deletes the element at the tbl[i]
position in the array (tbl).
Elements following the ith
position are moved forward by
one.
No return value.
Sorts the elements in the array
(tbl).
No return value.
D100
D100
D100
5-5User-defined function
This section describes functions that can be uniquely defined by users.
User-defined function
Format
z Definition of function
function function name (argument)
Variable declaration
700
700
700
Process
return(variable)The value entered into return is the return value.
end
z Calling the function
Function name (value)
Example 1
Others
Function nameArgumentReturn valueApplicable model
assert( v,mes)
error("",1)-
print(mes)
tonumber(v)v: value
tostring(v)v: valueConverts to character strings.
type(v)v: valueVariable type
v: judgment
mes: character string
mes: character string
If v is False, mes is output.
The program is force-quit.
Errors (ScriptError) out
explicitly and terminates the
program.
Outputs messages for debug.
Converts to numerical values.
Returns nil if value conversion
is not possible.
D100
D100
D100
D100
D100
D100
function readformatEvent()
local aDeclares variable a.
700
700
a= test_1()Stores the result of test_1() in variable a.
a = a .. "ABC"Appends character string "ABC" to variable a.
return(a)Outputs the result.
end
700
700
700
700
function test_1()Defines the user-defined function test_1().
local cDeclares variable c.
c = 123Assigns "123" to variable c.
return(c)The value of variable c is the return value.
end
Execution result 123ABC
E SR SCRIPT RM
12
Page 13
6-1Debug methods
6-2Error message list
This section describes debug methods when the script is executed.
Operation check procedure
1 Send the FmtSet.lua file to SR-1000/D100/750/700 Series using
AutoID Network Navigator.
2 Start the AutoID Network Navigator [Terminal] and click [LON] to
start reading.
3 Read with the code reader and check if the result is correctly
reflected.
• For editing read data
→ Check if the output data is correct.
• For editing image file name
→ When using the setting to send image files via FTP, check the name of
image file uploaded on the specified FTP server.
* While reading, if an error message such as "Load Error" is displayed, debug
according to the following debug methods.
LoadErrorScript file loading failed.
ReadResultScriptError
ImageResultScriptError
TimeoutError
ScriptErrorOther errors.
*1 The time for script timeout should be 3 seconds.
Error messageDescription
An error has occurred in
readformatEvent.
An error has occurred in
nameformatEvent.
Script timeout error.
The script execution took too long.
*1
Debug methods
Error details check
1 Send the "SCPERR" command to SR-1000/D100/750/700 Series with
AutoID Network Navigator [Terminal]. (Executing this command will
display the error details.)
2 "error ~~~ FmtSet.lua: ○ : ~~" is displayed. The number applied to ○
is the corresponding row in error.
Open FmtSet.lua with the text editor and repair the source code.
print(mes) display (Page 12)
To check (debug output) the variable value in the source code of FmtSet.lua,
use the print function.
1 Write the print function on where the variable value is to be checked
in the source code of FmtSet.lua.
2 Send the "SCPDBG,1" command to SR-1000/D100/750/700 Series
with AutoID Network Navigator [Terminal]. (Executing this command
enables debug output when reading.)
3 Click [LON] to start reading.
The content specified as the argument of the print function is output.
Referring to this output result, open FmtSet.lua with the text editor and repair
the source code.
4 After the source code is repaired, send the "SCPDBG,0" command
and disable debug output.
After the "SCPDBG,1" command is executed, if the script file is sent to the code
reader, the following error messages are displayed.
Error message list
Load errors
Error messageDescription
error loading module 'FmtSet' from file 'FmtSet.lua':
FmtSet.lua:○: unfinished long comment near '<eof>'
error loading module 'FmtSet' from file 'FmtSet.lua':
FmtSet.lua:○: 'end' expected (to close 'function' at
line 1) near '<eof>'
error loading module 'FmtSet' from file 'FmtSet.lua':
FmtSet.lua:○: 'end' expected (to close 'for' at line 2)
near '<eof>'
error loading module 'FmtSet' from file 'FmtSet.lua':
FmtSet.lua:○: ')' expected (to close '(' at line 1) near
'<eof>'
error loading module 'FmtSet' from file 'FmtSet.lua':
FmtSet.lua:○: <name> or '...' expected near 'end'
error loading module 'FmtSet' from file 'FmtSet.lua':
FmtSet.lua:○: '=' expected near '+'
error loading module 'FmtSet' from file 'FmtSet.lua':
FmtSet.lua:○: '=' expected near '=='
error loading module 'FmtSet' from file 'FmtSet.lua':
FmtSet.lua:○: 'then' expected near '='
error loading module 'FmtSet' from file 'FmtSet.lua':
FmtSet.lua:○: unexpected symbol near '='
error loading module 'FmtSet' from file 'FmtSet.lua':
FmtSet.lua:○: malformed number near '1.a'
Execution errors
Error messageDescription
FmtSet.lua:○: attempt to perform arithmetic on a
string value
FmtSet.lua:○: attempt to perform arithmetic on
global 'a' (a string value)
FmtSet.lua:○: attempt to concatenate a nil value
FmtSet.lua:○: attempt to concatenate global 'a' (a
table value)
FmtSet.lua:○: attempt to call global 'a' (a nil value)
FmtSet.lua:○: attempt to call global 'a' (a number
value)
FmtSet.lua:○: attempt to index global 'a' (a nil value)
FmtSet.lua:○: attempt to index global 'a' (a string
value)
FmtSet.lua:○: bad argument #1 to 'cos' (number
expected, got string)
FmtSet.lua:○: bad argument #2 to 'max' (number
expected, got nil)
“]]” of the comment “-[[ ]]” is missing.
Add “]]” to the end of the comment.
end is missing for “function” on the first
line.
Write end at the correct position.
end is missing for “for” on the second
line.
Write end at the correct position.
“)” for “(” is missing.
Write “)” at the correct position.
When declaring function, “)” for “(” is
missing.
Write “)” at the correct position.
Grammatical error (Arithmetic expression
error).
Check if the arithmetic expression is
correct.
Grammatical error (Is == used instead of
=?)
Correct == to =.
Grammatical error (Is = used instead of
==?)
Correct = to ==.
Grammatical error (Is a value assigned to
the reserved word?)
Do not assign any value to the reserved
word.
Numerical value writing error.
Write numerical values correctly.
Was the arithmetic expression written
with character strings?
Write it correctly.
Was the arithmetic expression written
with character strings?
Write it correctly.
Concatenation failed.
Check if values other than character
strings are not specified.
Concatenation failed.
Check if values other than character
strings are not specified.
Undeclared functions were called.
Check if the name of the function to call
is correct.
Undeclared functions were called.
Check if the name of the function to call
is correct.
Undeclared tables were called.
Check if the name of the table to call is
correct.
Undeclared tables were called.
Check if the name of the table to call is
correct.
Wrong argument.
Specify the correct argument.
Wrong argument.
Specify the correct argument.
13
E SR SCRIPT RM
Page 14
Other errors
Error messageDescription
not enough memory
attempt to call global 'readformatEvent' (a nil value)
attempt to call global 'nameformatEvent' (a nil
value)
FmtSet.lua:○: cancel
Memory shortage has occurred.
Review the program.
The readformatEvent function does not
exist.
Write the readformatEvent function.
The nameformatEvent function does not
exist.
Write the nameformatEvent function.
Aborted while the program is running.
• Aborted by the CANCEL command
• Aborted due to the timeout of the
program execution time
Check if the program is not
supposed to go into the infinite loop
or the process time of the program is
too long.
1 Editing read data
1-1Extracting the first 1 character and the last 2 characters of read data.
1-2 Appending matching level to the end of read data.
-- Obtains the code reading result.
-- Extracts 1 character on the left
and 2 characters on the right.
7-1Practical sample programs
Sample programs
1 Editing read data
1-1 Extracting the first 1 character and the last 2 characters of read data.
1-2 Appending matching level to the end of read data.
1-3 Deleting the first 1 character of read data.
1-4 Deleting all unnecessary zeros at the beginning of barcode.
2 Count
2-1 Counting the number of read codes with "Multi2 read mode".
2-2 Counting the number of readings
3 Conditional branching
3-1 Outputting the type of read codes
3-2 Branching according to the read results (OK/NG/ERROR)
3-3 Branching after looking at the first 1 character of read data
4Comparison
4-1 Comparison when specific characters are included in read data
4-2 Comparison when control characters are included in read data
4-3 Deleting control characters when they are included in read data
4-4 Deleting <LF>(0x) when it is included in read data
4-5 Date comparison
5 Calculations
5-1 Obtaining angular degrees of a tilted code
6 Editing read image file names
6-1 Appending read data to the read image file name
6-2 Appending date and time to the read image file name
6-3 Appending date and time and read data to the read image file name
local year=2012
local month=12
local date=22
local code_Year
local code_Month
local code_Date
local read_data = readResult():readData()
if string.len(read_data) < 8 then
-- Extracts date information and
converts it to numerical values.
-- Returns OK.
5-1 Obtaining angular degrees of a tilted 2D code
function readformatEvent()
if result() == 2 then
return "READ_ERROR"
end
local o_data
local
data = readResult():cornerCoordinates()
local x1_y1 = field(data,1,":")
local x2_y2 = field(data,2,":")
local x1 = tonumber(field(x1_y1,1,"/"))
local x1 = tonumber(field(x1_y1,1,"/"))
local x2 = tonumber(field(x2_y2,1,"/"))
local y2 = tonumber(field(x2_y2,2,"/"))
if (x1 - x2) == 0 then
Angular degrees when a workpiece is read from the front are obtained.
* If it is read from angles other than the front, correct angular degrees cannot be
obtained.
* Set the "partition mark" for SR to ":" (colon).
Execution result
Read data: 22001225. 20111222
Execution result : OKThe year is not correct
This is used to control expiration dates, etc. The date data in the barcode is
compared with the reference date and output.
E SR SCRIPT RM
16
Page 17
5-2 Obtaining angular degrees of a tilted barcode
*SR*
*SR*
6 Editing read image file names
function readformatEvent()
local o_data_u
local o_data
if result() == 2 then
return "READ_ERROR"
end
local data = readResult():cornerCoordinates()
local x1_y1 = field(data,1,":")
local x2_y2 = field(data,2,":")
local x3_y3 = field(data,3,":")
local x4_y4 = field(data,4,":")
local x1 = tonumber(field(x1_y1,1,"/"))
local y1 = tonumber(field(x1_y1,2,"/"))
local x2 = tonumber(field(x2_y2,1,"/"))
local y2 = tonumber(field(x2_y2,2,"/"))
local x3 = tonumber(field(x3_y3,1,"/"))
local y3 = tonumber(field(x3_y3,2,"/"))
local x4 = tonumber(field(x4_y4,1,"/"))
local y4 = tonumber(field(x4_y4,2,"/"))
Angular degrees when a workpiece is read from the front are obtained.
* If it is read from angles other than the front, correct angular degrees cannot be
obtained.
* Set the "partition mark" for SR to ":" (colon).
Read data: keyence
Execution result : 20121222120001_keyence.bmp
* When setting the time on the SR-D100 Series, synchronize the time when setting
with the AutoID Network Navigator.
* When setting the time on the SR-1000/750 Series, prepare the SNTP server on
the same network and enable the synchronization with the SNTP.
17
E SR SCRIPT RM
Page 18
7 Controlling output terminals
^
not # - (unary)
* / %
+ -
..
< > <= >= ~= ==
and
or
High
Low
To use scripts to control the output terminals, you have to set "Enable scripts," and
then configure the settings as shown below.
7-1 Controlling output terminals (OK/NG/ERROR)
function readformatEvent()
local r_data = result()
local data = readResult():readData()
if r_data == 0 then
outonEvent(1)
elseif r_data == 2 then
outonEvent(2)
else
outonEvent(1)
outonEvent(2)
end
return (data)
end
Execution result
Read data: keyence
Execution result : OUT1 turns on.
7-2 Preventing duplicate reading
--If the result is OK, turn on OUT1.
--If the result is ERROR, turn on
OUT2.
--In all other situations, turn on
OUT1 and OUT2.
8-1ASCII code table
High-order 4 bits
Low-
order 4
bits
Hexadecimal
number
number
00000
10001
20010
30011
40100
50101
60110
70111
81000
91001
A1010
B1011
C110 0
D110 1
E11 10
F1111
01234567
Binary
0000 0001 0010 0011 0100 0101 0110 0111
NUL
DLE
000
SOH
001
STX
002
ETX
003
EOT
004
ENQ
005
ACK
006
BEL
007
BS
008
HT
009EM025)0419057I073Y089i105y121
LF
010
VT
011
CL
012FS028,044<060L076\092l108|124
CR
013GS029-045=061M077]093m109}125
SOH
014RS030.046>062N078^094n110~126
SI
015US031/047?063O079_095o111
(SP)
016
0320048@064P080`096p112
DC1
017!0331049A065Q081a097q113
DC2
018"0342050B066R082b098r114
DC3
019#0353051C067S083c099s115
DC4
020$0364052D068T084d100t116
NAK
021%0215053E069U085e101u117
SYN
022&0386054F070V086f102v118
ETB
023'0397055G071W087g103w119
CAN
024(0408056H072X088h104x120
SUB
026*042:058J074Z090j106z122
ESC
027+043;059K075[091k107{123
DEL
127
8-2Reserved words/Language
elements
local g_latestData = ""
function readformatEvent()
local r_data = result()
local readData = readResult():readData()
if r_data == 0 then
if g_latestData == readData then
return ""
end
g_latestData = readData
outonEvent(1)
return readData
elseif r_data == 2 then
outonEvent(2)
return "ERROR"
end
end
Execution result
Read data: keyence
Execution result : keyence (The same data is not output twice.)
--
Branching depending on the result (OK/ERROR)
--Read data
--OK
--ERROR
8Others
8-1Appending brackets to AI of GS1-128, GS1 Databar and GS1-DataMatrix.
Brackets are appended to AI. Download this sample program from KEYENCE Web
page.
*1 Specify characters other than alphanumeric characters
*1
Literal character
8-3Code type
Code type list used for symbolType of readResult(idx)
Code typeReturn value of symbolType
Reading error0
QR1
DataMatrix2
PDF417/MicroPDF3
GS1 DataBar5
CODE396
ITF7
2of58
NW-7(Codabar)9
JAN/EAN/UPC10
CODE12811
COOP2of512
CODE9313
CC-A/B(GS1 DataBar)14
CC-A/B(JAN/EAN/UPC)15
CC-A/B/C(GS-128)16
Pharmacode18
The script does not operate.
If codes can be read normally but the script does not operate, the script execution
setting of the SR-1000/D100/750/700 Series may not be set to "Enable". Using the
AutoID Network Navigator, set the script execution setting to "Enable".
* For using the AutoID Network Navigator, refer to the corresponding user's
manual.
Expected results cannot be achieved.
Debug according to "6-1 Debug methods" (Page 13)
An error occurs when executed.
See the applicable error message on "6-2 Error message list" (Page 13), and
revise the program.
Barcodes/2D codes cannot be read.
Reading setting may not be correctly made on your code reader. Using the AutoID
Network Navigator, make the reading setting for the SR-1000/D100/750/700
Series.
* For using the AutoID Network Navigator, refer to the corresponding user's
manual.
8-5Copyright indication
This software uses the following libraries:
Lua:
Copyright (c) 1994-2014 Lua.org, PUC-Rio.
Code type list used for symbolIdentifier of readResult(idx)
Copyright (c) 2014 KEYENCE CORPORATION. All rights reserved.
193033E 1104-5 301GB Printed in Japan
Date of printing
May 2013
September 2013
January 2014
October 2014
VersionRevision contents
2nd edition
3rd edition
4th edition
5th edition
Erroneous descriptions corrected
Functions have been added due to the upgrade of the
SR-750 series.
Information has been added for the SR-1000/700 Series.
WARRANTIES AND DISCLAIMERS
(1) KEYENCE warrants the Products to be free of defects in materials and workmanship
for a period of one (1) year from the date of shipment. If any models or samples were
shown to Buyer, such models or samples were used merely to illustrate the general
type and quality of the Products and not to represent that the Products would
necessarily conform to said models or samples. Any Products found to be defective
must be shipped to KEYENCE with all shipping costs paid by Buyer or offered to
KEYENCE for inspection and examination. Upon examination by KEYENCE,
KEYENCE, at its sole option, will refund the purchase price of, or repair or replace at
no charge any Products found to be defective. This warranty does not apply to any
defects resulting from any action of Buyer, including but not limited to improper
installation, improper interfacing, improper repair, unauthorized modification,
misapplication and mishandling, such as exposure to excessive current, heat,
coldness, moisture, vibration or outdoors air. Components which wear are not
warranted.
(2) KEYENCE is pleased to offer suggestions on the use of its various Products. They are
only suggestions, and it is Buyer's responsibility to ascertain the fitness of the
Products for Buyer's intended use. KEYENCE will not be responsible for any damages
that may result from the use of the Products.
(3) The Products and any samples ("Products/Samples") supplied to Buyer are not to be
used internally in humans, for human transportation, as safety devices or fail-safe
systems, unless their written specifications state otherwise. Should any Products/
Samples be used in such a manner or misused in any way, KEYENCE assumes no
responsibility, and additionally Buyer will indemnify KEYENCE and hold KEYENCE
harmless from any liability or damage whatsoever arising out of any misuse of the
Products/Samples.
(4) OTHER THAN AS STATED HEREIN, THE PRODUCTS/SAMPLES ARE PROVIDED
WITH NO OTHER WARRANTIES WHATSOEVER. ALL EXPRESS, IMPLIED, AND
STATUTORY WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, AND NON-INFRINGEMENT OF PROPRIETARY RIGHTS, ARE
EXPRESSLY DISCLAIMED.
IN NO EVENT SHALL KEYENCE AND ITS AFFILIATED ENTITIES BE LIABLE TO
ANY PERSON OR ENTITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, PUNITIVE,
SPECIAL OR CONSEQUENTIAL DAMAGES (INCLUDING, WITHOUT LIMITATION,
ANY DAMAGES RESULTING FROM LOSS OF USE, BUSINESS INTERRUPTION,
LOSS OF INFORMATION, LOSS OR INACCURACY OF DATA, LOSS OF
PROFITS, LOSS OF SAVINGS, THE COST OF PROCUREMENT OF
SUBSTITUTED GOODS, SERVICES OR TECHNOLOGIES, OR FOR ANY MATTER
ARISING OUT OF OR IN CONNECTION WITH THE USE OR INABILITY TO USE
THE PRODUCTS, EVEN IF KEYENCE OR ONE OF ITS AFFILIATED ENTITIES
WAS ADVISED OF A POSSIBLE THIRD PARTY'S CLAIM FOR DAMAGES OR
ANY OTHER CLAIM AGAINST BUYER. In some jurisdictions, some of the foregoing
warranty disclaimers or damage limitations may not apply.
BUYER'S TRANSFER OBLIGATIONS:
If the Products/Samples purchased by Buyer are to be resold or delivered to a third
party, Buyer must provide such third party with a copy of this document, all
specifications, manuals, catalogs, leaflets and written information provided to Buyer
pertaining to the Products/Samples.
BarcodeReader.com
http://www.barcodereader.com/
You can download technical documents useful for BL/SR/RF introduction and
operation.
E 1101-3
E SR SCRIPT RM
20
Loading...
+ 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.