*读取2/5字体一维码
*Read bar codes of type 2/5 Industrial
- 创建一维码读取句柄
create_bar_code_model ([], [], BarCodeHandle)
*设置每次只读取一个一维码,参数意义为:‘搜索到个数后停止’ - We expect to decode a single bar code per image
set_bar_code_param (BarCodeHandle, ‘stop_after_result_num’, 1)
*有些条码码长为一位,所以这里我们要更改一下默认设置() - Some codes show a minimal code length of 1 digit. Hence, we need to decrease the
- default setting for this application.
set_bar_code_param_specific (BarCodeHandle, ‘2/5 Industrial’, ‘min_code_length’, 1)
*当然,在实际应用中,为了避免过多的错误读取,我们并不推荐这么做 - Note, that this is not recommended in real world applications due to the possibility
- of more false reads.
*关闭窗体更新
dev_close_window ()
*打开新窗体
dev_open_window (0, 0, 120, 300, ‘black’, WindowHandle)
*设置显示字体
set_display_font (WindowHandle, 14, ‘mono’, ‘true’, ‘false’)
*设置填充方式
dev_set_draw (‘margin’)
*设置线宽
dev_set_line_width (3)
*读取四张图片分贝处理
for I := 1 to 4 by 1
*读取图片
read_image (Image, ‘barcode/25industrial/25industrial0’ + I)
*获取图片尺寸
get_image_size (Image, Width, Height)
*设置激活的窗体尺寸
dev_set_window_extents (0, 0, Width - 1, Height - 1)
*显示图像
dev_display (Image)
*设置显示颜色为绿色
dev_set_color (‘green’)
*读取条码,结果中包含校验字符- Read bar code, the resulting string includes the check character
*设置校验字符为“absent”,不验证条码的正确性
set_bar_code_param (BarCodeHandle, ‘check_char’, ‘absent’)
*读取一维码,结果在DecodedDataStrings中
find_bar_code (Image, SymbolRegions, BarCodeHandle, ‘2/5 Industrial’, DecodedDataStrings)
*显示全部字符
disp_message (WindowHandle, DecodedDataStrings, ‘window’, 12, 12, ‘black’, ‘false’)
*显示最后一个字符为绿色
LastChar := strlen(DecodedDataStrings) - 1
disp_message (WindowHandle, sum(gen_tuple_const(LastChar,’ ')) + DecodedDataStrings{LastChar}, ‘window’, 12, 12, ‘forest green’, ‘false’)
stop ()
*读取一维码,并用校验码去检测这个字符,那么这个字符就不属于这个一维码内容了,当然如果校验码不正确,那么读取结果也不对 - Read bar code using the check character to check the result, i.e.,
- the check character does not belong to the returned string anymore.
- If the check character is not correct, the bar code reading fails
dev_set_color (‘green’)
*设置校验字符为“present”,要验证条码的正确性
set_bar_code_param (BarCodeHandle, ‘check_char’, ‘present’)
*读取一维码
find_bar_code (Image, SymbolRegions, BarCodeHandle, ‘2/5 Industrial’, DecodedDataStrings)
*显示一维码
disp_message (WindowHandle, DecodedDataStrings, ‘window’, 36, 12, ‘black’, ‘false’)
dev_set_color (‘magenta’)
if (I < 4)
stop ()
endif
endfor
*释放内存
clear_bar_code_model (BarCodeHandle)
- Read bar code, the resulting string includes the check character