从扫描的 GS1 类型条码中提取信息 [英] Extracting information from a scanned GS1-type barcode

查看:89
本文介绍了从扫描的 GS1 类型条码中提取信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Android Studio 上开发一个应用程序,以便在扫描条形码时获取商品的到期日期.

我不希望用户单独安装 ZXing 条码应用,所以我将 ZXing 代码嵌入到我的项目中.这样做我已经能够获得产品标识符.

我还想使用扫描的条形码数据获取产品信息,例如描述、制造商和有效期.我该怎么做?

解决方案

获取以 GS1 应用标识符标准格式存储数据的 GS1 类型条码表示的信息涉及两个过程.

  1. 提取包含在通过扫描符号获得的 GS1 结构化数据中的数据字段(称为应用标识符).这始终包括称为 GTIN-14 的项目的唯一标识符,并且可能包括补充信息,例如有效期、批号等.此过程可由独立应用程序执行.
  2. 在数据库中
  3. 查找提取的 GTIN,无论是在您的应用程序本地还是通过某些公共 API,以提供原产国、制造商和可能的商品描述的文本表示.要全面执行此过程,应用程序需要访问外部资源.

背景:GS1 应用标识符标准格式组成

GS1 格式的数据由应用标识符 (AI) 和值的串联列表组成,以代表 GTIN 的 AI (01) 开头.

例如数据(01) 95012345678903 (10) 000123 (17) 150801"代表以下信息:

GTIN:95012345678903批次/批次:000123使用期限或到期日期:2015 年 8 月 1 日

第 3 部分:

当条形码扫描仪读取这个符号时,它被解码如下[†]:

019501234567890310000123{GS}17150801

注意初始的 FNC1 非数据字符已被丢弃,变长 AI 分隔符角色中使用的 FNC1 已由 GS 字符(ASCII 值 29)表示.

提取(以及可选的验证)

GTIN 和任何补充信息的提取可以由您的应用程序直接执行.

要从条形码扫描仪解码的 GS1 符号数据中提取原始应用程序标识符数据,您的应用程序需要包含一个数据结构,我们将其称为 AI-TABLE 将 AI 模式映射到长度从上面链接的 GS1 通用规范部分中提供的数据得出的值:

AI |N(值长度)-------------------------(00) |18(01) |14(10) |多变的(17) |6(240) |多变的(310n) |6(37) |多变的...

有了这个,您可以从扫描的条码数据中提取 AI 值,如下所示:

而更多的数据:AI,N = AI-TABLE 中匹配数据前缀的条目,否则为 FAIL.如果 N 是固定长度:VALUE = 下 N 个字符否则 N 是可变长度:VALUE = 字符直到GS"或数据结束发出:(AI)值

在实践中,您可以选择在您的 AI-TABLE 中包含更多来自通用规范的数据,以允许您的应用程序对每个 VALUE 执行增强的验证类型和长度.但是,以上足以提取给定的数据,例如代表您要查找的到期日期的 AI (17).

查找

要获取您感兴趣的剩余数据(未直接编码在条形码中),例如商品名称和制造商详细信息,您需要使用外部资源(例如本地产品数据库或可用的公共 UPC 数据库 API.

GTIN 本身包含一个原产国(实际上它代表制造商注册的国家 GS1 成员组织,所以不完全是原产国)、制造商标识符——这些统称为 GS1 前缀,是可变的-length 和由 GS1 分配 - 其余数字表示由制造商自由分配的产品代码.

给定 GTIN,一些 UPC 数据库将仅提供与 GS1 前缀相关的详细信息,例如 GS1 成员组织和制造商的文本表示.其他人试图维护对常见项目的个人 GTIN 分配记录,但是由于没有强制注册实时 GTIN 分配,因此这些数据总是有些不完整和过时.

这个问题的答案提供了一些免费产品信息平台的示例.

[†] 事实上你可能会看到 ]C1019501234567890310000123{GS}17150801 在这种情况下,GS1-128 ]C1 的前导符号标识符可以被丢弃.

I am developing an app on Android Studio to get the expiry date of items upon scanning the barcode.

I don't want the user to install ZXing barcode app separately so I embedded the ZXing code into my project. Doing this I have been able to obtain the product identifier.

