Yeah, probably so. Thank you for all the help though
The regexes are looking for separators that don’t seem to exist in your QR.
Try using the string method.
result = event.toDict()
fieldDelimiterList = ['(GS1-241)','(GS1-10)','(GS1-37)']
parsedData = parseString(result['Default'][0] , fieldDelimiterList)
Your original code seemed to be the what you needed, here is another example I found from sepasoft that you probably already had, but this is probably the best
Sample #1 onBarcodeReceived event script:
#Sample Use of the Python Dictionary method to get barcode values from a single-pass #decode method
results = event.toDict() # converts Java hashtable to Python dictionary
#Sample method to print out all result values
for key, value in results.items():
print(key, value)
#Look for an error message and display it to text box
if event.hasErrorMessage():
event.source.parent.getComponent('txtError').text = event.getErrorMessage()
system.util.beep()
else:
#Update screen components from decode results
if 'GS1-241' in results:
event.source.parent.getComponent('txtPartNumber').text = results['GS1-241'][0]
if 'GS1-10' in results:
event.source.parent.getComponent('txtLotNumber').text = results['GS1-10'][0]
if 'GS1-37' in results:
event.source.parent.getComponent('numQty').int = results['GS1-37'][0]
I tried this and now instead of an error popping up, I get an error in the textError box that says 'No matching patterns were found in the raw barcode'
With this I get a KeyError: Default
Is Default enabled in the Pattern configuration?
It wasn’t selected anymore but I went back and selected and no still get the same error.
Did you save the project after the change?
This is the script I am using:
def parseString(stringIn, delimiters):
########################################################
## ##
## parse a delimited string and return a dictionary ##
## ##
## NOTE: Be sure the delimiter list is in the same ##
## order as they appear in the string. Save ##
## yourself some pain. :) ##
## ##
########################################################
# Create a list of lists that contains the indexes of where each delimiter appears,
# and the length of the delimiter, so we can use them to say where each field data lies.
indexList = [[stringIn.index(delimiter), len(delimiter)] for delimiter in delimiters]
# This is just a pointer that we'll use later to flag when the last iteration of the
# following loop is in play.
last = len(indexList) - 1
# Initialize the output dictionary.
dictOut = {}
# populate the output dictionary with the field data
for index, delimiter in zip(range(len(indexList)), delimiters):
# set the start of each field data
start = indexList[index][0] + indexList[index][1]
# set the end of the field data. This is treated differently if it
# is the last iteration.
if index != last:
end = indexList[index + 1][0]
else:
end = len(stringIn)
# Add to the output dictionary
dictOut[delimiter] = stringIn[start:end]
return dictOut
result = event.toDict()
print '--- result ---'
print result
print '--------------'
print
fieldDelimiterList = ['(GS1-241)','(GS1-10)','(GS1-37)']
parsedData = parseString(result['Default'][0], fieldDelimiterList)
print '--- parsedData ---'
print parsedData
print '--------------'
This is what I have in my console:
So apparently there was an issue with the scanner I was using. Once I got a new one and set the prefix, this worked.
I want to thank you both for all your help. Between code and bad hardware, it made it tougher than I thought it would be.