KEYENCE SR-700 User Manual

Page 1
SR-1000/D100/750/700 Series
Point
Reference
301GB
Script Reference Rev.5.0
Symbols
This user's manual uses the following symbols that alert you to important messages. Be sure to read these messages carefully.
It indicates a hazardous situation which, if not avoided, will result
DANGER
in death or serious injury.
It indicates a hazardous situation which, if not avoided, could
WARNING
result in death or serious injury.
It indicates a hazardous situation which, if not avoided, could
CAUTION
result in minor or moderate injury.
It indicates a situation which, if not avoided, could result in
NOTICE
product damage as well as property damage.
Cautions as to operation that is always performed are shown.
Table of Contents
General cautions .................................................................................. 1
1-1 Overview .............................................................................................. 2
1-2 Script execution flow ............................................................................ 2
1-3 What Script can do ............................................................................... 2
1-4 Script file configuration ......................................................................... 2
2-1 Naming rules ........................................................................................ 4
2-2 Variables .............................................................................................. 4
2-3 Table .................................................................................................... 5
2-4 Array..................................................................................................... 5
3-1 Calculation............................................................................................ 6
3-2 Comparison .......................................................................................... 6
3-3 Combination of condition......................................................................6
3-4 Character string concatenation ............................................................6
3-5 Pattern matching .................................................................................. 7
4-1 Conditional branching of process.........................................................8
4-2 Repeat process .................................................................................... 9
5-1 Input/Output functions ........................................................................ 10
5-2 Data acquisition functions .................................................................. 10
5-3 Common functions (Basic) ................................................................. 11
5-4 Common functions (Advanced) .......................................................... 11
5-5 User-defined function ......................................................................... 12
6-1 Debug methods.................................................................................. 13
6-2 Error message list .............................................................................. 13
7-1 Practical sample programs ................................................................. 14
8-1 ASCII code table ................................................................................18
8-2 Reserved words/Language elements................................................. 18
8-3 Code type........................................................................................... 19
8-4 Troubleshooting..................................................................................19
8-5 Copyright indication ............................................................................ 19
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-1 Overview

[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
1234567890 1 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-3 What 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-2 Script 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-4 Script 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 a Declares 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
-- Comment Character 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 b Declares 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.
z Usable characters
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789
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-1 Naming 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-2 Variables

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"
Escape sequence : "¥r"
Integer number : 1, -1 Decimal number : 2.0, -2.0 Hexadecimal number notation : 0x0a
True : true False : false
([CR][LF])
(CR)
character string
z Text notation
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=0 Initializes with 0 when declaring variable a.
a=1 Assigns 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.
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 = 0x0f Assigns 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

Pattern Meaning
¥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
¥000 Specifies an arbitrary character code as decimal number.
E SR SCRIPT RM
4
Page 5

2-3 Table

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-4 Array

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 = 0 Declares 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] = 10 Assigns 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-1 Calculation

Reference
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 == 10 true
a~=10 false
Examples of calculations and results
Arithmetic expression
Result
true and true true
true or true true
true and false false
true or false true
not false true
not true false
10 or 30 10
nil or 30 30
false or nil nil