I also want to get product information such as the description, manufacturer and expiry date using the scanned barcode data. How can I do that?

解决方案

There are two processes involved in obtaining the information represented by a GS1-type barcode that stores data in GS1 Application Identifier Standard Format.

  1. Extraction of the data fields (referred to as Application Identifiers) contained within the GS1-structured data obtained by scanning the symbol. This always includes a unique identifier for the item called a GTIN-14 and may include supplementary information such as an expiry date, LOT number, etc. This process can be performed by a standalone application.
  2. Lookup of the extracted GTIN in a database, either local to your application or via some public API, to provide a textual representation of the country of origin, manufacturer and possibly the item description. To perform this process comprehensively an application requires access to external resources.

Background: GS1 Application Identifier Standard Format Composition

GS1-formatted data consists of a concatenated list of Application Identifiers (AIs) and values, beginning with AI (01) which represents the GTIN.

For example, the data "(01) 95012345678903 (10) 000123 (17) 150801" represents the following information:

GTIN:             95012345678903
BATCH/LOT:        000123
USE BY OR EXPIRY: 1st August 2015

Section 3: GS1 Application Identifier Definitions of the GS1 General Specifications provides the meaning of each of the Application Identifiers and importantly also states whether the AI values are by definition variable-length or fixed-length in which case the mandatory length is provided.

GS1 barcodes use a special non-data character (FNC1) both to indicate that the data conforms to GS1 Application Identifier standard format and to delimit the end of a variable-length data field from the next AI. For example, the above data could be encoded in a Code 128 symbol as {FNC1}019501234567890310000123{FNC1}17150801 to produce the following GS1-128 symbol:

When this symbol is read by a barcode scanner it is decoded as follows[†]:

019501234567890310000123{GS}17150801

Note that the initial FNC1 non-data character has been discarded and the FNC1 used in the variable-length AI separator role has been represented by a GS character (ASCII value 29).

Extraction (and optionally validation)

Extraction of the GTIN and any supplementary information can be performed directly by your application.

To extract the original Application Identifier data from the decoded GS1 symbol data from a barcode scanner requires that your application contains a data structure that we shall refer to as AI-TABLE mapping AI patterns to the length of their values as derived from the data provided in the section of the GS1 General Specifications linked to above:

AI     | N (value length)
-------------------------
(00)   | 18
(01)   | 14
(10)   | variable
(17)   | 6
(240)  | variable
(310n) | 6
(37)   | variable
...

With this available you can proceed with AI-value extraction from the scanned barcode data as follows:

while more data:
    AI,N = Entry from AI-TABLE matching a prefix of the data, otherwise FAIL.

    if N is fixed-length:
        VALUE = next N characters
    else N is variable length:
        VALUE = characters until "GS" or end of data

    emit: (AI) VALUE

In practise you may choose to include more of the data from the General Specifications in your AI-TABLE to permit your application to perform enhanced validation of each VALUE's type and length. However the above is sufficient to extract the given data, such as AI (17) representing the expiry date which you are looking for.

Lookup

To obtain the remaining data that you are interested in (which is not directly encoded in the barcode) such as the item's name and manufacturer details requires that you look up the extracted GTIN using external resources such as a local product database or one of the public UPC database APIs that are available.

The GTIN itself contains a country of origin (actually it represents the national GS1 Member Organisation with which the manufacturer is registered, so not quite country of origin), manufacturer identifier – together these are referred to as the GS1 Prefix, are variable-length and are assigned by GS1 – and the remainder of the digits represent the product code which is assigned freely by the manufacturer.

Given a GTIN, some UPC databases will provide only details relating to the GS1 Prefix such as a textual representation of the GS1 Member Organisation and the manufacturer. Others attempt to maintain a record of individual GTIN assignments to common items, however this data will always be somewhat incomplete and out of date as there is no mandatory registry of real time GTIN assignments.

The answers to this question provide some examples of free product information platforms.

[†] In fact you might see ]C1019501234567890310000123{GS}17150801 in which case the leading symbology identifier for GS1-128 ]C1 can be discarded.

这篇关于从扫描的 GS1 类型条码中提取信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