1 practical sample programs, Sample programs, Practical sample programs – KEYENCE SR-700 Series User Manual

Page 14: 1 editing read data

Advertising
background image

14

E SR SCRIPT RM

Other errors

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

4 Comparison

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

8 Others

8-1 Appending brackets to AI of GS1-128, GS1 Databar and GS1-

DataMatrix.

Error message

Description

not enough memory

Memory shortage has occurred.
Review the program.

attempt to call global 'readformatEvent' (a nil value)

The readformatEvent function does not
exist.
Write the readformatEvent function.

attempt to call global 'nameformatEvent' (a nil
value)

The nameformatEvent function does not
exist.
Write the nameformatEvent function.

FmtSet.lua:○: cancel

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.

1-2

Appending matching level to the end of read data.

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

1-4

Deleting all unnecessary zeros at the beginning of barcode.

function readformatEvent()

local

read_data

read_data = readResult():readData()
read_data = left(read_data,1)..right(read_data,2)

return

(read_data)

end

-- Obtains the code reading result.
-- Extracts 1 character on the left

and 2 characters on the right.

Execution result

Read data

: keyence

Execution result

: kce

function readformatEvent()

local

read_data

read_data = readResult():readData()
read_data = read_data .. readResult():matchingLevel()

return

(read_data)

end

-- Stores read data in the variable.
-- Appends matching level.

Execution result

Read data

: keyence

Execution result

: keyence65

(When the matching level is 65)

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

-- Stores read data in the variable.
-- Obtains the length of read data
-- Extracting character strings from

the second character to the end.

Execution result

Read data

: keyence

Execution result

: eyence

function readformatEvent()

local

read_data = readResult():readData()

local

data

data = string.gsub(read_data,"^0+","")

return

(data)

end

-- Obtains the code reading result.

-- Remove consecutive zeros from

the start.

Execution result

Read data

: 00000143

Execution result

: 143

Advertising
This manual is related to the following products: