GRAI¶
- class epc.schemes.GRAI(*args, **kwargs)¶
The Global Returnable Asset Identifier EPC scheme is used to assign a unique identity to a specific returnable asset, such as a reusable shipping container or a pallet skid.
General syntax: urn:epc:id:grai:CompanyPrefix.AssetType.SerialNumber
Example: urn:epc:id:grai:0614141.12345.400
- filter(tag_filter)¶
The filter value is additional control information that may be included in the EPC memory bank of a Gen 2 tag. The intended use of the filter value is to allow an RFID reader to select or deselect the tags corresponding to certain physical objects, to make it easier to read the desired tags in an environment where there may be other tags present in the environment. For example, if the goal is to read the single tag on a pallet, and it is expected that there may be hundreds or thousands of item-level tags present, the performance of the capturing application may be improved by using the Gen 2 air interface to select the pallet tag and deselect the item-level tags.
Allowed values for GRAI tags:
Value
Constant
Description
0
FILTER_ALL
All Others
1-7
FILTER_RESERVED_*
Reserved
- Parameters
tag_filter (int) – The filter value, defaults to
FILTER_ALL
.- Raises
AttributeError – Filter must be between 0 and 7.
- Returns
The GRAI tag object.
- Return type
- company_prefix(company_prefix, company_prefix_length=None)¶
The GS1 Company Prefix, assigned by GS1 to a managing entity.
Length corresponds to the number of digits in the company prefix.
- Parameters
company_prefix (str, int) – GS1 company prefix.
company_prefix_length (int, optional) – Number of digits in the company prefix. Required when
company_prefix
is an int.
- Returns
The GRAI tag object.
- Return type
- asset_type(asset_type)¶
The Asset Type, assigned by the managing entity to a particular class of asset.
- Parameters
asset_type (int, str) – The asset type.
- Raises
ValueError – Unable to convert input to an integer.
- Returns
The GRAI tag object.
- Return type
- serial_number(serial_number)¶
The Serial Number, assigned by the managing entity to an individual object. Because an EPC always refers to a specific physical object rather than an asset class, the serial number is mandatory in the GRAI-EPC.
- Parameters
serial_number (str, int) – The serial number.
- Raises
AttributeError – Serial number bit length incorrect.
AttributeError – Serial number length incorrect.
- Returns
The GRAI tag object.
- Return type
- tag_size()¶
Set the size for the tag. Options are
SIZE_96
orSIZE_170
.- Parameters
tag_size (int) – Tag size in bits. Defaults to
SIZE_96
.- Raises
AttributeError – Invalid tag size specified.
- Returns
The GRAI tag object.
- Return type
- property tag_uri¶
- Returns
The tag’s URI.
- Return type
str
- property pure_identity_uri¶
- Returns
The tag’s pure identity URI.
- Return type
str
- property barcode¶
- Returns
The barcode representation of the tag.
- Return type
str
- property barcode_humanized¶
- Returns
A human readable barcode representation of the tag.
- Return type
str
- property values¶
- Returns
Dictionary containing:
size
(int): the tag’s size in bitsfilter
(int)company_prefix
(str)asset_type
(int)serial_number
(int or str)
- decode_epc(hex_string)¶
Decode an encoded tag and populate this object’s values from it.
- Parameters
hex_string (str) – Tag data encoded as a hexadecimal string.
- Raises
ValueError – EPC scheme header does not match input.
ValueError – Filter does not match allowed values.
ValueError – Supplied
hex_string
bit length invalid.
- decode_barcode(barcode, company_prefix_length)¶
Decode a barcode and populate this object’s values from it.
- Parameters
hex_string (str) – Barcode
company_prefix_length (int) – Number of digits of the company prefix length
- Raises
ValueError – Expected barcode header does not match input.
AttributeError – Invalid barcode length, or wrong company prefix.
- check_fields()¶
Checks to make sure all components of the tag are present, including
size
,filter
,company_prefix
,asset_type
andserial_number
.- Raises
AttributeError – If any components of the tag are missing.
Hint
To get the encoded tag data, use python’s built in conversion methods:
>>> tag = GRAI().tag_size(GRAI.SIZE_170)
>>> tag.company_prefix('000123').asset_type(8).serial_number('ABC')
# Hexadecimal
>>> hex(tag)
'0x3718001ec0000220c286000000000000000000000000'
# Binary
>>> bin(tag)
'0b110111000110000000000000011110110000000000000000000010001000001100001010000110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
Constants¶
Filters
- GRAI.FILTER_ALL¶
- GRAI.FILTER_RESERVED_*
Replace asterisk with 1-7.
Sizes
- GRAI.SIZE_96¶
96 bit tag size.
- GRAI.SIZE_170¶
170 bit tag size.
Headers
- GRAI.HEADER_BARCODE¶
GS1 specified barcode header:
8003
.
- GRAI.HEADER_96¶
GS1 specified hexadecimal header for 96 bit GRAI tags:
0x33
.
- GRAI.HEADER_170¶
GS1 specified hexadecimal header for 202 bit GRAI tags:
0x37
.
- GRAI.GRAI_96¶
Human readable GS1 specified header for 96 bit GRAI tags:
grai-96
.
- GRAI.GRAI_170¶
Human readable GS1 specified header for 202 bit GRAI tags:
grai-170
.