3-3 Combination 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 operator Meaning
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-2 Comparison

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-4 Character 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 c Declares variable c.
c = a..b Assigns 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-5 Pattern 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.
Meta-character
Pattern Meaning
. All characters (arbitrary 1 character)
%a Character
%c Control character (0x01 to 0x1F, 0x7F)
%d Number
%l Alphabet lowercase
%p Symbol (! " # $ % & ' ( ) * + , - . / : ; > = < ? @ [ \ ] ^ _ ` { | })
%s Space character (0x09,0x0a,0x0b,0x0c,0x0d,0x20)
%u Alphabet uppercase
%w Alphabet and number
%x Hexadecimal number (0 to 9, a to f, A to F)
%z null character
% character
*1 Specify characters other than alphanumeric characters
Quantifier
*1
Literal character
Pattern Meaning
+ 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
Pattern Meaning
[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-1 Conditional branching of
Reference
condition 1
process 1 process 2 process 3
condition 2
Yes
No
Yes
No
process
To branch processes, use if sentences.

if sentence

Format
z For 1 branch
if condition 1 then If "condition 1" is fulfilled, "process 1" is executed.
process 1 If "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 type Conditional expression Description
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") then If str is equal to "A"
if (str ~= "A") then If str is not equal to "A"
if (i < 10) then If i is less than 10
if (i < =10) then If i is 10 or less
if (i ==10) then If i is equal to 10
if (i > =10) then If i is 10 or more
if (i > 10) then If i is more than 10
if (i ~=10) then If i is a number other than 10
if ( bool == true) then if bool is true
if ( bool ~= true) then if 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-2 Repeat 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-1 Input/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.
readResult(1) readResult(2) readResult(3) readResult(4)
imageResult(1)
1000
D100
750
700
D100
700
D100
700
D100
700
D100
700
D100
700
D100
750
D100
700
D100
700
D100
700
D100
700
D100
700
D100
700
D100
700
1000
D100
750
700
700
D100
700
D100
700
700
700
700
1000
750
700
700
700
700
700
700
1000
D100
750
D100
D100
D100

5-2 Data acquisition functions

This section describes basic functions for editing data of SR-1000/D100/750/700.
readResult(idx)
Edit read data
Argument idx : Index for read information array
Return value return : Read value
*1
*1 The number of arrays can be obtained using the common function
"readCount()". If idx is omitted, the first code is specified.
imageResult(idx)
Edit image file name
Argument idx : Index for image name information array
Return value return : Image file name
*2
*2 The number of arrays can be obtained using the common function
"imageCount()". If idx is omitted, the first code is specified.

Data entry to readResult and imageResult

Example 1
This describes the functions to obtain data of codes read by SR-1000/D100/750/700.

Functions used in readResult(idx)

These functions obtain information of read data. Use as readResult(n):***
Example) readResult(n):readData()
Function name
readData() None Read data
symbolType() None
symbolIdentifier() None
bankNo() None Bank number
scanTimes() None Scan count
positonStableLevel() None Position measurement level
cornerCoordinates() None
centerCoordinate() None
eccQuality() None
matchingLevel() None Matching Level (0-100)
i15415Verification() None
aimVerification() None
as9132Verification() None SAE AS9132 verification result
semiT10Verification() None
japanMedicalVerification ()
imageFileNames() None Image file name
readingDuration() None Reading 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 Inter­delimiter is the same value set for the SR-1000/D100/750/700.
Argu-
ment
None
n: Output terminal number
Return value Applicable 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() None Read data
symbolIdentifier() None Symbol 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() None Code center coordinates:
matchingLevel() None Matching 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 value Applicable model
bankNo() None Bank number or nil
burstNum() None
imageFileName() None Image 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-3 Common 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 name Argument Return value Applicable 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 name Argument Return value Applicable model
time() None Time
readCount() None
Total number of reading
*1
results
imageCount() None Total 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() None Master/Slave ID
masterSlaveGroupNa me()
None Master/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 name Argument Return value Applicable 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 name Argument Return value Applicable 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 name Argument Return value Applicable 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 name Argument Return value Applicable 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-5 User-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 name Argument Return value Applicable model
assert( v,mes)
error("",1) -
print(mes)
tonumber(v) v: value
tostring(v) v: value Converts to character strings.
type(v) v: value Variable 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 a Declares 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 c Declares variable c.
c = 123 Assigns "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-1 Debug methods

6-2 Error 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.
LoadError Script file loading failed.
ReadResultScriptError
ImageResultScriptError
TimeoutError
ScriptError Other errors.
*1 The time for script timeout should be 3 seconds.
Error message Description
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 message Description
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 message Description
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 message Description
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-1 Extracting the first 1 character and the last 2 characters of read data.
function readformatEvent()
local read_data
read_data = readResult():readData() read_data = left(read_data,1)..right(read_data,2)
return(read_data)
end
Execution result
Read data : keyence
Execution result : kce
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-1 Practical 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
7 Controlling output terminals
7-1 Controlling output terminals (OK/NG/ERROR) 7-2 Preventing duplicate reading
8Others
8-1 Appending brackets to AI of GS1-128, GS1 Databar and GS1-
DataMatrix.
function readformatEvent()
local read_data
read_data = readResult():readData() read_data = read_data .. readResult():matchingLevel()
return(read_data)
end
Execution result
Read data : keyence
Execution result : keyence65 (When the matching level is 65)
-- Stores read data in the variable.
-- Appends matching level.
* To append the matching level, the functions must be enabled on the SR Series
main unit settings beforehand.
1-3 Deleting the first 1 character of read data.
function readformatEvent()
local read_data local datalength
read_data = readResult():readData() datalength = string.len(read_data) read_data = mid(read_data,2,datalentgh-1)
return(read_data)
end
Execution result
Read data : keyence
Execution result : eyence
-- Stores read data in the variable.
-- Obtains the length of read data
-- Extracting character strings from the second character to the end.
1-4 Deleting all unnecessary zeros at the beginning of barcode.
function readformatEvent()
local read_data = readResult():readData() local data
data = string.gsub(read_data,"^0+","")
return(data)
end
Execution result
Read data : 00000143
Execution result : 143
-- Obtains the code reading result.
-- Remove consecutive zeros from the start.
E SR SCRIPT RM
14
Page 15
2 Count
3-2 Branching according to the read results (OK/NG/ERROR)
2-1 Counting the number of read codes with "Multi2 read mode".
function readformatEvent()
local read_count = readCount() local counter=0 local i=0 for i = 1, read_count do
if
readResult(i):readData() ~= "ERROR" then
counter = counter + 1
end
end return(counter)
end
Execution result
Read data : keyence
Number of read codes : 3 Execution result : 3
--
Number of read codes with "Multi2 read mode"
--
Counts the number of reading success codes.
-- Counts the number of codes other than "ERROR" codes among read codes.
* This is a sample for the SR-D100/750.
2-2 Counting the number of readings
local count = 0 function readformatEvent()
local maxCount = 5 local data
while count < maxCount do
count = count + 1 data = readResult():readData() .. ":count_data is"..count
return data
end return "5 count over"
end
Execution result
Read data : keyence
Number of readings : n (n=1 to 4) n=5 and more Execution result :
keyence:count_data is n 5 count over
-- Retains count.*1
-- If codes are read 5 times or more, "5 count over" is returned.
*1 The variable value defined here is initialized when the script file is sent again or
the SR main unit is reset.
* When the Master/Slave function is used, the count is not correct.
3 Conditional branching
3-1 Outputting the type of read codes
function readformatEvent()
local data = readResult():symbolType() if data == 1 then
return "QR"
elseif data == 2 then
return "DataMatrix"
elseif data == 5 then
return "GS1 DataBar"
elseif data == 6 then
return "CODE39"
elseif data == 7 then
return "ITF"
elseif data == 9 then
return "Codabar"
elseif data == 10 then
return "JAN/EAN/UPC"
elseif data == 11 then
return "CODE128"
elseif data == 0 then
return "no data"
end return "other"
end
Execution result
Read data : keyence
Execution result : DataMatrix
* The symbolType function in "5-2 Data acquisition functions" (Page 10) is
used.
-- Stores code types.
-- Conditionally branches according to the type of code.
function readformatEvent()
local r_data = result() local data = readResult():readData() if r_data == 0 then
return "OK:"..data
elseif r_data == 1 then
return "NG:"..data
elseif r_data == 2 then
return "ERROR:"..data
end return "result has no return"
end
Execution result
Read data : keyence
Execution result : OK:keyence (Reading success)
-- Branches according to the read results (OK/NG/ERROR).
-- OK image
-- Comparison NG
-- READ ERROR
3-3 Branching after looking at the first 1 character of read data
function readformatEvent()
local data = readResult():readData() local header = left(data,1) if header == "1" then
return "A"
elseif header == "2" then
return "B"
else
return "Z"
end return "other"
end
Execution result
Read data : 1SR-D100 2SR-D110 3SR-D100HA
Execution result : A B Z
-- Obtains the code reading result.
-- Obtains the first 1 character.
4Comparison
4-1 Comparison when specific characters are included in read data
function readformatEvent()
local o_data= "" if
string.match(readResult():readData(),"456")
o_data = readResult():readData() .. "_OK"
else
o_data = readResult():readData() .. "_NG"
end return (o_data)
end
Execution result
Read data : 123456789
Execution result : 123456789_OK
then
( "3-5 Pattern matching" (Page 7)is used.)
4-2 Comparison when control characters are included in read data
function readformatEvent()
local o_data= "" if
string.match(readResult():readData(),"%c")
o_data = "OK"
else
o_data ="NG"
end return (o_data)
end
Execution result
Read data : ABC<HT>123
Execution result : OK
( "3-5 Pattern matching" (Page 7)is used.)
--
When "456" is included in read data
--Appends "_OK" to the end of read data.
-- Other cases Appends "_NG" to the end of read
-­data.
then
--
When control characters are included in read data
-- Outputs "OK".
-- Other cases
-- Outputs "NG".
15
E SR SCRIPT RM
Page 16
4-3 Deleting control characters when they are included in read data
5 Calculations
function readformatEvent()
local read_data
read_data=readResult():readData() read_data=string.gsub(read_data,"%c","") read_data=string.gsub(read_data,"%z","")
return(read_data)
end
Execution result
Read data : <SOH><SOH>123
Execution result : 123
-- Deletes control characters
-- Deletes NULL<0x00>
( "3-5 Pattern matching" (Page 7)is used.)
4-4 Deleting <LF>(0x0A) when it is included in read data
function readformatEvent()
local read_data
read_data=readResult():readData() read_data=string.gsub(read_data,"\010","")
return(read_data)
end
Execution result
Read data : ABC<LF>123
Execution result : ABC123
-- Deletes [LF]<0x0A>(010 in decimal number)
4-5 Date comparison
function readformatEvent()
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
return("reading data is not correct")
end
code_Year = tonumber(left(read_data ,4)) code_Month = tonumber(mid(read_data,5,2)) code_Date = tonumber(mid(read_data,7,2))
if code_Year < year then
return "The year is not correct"
elseif code_Month < month then
return "The month is not correct"
elseif code_Date < date then
return "The date is not correct"
end return ("OK")
end
-- 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
o_data = "90".."[deg]_"..readResult():readData()
return (o_data)
elseif (y1 - y2) == 0 then
o_data = "0".."[deg]_"..readResult():readData()
return (o_data)
else
o_data = (y1 - y2)/(x2 - x1) o_data = math.atan(o_data) o_data = math.deg(o_data) o_data = math.floor(o_data) o_data = o_data.."[deg]_"..readResult():readData()
return (o_data)
end
end
Execution result
Read Data :
Execution result : 45[deg]_keyence 0[deg]_keyence
-- Displays the message at read error.
--
Obtains the coordinates at 4 positions of code.
-- x1/y1:x2/y2:x3/y3:x4/y4
-- Obtains arctan.
-- Radian --> Converted to deg(°).
-- Truncates decimals.
-- Appends read data to output.
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 : OK The 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,"/"))
if (x3 - x2) == 0 then
if(y3 - y2) > 0 then
o_data_u = 0
else
o_data_u = 180
end
elseif (y3 - y2) == 0 then
if (x3 - x2) > 0 then
o_data_u = -90
else
o_data_u = 90
end
else
o_data_u = (y3 - y2)/(x3-x2) o_data_u = math.atan(o_data_u) o_data_u = math.deg(o_data_u) o_data_u = math.floor(o_data_u)
if (x3 > x2) then
o_data_u = -90 + o_data_u
else
o_data_u = 90 + o_data_u
end
end
o_data = o_data_u.."[deg]_"..readResult():readData()
return (o_data)
end
--Output data
--Displays the message at read error.
--
Obtains the coordinates at 4 positions of code.
--x1/y1:x2/y2:x3/y3:x4/y4
--Converts it to numerical values and assigns the value to the variable.
--Appends read data to output.
6-1 Appending read data to the read image file name
function nameformatEvent()
local read_data
read_data = readResult():readData()
return(read_data)
end
Execution result
Read data : keyence
Execution result : keyence.bmp
-- Obtains the code reading result.
* The read data is specified as the image file name. If a code with exactly the same
data contents is read, the same image file name is adopted. In this case, the old file is overwritten.
6-2 Appending date and time to the read image file name
function nameformatEvent()
return(time())
end
Execution result
Read data : keyence
Execution result : 20121222120001.bmp
-- Obtains date information.
* 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.
6-3 Appending date and time and read data to the read image file name
function nameformatEvent()
local read_data
read_data = readResult():readData() read_data = time().."_"..read_data
return(read_data)
end
Execution result
-- Obtains the code reading result.
-- Appends date information.
Execution result
Read Data :
Execution result : 30[deg]_SR 0[deg]_SR
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-1 ASCII code table

