User guide

15
E SR SCRIPT RM
2 Count
2-1 Counting the number of read codes with "Multi2 read mode".
* This is a sample for the SR-D100/750.
2-2 Counting the number of readings
*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
* The symbolType function in "5-2 Data acquisition functions" (Page 10) is
used.
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
--
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.
Execution result
Read data : keyence
Number of read codes : 3
Execution result : 3
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
-- Retains count.*1
-- If codes are read 5 times or more,
"5 count over" is returned.
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
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
-- Stores code types.
-- Conditionally branches according
to the type of code.
Execution result
Read data : keyence
Execution result : DataMatrix
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
( "3-5 Pattern matching" (Page 7)is used.)
4-2 Comparison when control characters are included in read data
( "3-5 Pattern matching" (Page 7)is used.)
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
-- Branches according to the read
results (OK/NG/ERROR).
-- OK image
-- Comparison NG
-- READ ERROR
Execution result
Read data : keyence
Execution result : OK:keyence (Reading success)
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
-- Obtains the code reading result.
-- Obtains the first 1 character.
Execution result
Read data : 1SR-D100 2SR-D110 3SR-D100HA
Execution result : A B Z
function readformatEvent()
local o_data= ""
if
string.match(readResult():readData(),"456")
then
o_data = readResult():readData() .. "_OK"
else
o_data = readResult():readData() .. "_NG"
end
return (o_data)
end
--
When "456" is included in read data
--
A
ppends "_OK" to the end of read data.
-- Other cases
--
Appends "_NG" to the end of read
data.
Execution result
Read data : 123456789
Execution result : 123456789_OK
function readformatEvent()
local o_data= ""
if
string.match(readResult():readData(),"%c")
then
o_data = "OK"
else
o_data ="NG"
end
return (o_data)
end
--
When control characters are included in read data
-- Outputs "OK".
-- Other cases
-- Outputs "NG".
Execution result
Read data : ABC<HT>123
Execution result : OK