def OnScan(self, event): """ OMR form timing marks and their meaning: Col. # Value ----------------- 1 Category labels 2 Category mark 3 Blank line 4 Position labels 5 Polition mark 6 Row labels 7-34 Pairwise comparison votes A total of 69 bytes are sent in a stream; the last is '\r' for end of record """ # scanner row translations DATA_MAP_BLANK = { chr(32)+chr(32): 0 } DATA_MAP_2 = { chr(32)+chr(36): 'nat', chr(96)+chr(32): 'eco', chr(36)+chr(32): 'soc' } DATA_MAP_5 = { chr(32)+chr(36): 'pro', chr(96)+chr(32): 'neu', chr(36)+chr(32): 'con' } DATA_MAP_7 = { chr(32)+chr(16): 1.000, chr(32)+chr(8): 2.000, chr(32)+chr(4): 3.000, chr(32)+chr(2): 4.000, chr(32)+chr(1): 5.000, chr(64)+chr(32): 6.000, chr(16)+chr(32): 7.000, chr(8)+chr(32): 8.000, chr(4)+chr(32): 9.000, chr(34)+chr(8): 0.500, chr(34)+chr(4): 0.333, chr(34)+chr(2): 0.025, chr(34)+chr(1): 0.200, chr(66)+chr(32): 0.167, chr(18)+chr(32): 0.143, chr(10)+chr(32): 0.125, chr(6)+chr(32): 0.111 } # Open serial port ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1) ser.open() if ser.isOpen() != True: serial.SerialException searchString = '\r' # end of card read vote_id = 0 # card number incremented at start of read loop newStart = 0 # only > 0 if the run is aborted by the operator progressMax = 500 omrDialog = wx.ProgressDialog("Scoping Form Input", "Processing ...", progressMax, style=wx.PD_CAN_ABORT | wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME) keepGoing = True while True: vote_id += 1 # vote record number; heads list row & displayed for entry on form if newStart > 0: # read was aborted (card mis-read? jammed?) and restarted vote_id = newStart omrDialog.Resume() # read the line sent by the OMR reader; record end is '\r'. line = ser.readline # get all 69 bytes in one chunk """ if value == DATA_MAP_BLANK: # skip line if blank or labels continue if value == searchString: # we're done with that form vrecord[:-1] # slice off the terminal comma vrecord.append('\n') # add a newline break vrecord.extend([line, ", "]) # add the pairwise comparison value, a comma, and a space Now I need to add that vote record to an array, and start a new row """ while keepGoing and vote_id < progressMax: # increment progress dialog if keepGoing == False: newStart = vote_id break keepGoing = omrDialog.Update(vote_id) # close the dialog box and serial port omrDialog.Destroy() ser.Close()