Barcode Scan Event Triggered by External Scanner

Hi all,

I have a perspective app that relies on barcode scanning events to pass data throughout itself. I am currently using barcode session events to handle the incoming data as follows.

	if context['event'] == 'scan':
		# clicked to scan any barcode
		if context['barcode_type'] == 'any':"sending scannedBarcode message with payload: %s"%data['text'])
			res = system.perspective.sendMessage('scannedBarcode', payload={'data': data['text']}, scope='session')

All buttons that trigger a scan event listen to the corresponding message, and call a script in the project library to the handle the data accordingly.

It has been requested that I find a way to implement a bluetooth scanner in order to avoid having to use the built in cameras on tablets running perspective. Through some quick tests, the bluetooth scanners seem to operate by sending keystrokes (text) back to the paired device.

My current solution would be to add a toggle button to handle the scan events either with the tablet and eventHandlers as is currently working, or let the operator select to use a hand scanner. The hand scanner would likely have to override the scan events and just write text back to where it belongs in memory. This seems doable but a bit messy.

Long story short, does anyone have a cleaner way to have external cameras/scanners report back to the scan event from the built-in camera?

It seems that all you would need to do is add a barcode scanner input component and in the onActionPerformed event, send the message.

# get last barcode scan
data =[-1]
res = system.perspective.sendMessage('scannedBarcode', payload={'data': data}, scope='session')

Press scan event button to use the camera, or use the external scanner to scan a barcode, which will trigger your sendMessage script on each read. That way, if the bluetooth stops working, press your button and use the camera.

If you do this a lot, I recommend using handhelds with built-in scanning engines. So much better than trying to use Bluetooth scanners. We use the CipherLab RS36s with really good results. They aren't tablet sized, but you can find them online.

Not really sure how I missed triggering an sendMessage on data read from the scanner.. Seems like a pretty straightforward way of doing it. I'll likely make a variable with a change script that sends out the message it needs to. Thanks!

1 Like