5 calculations – KEYENCE SR-700 Series User Manual

Page 16

Advertising
background image

16

E SR SCRIPT RM

4-3

Deleting control characters when they are included in read data

(

"3-5 Pattern matching" (Page 7)is used.)

4-4

Deleting <LF>(0x0A) when it is included in read data

4-5

Date comparison

This is used to control expiration dates, etc. The date data in the barcode is
compared with the reference date and output.

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

-- Deletes control characters
-- Deletes NULL<0x00>

Execution result

Read data

: <SOH><SOH>123

Execution result

: 123

function readformatEvent()

local

read_data

read_data=readResult():readData()
read_data=string.gsub(read_data,"\010","")

return

(read_data)

end

-- Deletes [LF]<0x0A>(010 in

decimal number)

Execution result

Read data

: ABC<LF>123

Execution result

: ABC123

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.

Execution result

Read data

: 22001225.

20111222

Execution result

: OK

The year is not correct

5 Calculations

5-1

Obtaining angular degrees of a tilted 2D code

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).

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

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

Execution result

Read Data

:

Execution result

: 45[deg]_keyence

0[deg]_keyence

Advertising
This manual is related to the following products: