Client / Gateway Scripts-BarcodeScanner

Sepasoft MES Module Suite

Client and Gateway Scripts for Barcode Scanner

The functionality of the BarcodeScanner component is also available for gateway and client scripting. The following methods can be utilized in a gateway script to create regular expressions (regex) patterns and decode a barcode by searching the raw barcode for the list of patterns. The results of the barcode decoding can then be used by in the gateway script.

In the Ignition script editor, documentation for the script functions can be accessed by pressing control-space after typing in 'system.'. For all the track and trace script functions, type in system.barcode. and press control-space to see the associated function and documentation.

Ignition Script Auto Document Feature

Barcode decoding uses Regex patterns to decode raw barcode data. The Barcode Scanner Module is pre-configured with a set of 100- patterns to include common and GS1 Application Identifier standards. If the default patterns do not fit the required needs, then custom patterns can be defined. Below is the list of  predefined patterns:

NAME      KEYREGEX PATTERN
Default      Default  "(.*)"
GTIN-14  GTIN-14   "^(\\d{14})$
GTIN-12 UPCGTIN-12   "^(\\d{12})$
GTIN-13 EAN  GTIN-13      "^(\\d{13})$
GTIN-8 EAN  GTIN-8"^(\\d{8})$
SSCC  GS1-00"(00)(\\d{18})"
GTINGS1-01 "(01)(\\d{14})"
CONTENTGS1-02"(02)(\\d{14})"
BATCH/LOT   GS1-10  "(10)(\\d{1,20}" - separator - "|\\d{1,20}$)"
PROD DATE   GS1-11 "(11)(\\d{6})"
DUE DATEGS1-12 "(12)(\\d{6})"
PACK DATEGS1-13"(13)(\\d{6})"
BEST BY GS1-15 "(15)(\\d{6})"      
SELL BY   GS1-16"(16)(\\d{6})"
USE BYGS1-17 "(17)(\\d{6})"
VARIANT GS1-20  "(20)(\\d{2})"
SERIALGS1-21"(21)(.{1,20}" - separator - "|.{1,20}$)"
ADDITIONAL IDGS1-240    "(240)(.{1,30}" - separator - "|.{1,30}$)"
CUST.PART NO.GS1-241"(241)(.{1,30}" - separator - "|.{1,30}$)"
MTO VARIANTGS1-242   "(242)(\\d{1,6}" - separator - "|\\d{1,6}$)"
PCN  GS1-243    "(243)(.{1,20}" - separator - "|.{1,20}$)"
SECONDARY SERIALGS1-250  "(250)(.{1,30}" - separator - "|.{1,30}$)"
REF. TO SOURCEGS1-251"(251)(.{1,30}" - separator - "|.{1,30}$)"
GDTI GS1-253 "(253)(\\d{13}.{1,17}" - separator - "|\\d{13}.{1,17}$)"
GLN EXTENSIION COMPGS1-254"(254)(.{1,20}" - separator - "|.{1,20}$)"
GCN   GS1-255"(255)(\\d{13}\\d{1,12}" - separator - "|\\d{13}\\d{1,12}$)"
VAR. COUNTGS1-30"(30)(\\d{1,8}" - separator - "|\\d{1,8}$)"
NET WEIGHT (kg) GS1-310 "(310)([0-6]{1})(\\d{6})"
LENGTH (m)   GS1-311 "(311)([0-6]{1})(\\d{6})"
WIDTH (m)  GS1-312"(312)([0-6]{1})(\\d{6})"
HEIGHT (m) GS1-313 "(313)([0-6]{1})(\\d{6})"
AREA (m²)  GS1-314 "(314)([0-6]{1})(\\d{6})"
NET VOLUME (l)GS1-315   "(315)([0-6]{1})(\\d{6})"
NET VOLUME (m³)GS1-316  "(316)([0-6]{1})(\\d{6})"
NET WEIGHT (lb) GS1-320   "(320)([0-6]{1})(\\d{6})"
LENGTH (i) GS1-321"(321)([0-6]{1})(\\d{6})"
LENGTH (f)GS1-322  "(322)([0-6]{1})(\\d{6})"
LENGTH (y)  GS1-323 "(323)([0-6]{1})(\\d{6})"
WIDTH (i)    GS1-324   "(324)([0-6]{1})(\\d{6})"
WIDTH (f) GS1-325 "(325)([0-6]{1})(\\d{6})"
WIDTH (y)  GS1-326    "(326)([0-6]{1})(\\d{6})"
HEIGHT (i)GS1-327"(327)([0-6]{1})(\\d{6})"
HEIGHT (f)GS1-328    "(328)([0-6]{1})(\\d{6})"
HEIGHT (y)GS1-329"(329)([0-6]{1})(\\d{6})"
GROSS WEIGHT (kg)GS1-330  "(330)([0-6]{1})(\\d{6})"
LENGTH (m),log  GS1-331"(331)([0-6]{1})(\\d{6})"
WIDTH (m),log GS1-332 "(332)([0-6]{1})(\\d{6})"
HEIGHT (m),log GS1-333"(333)([0-6]{1})(\\d{6})"
AREA (m²),log   GS1-334 "(334)([0-6]{1})(\\d{6})"
VOLUME (l),log  GS1-335  "(335)([0-6]{1})(\\d{6})"
VOLUME (m³),log  GS1-336"(336)([0-6]{1})(\\d{6})"
KG PER m² GS1-337"(337)([0-6]{1})(\\d{6})"
GROSS WEIGHT (lb) GS1-340 "(340)([0-6]{1})(\\d{6})"
LENGTH (i),log GS1-341   "(341)([0-6]{1})(\\d{6})"
LENGTH (f),log  GS1-342  "(342)([0-6]{1})(\\d{6})"
LENGTH (y),log GS1-343 "(343)([0-6]{1})(\\d{6})"
WIDTH (i),log  GS1-344  "(344)([0-6]{1})(\\d{6})"
WIDTH (f),log GS1-345 "(345)([0-6]{1})(\\d{6})"
WIDTH (y),log GS1-346"(346)([0-6]{1})(\\d{6})"
HEIGHT (i),log GS1-347 "(347)([0-6]{1})(\\d{6})"
HEIGHT (f),logGS1-348   "(348)([0-6]{1})(\\d{6})"
HEIGHT (y),logGS1-349  "(349)([0-6]{1})(\\d{6})"
AREA (i²) GS1-350  "(350)([0-6]{1})(\\d{6})"
AREA (f²)GS1-351"(351)([0-6]{1})(\\d{6})"
AREA (y²) GS1-352"(352)([0-6]{1})(\\d{6})"
AREA (i²),log GS1-353"(353)([0-6]{1})(\\d{6})"
AREA (f²),log GS1-354"(354)([0-6]{1})(\\d{6})"
AREA (y²),log   GS1-355"(355)([0-6]{1})(\\d{6})"
NET WEIGHT (t)GS1-356 "(356)([0-6]{1})(\\d{6})"
NET VOLUME (oz) GS1-357"(357)([0-6]{1})(\\d{6})"
NET VOLUME (q) GS1-360 "(360)([0-6]{1})(\\d{6})"
NET VOLUME (g)GS1-361 "(361)([0-6]{1})(\\d{6})"
VOLUME (q),log GS1-362    "(362)([0-6]{1})(\\d{6})"
VOLUME (g),logGS1-363"(363)([0-6]{1})(\\d{6})"
VOLUME (i³) GS1-364 "(364)([0-6]{1})(\\d{6})"
VOLUME (f³)   GS1-365 "(365)([0-6]{1})(\\d{6})"
VOLUME (y³)GS1-366"(366)([0-6]{1})(\\d{6})"
VOLUME (i³),log  GS1-367"(367)([0-6]{1})(\\d{6})"
VOLUME (f³),log GS1-368 "(368)([0-6]{1})(\\d{6})"
VOLUME (y³),log  GS1-369"(369)([0-6]{1})(\\d{6})  
COUNTGS1-37"(37)(\\d{1,8}" - separator - "|\\d{1,8}$)"
AMOUNT GS1-390"(390)([0-9]{1})(\\d{1,15}" - separator - "|\\d{1,15}$)"
AMOUNTGS1-391"(391)([0-9]{1})(\\d{3})(\\d{1,18}" - separator - "|\\d{1,18}$)"
PRICE GS1-392  "(392)([0-9]{1})(\\d{1,15}" - separator - "|\\d{1,15}$)"
PRICE    GS1-393    "(393)([0-9]{1})(\\d{3})(\\d{1,18}" - separator - "|\\d{1,18}$)"
ORDER NUMBER  GS1-400  "(400)(.{1,30}" - separator - "|.{1,30}$)"
GINC    GS1-401    "(401)(.{1,30}" - separator - "|.{1,30}$)"
GSIN      GS1-402"(402)(\\d{17}" - separator - "|\\d{17}$)"
ROUTE      GS1-403"(403)(.{1,30}" - separator - "|.{1,30}$)"
SHIP TO LOCGS1-410 "(410)(\\d{13})"
BILL TO GS1-411  "(411)(\\d{13})"
PURCHASE FROMGS1-412"(412)(\\d{13})"
SHIP FOR LOC GS1-413 "(413)(\\d{13})"
LOC No  GS1-414"(414)(\\d{13})"
PAY TO GS1-415 "(415)(\\d{13})"
SHIP TO POSTGS1-420"(420)(.{1,20}" - separator - "|.{1,20}$)"
SHIP TO POST  GS1-421"(421)(\\d{3})(.{1,20}" - separator - "|.{1,20}$)"
ORIGINGS1-422"(422)(\\d{3})"
COUNTRY - INIT PROCESSGS1-423"(423)(\\d{3})(\\d{3,12}" - separator - "|\\d{3,12}$)"
COUNTRY - PROCESS GS1-424 "(424)(\\d{3})"
COUNTRY - DISASSEMBLY  GS1-425  "(425)(\\d{3})"
COUNTRY - FULL PROCESSGS1-426"(426)(\\d{3})"
ORIGIN SUBDIVISIONGS1-427"(427)(.{1,3}" - separator - "|.{1,3}$)"

Sample Gateway Tag Change Scripts

Example 1
Python
# Gateway Tag Change Script to decode a UPC, EAN, GTIN barcode

# Setup the logger to see activity on the Ignition Gateway console
# or just use print statements and look at wrapper.log file.
from org.apache.log4j import Logger
log = Logger.getLogger('GTINDecoder')
 
# Import java needed classes
from java.util import List
 
# Only execute if not initializing and tag value is not null
if (initialChange == 0 and newValue.value != None):
 # Get rawBarcode from tag value
 rawBarcode = newValue.value        
 
 # Get only the predefined regex patterns for GTIN-12 UPC, GTIN-13 EAN, & GTIN-14
 patterns = system.barcode.scanner.getPatternList("GTIN-12,GTIN-13,GTIN-14", "")
 
 # Call the decode method for a single pass search with a preamble of \u0002 ascii STX (start of text),
 # and no postamble, or separator in barcode
 results = system.barcode.scanner.decode(rawBarcode, "SinglePass", patterns, u"\u0002", "", "")
 
 if (results.hasErrorMessage()):
         # Log error message
         log.info("Error from barcode scan: " + results.getErrorMessage())
 else:
         # Get a Python dictionary of the decoding results
         resultsDict = results.toDict()
 
         # Loop through results        
         for key,value in resultsDict.items():
                 log.info("Key: " + key + ", Value: " + value.toString())


Example 2
Python
# Gateway Tag Change Script to decode a GS1 Active Matrix barcode
 
# Setup the logger to see activity on the Ignition Gateway console
# or just use print statements and look at wrapper.log file.
from org.apache.log4j import Logger
log = Logger.getLogger('GS1Decoder')
 
# Import java needed classes
from java.util import List
 
# Only execute if not initializing and tag value is not null
if (initialChange == 0 and newValue.value != None):
 # Get rawBarcode from tag value
 rawBarcode = newValue.value        
 
 # Get the predefined regex patterns for GS1 Application Identifer (AI) we are interested in, The FNC1
 # separator for the variable length AIs is Unicode \u001d and will be inserted into the patterns.
 patterns = system.barcode.scanner.getPatternList("GS1-10,GS1-17,GS1-01,GS1-390,GS1-310", u"\u001d")           
 
 #Uncomment to see patterns in list
 #for p in patterns:
         #log.info("key=%s regex=%s" %(p.getKey(), p.getRegexPattern()))
 
 # Call the decode method for a GS1 consume search with a preamble of ]d1,  
 # and postamble of \u001a (LF line feed), and separator of \u001d (GS Group Separator for FNC1) in barcode
 results = system.barcode.scanner.decode(rawBarcode, "Consume", patterns, u"]d1", u"\u001a", u"\u000d")
 
 if (results.hasErrorMessage()):
         # Log error message
         log.info("Error from barcode scan: " + results.getErrorMessage())
 if (results.hasUnmatched()):
         # Log unmatched
         log.info("Unmatched: " + results.getUnmatched())
 
 # Get a Python dictionary of the decoding results
 resultsDict = results.toDict()
 
 # Loop through results        
 for key,value in resultsDict.items():
         log.info("Key: " + key + ", Value: " + value.toString())

Example 3
Python
# Gateway Tag Change Script to decode a custom regex pattern
 
# Setup the logger to see activity on the Ignition Gateway console
# or just use print statements and look at wrapper.log file.
from org.apache.log4j import Logger
log = Logger.getLogger('CustomDecoder')
 
# Import java needed classes
from java.util import List
 
# Only execute if not initializing and tag value is not null
if (initialChange == 0 and newValue.value != None):
 # Get rawBarcode from tag value
 rawBarcode = newValue.value        
 
 # Create a new empty patterns list
 patterns = []
 
 # Create customer barcode pattern and add to list
 pattern = system.barcode.scanner.getNewBarcodePattern("My Pattern Name", "MyPatternKey", u"^(\d{8})$")
 patterns.append(pattern)
 
 # Call the decode method for a single pass search with no preamble, postamble, or separator in barcode
 results = system.barcode.scanner.decode(rawBarcode, "SinglePass", patterns, "", "", "")
 
 if (results.hasErrorMessage()):
         # Log error message
         log.info("Error from barcode scan: " + results.getErrorMessage())
 
 # Get a Python dictionary of the decoding results
 resultDict = results.toDict()
 
 # Loop through results        
 for key,value in resultDict.items():
         log.info("Key: " + key + ", Value: " + value.toString())

                                                                                                                                                                                                                             


Sepasoft MES Module Suite