High-order 4 bits
Low-
order 4
bits
Hexadecimal
number
number
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
A 1010
B 1011
C 110 0
D 110 1
E 11 10
F 1111
0 1 2 3 4 5 6 7
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-2 Reserved 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-1 Appending brackets to AI of GS1-128, GS1 Databar and GS1-DataMatrix.
Brackets are appended to AI. Download this sample program from KEYENCE Web page.
E SR SCRIPT RM

Reserved word list

and break do else elseif end false for function goto if in local nil not or repeat return then true until while
* Do not use variables/functions starting with "_" (underscore).

Priority of operator

18
Page 19

Pattern matching

8-4 Troubleshooting

Pattern Meaning
. All characters (arbitrary 1 character)
%a Character
%c Control character (0x01 to 0x1F, 0x7F)
%d Number
%l Alphabet lowercase
%p Symbol (! " # $ % & ' ( ) * + , - . / : ; > = < ? @ [ \ ] ^ _ ` { | })
%s Space character (0x09,0x0a,0x0b,0x0c,0x0d,0x20)
%u Alphabet uppercase
%w Alphabet and number
%x Hexadecimal number (0 to 9, a to f, A to F)
%z null character
% character
*1 Specify characters other than alphanumeric characters
*1
Literal character

8-3 Code type

Code type list used for symbolType of readResult(idx)

Code type Return value of symbolType
Reading error 0
QR 1
DataMatrix 2
PDF417/MicroPDF 3
GS1 DataBar 5
CODE39 6
ITF 7
2of5 8
NW-7(Codabar) 9
JAN/EAN/UPC 10
CODE128 11
COOP2of5 12
CODE93 13
CC-A/B(GS1 DataBar) 14
CC-A/B(JAN/EAN/UPC) 15
CC-A/B/C(GS-128) 16
Pharmacode 18
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-5 Copyright 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)

Code type Details Symbol identifier
QR code Model 1 ]Q0
Model 2 ]Q1
Model 2, FNC1 is first. ]Q3
Model 2, FNC1 is second. ]Q5
DataMatrix ECC200 ]d1
PDF417 Standard ]L0
GS1 Databar ]e0
CODE39 No check digit ]A0
ITF No check digit ]l0
2of5 ]S0
NW-7(Codabar) ]F0
JAN/EAN/UPC UPC-A, UPC-E, JAN/EAN 13digits ]E0
CODE128 FNC1 is not included. ]C0
ECC200, FNC1 is first or fifth ]d2
ECC200, FNC1 is second or sixth. ]d3
Extended channel interpretation ]L1
Basic channel interpretation ]L2
Inspect check digit (Sent) ]A1
Inspect check digit (Not sent) ]A3
Inspect check digit (Sent) ]l1
Inspect check digit (Not sent) ]l3
JAN/EAN 8 digits ]E4
UPC-A, UPC-E, JAN/EAN 13digits Supplemental 2 digits. supplemental 5 digits
First digit is FNC1 (GS1-128). ]C1
Second digit is FNC1. ]C2
]E3
19
E SR SCRIPT RM
Page 20

Revision History

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
Version Revision 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...