Barcode Data Handling Script - stopped working

I was using the Barcode Data Handling Script, to scan the barcode with the cellphone camera.
I don't know for sure when stopped working. I didn't change anything in my code, the only thing I did recently is update to the 8.1.24 version.

I'm using the Ignition perspective on the phone too.

My example code:

def onBarcodeDataReceived(session, data, context):
	Consult.ConsultMaterials.scanCam(data.text)
def scanCam(vCamSerial):
	system.tag.writeAsync('[default]Writable/scantest', "xx") #Using only to test

	system.perspective.sendMessage(
	'getBarcodeScanned'
	,payload = {
			 'vSession':123
			,'vLabelScanned':vCamSerial
				}
	,scope="session"
	)

Script in a Label:

def onMessageReceived(self, payload):
	
	#getBarcodeScanned
	vSession = payload['vSession']
	vLabelScanned = payload['vLabelScanned']
	
	self.props.text = vLabelScanned

What version were you using before the upgrade? Are you seeing any errors in your gateway logs? I'm curious to see if one of the scripts is now failing, or if the scan is just not occurring at all.

Also, this line is doing nothing in your code:

self.parent.parent.parent.getChild("FlexSearch").getChild("ltTitleFlexProdInfo").props.text

I recommend removing it.

In my program, the line was commented #. I will remove it from my example.

I didn't receive any error, the application in the cell phone open the camera, and when I scanned the barcode, looks like works, but didn't return any information after scanning (data.text).
The last version it was working is 8.1.16.

Screen_Recording_20230120_160200_Ignition Perspective_1

Can you please share details about the device you're using - model, OS, OS version, and the Perspective app version?

2 Likes

This is happening for any OS cellphones Android or iPhone.
I already tried in both OS.
I'm using right now Samsung S22 Ultra (SM-S908W) S908WVLUBVKI (android 13)
Ignition perspective App version 1.0.5.1 updated Jan 13, 2023.

Ok, so it's likely not device related. For your message handler on the label, can you check to make sure the "Session" listen scope is selected?

Also, to check to see if the event is making it to the gateway, can you set the perspective.ClientSession event to TRACE. (Status->Logs->Gear icon). After scanning a barcode, you should get a message like "Mobile data received by mobile data eventBus with value MobileDataSubmissionEvent..."

I don't know if this helps, but I get the log on the Perspective app below.

Blockquote
DEBUG/2023-01-23 16:13:32 g4: Action created: native/barcode, Config(type=ANY, uuid=af93bd83-3185-4a97-a290-53b849839644, cameraPreference=BACK, backgroundColor=AUTO), context: {}
DEBUG/2023-01-23 16:13:32 BarcodeScannerActivity: Using Legacy barcode scanner.
INFO/2023-01-23 16:13:32 r0$r: openCamera onSurfaceTextureAvailable
ERROR/2023-01-23 16:13:32 r0$b: Couldn't find any suitable preview size
ERROR/2023-01-23 16:13:32 r0: Lock acquired openCamera
WARN/2023-01-23 16:13:32 r0: Camera switching was not able to complete
DEBUG/2023-01-23 16:13:32 PerspectiveClientImpl: WebViewClient Error: Http(forceDisplay=false, message=Code 403: Forbidden
ERROR/2023-01-23 16:13:32 r0$h: Lock released onOpened
DEBUG/2023-01-23 16:13:36 a1: VisionBarcode: TB1223154JJ
ERROR/2023-01-23 16:13:36 r0$h: Lock released onClosed

The log TRACE as you suggested.

Blockquote
|ClientSession|23Jan2023 16:19:54|Keepalive. page=19db5e48, roundtrip=2|
|---|---|---|
|ClientSession|23Jan2023 16:19:50|Keepalive. page=271e3a2, roundtrip=147|
|ClientSession|23Jan2023 16:19:49|Skipping keepalive message, channel not connected.|
|ClientSession|23Jan2023 16:19:49|Skipping keepalive message, channel not connected.|
|ClientSession|23Jan2023 16:19:49|Skipping keepalive message, channel not connected.|
|ClientSession|23Jan2023 16:19:46|Keepalive. page=3aaacdf6, roundtrip=9544|
|ClientSession|23Jan2023 16:19:46|Keepalive. page=3aaacdf6, roundtrip=39543|
|ClientSession|23Jan2023 16:19:24|Keepalive. page=19db5e48, roundtrip=2|
|Sync|23Jan2023 16:19:21|Sending sync 3 receipt|
|Sync|23Jan2023 16:19:21|Processed prop sync 3|
|ClientSession|23Jan2023 16:19:21|Received message. payload='PropertySyncMsg'|
|ClientSession|23Jan2023 16:19:21|Received message. payload='ClientActivityMsg'|
|ClientSession|23Jan2023 16:19:21|Received message. payload='ClientActivityMsg'|
|ClientSession|23Jan2023 16:19:21|Received message. payload='ClientActivityMsg'|
|ClientSession|23Jan2023 16:19:20|Keepalive. page=271e3a2, roundtrip=136|
|ClientSession|23Jan2023 16:19:19|Skipping keepalive message, channel not connected.|
|ClientSession|23Jan2023 16:19:19|Skipping keepalive message, channel not connected.|
|ClientSession|23Jan2023 16:19:19|Skipping keepalive message, channel not connected.|
|ClientSession|23Jan2023 16:19:19|Received message. payload='ClientActivityMsg'|
|ClientSession|23Jan2023 16:19:18|View 'Consult/ConsultMaterials@C' starting...|
|ClientSession|23Jan2023 16:19:18|Received message. payload='ViewStartMsg'|
|Sync|23Jan2023 16:19:18|Sending sync 2 receipt|
|Sync|23Jan2023 16:19:18|Processed prop sync 2|
|ClientSession|23Jan2023 16:19:18|Received message. payload='PropertySyncMsg'|
|ClientSession|23Jan2023 16:19:18|View 'MenuProjects@C' stopping...|
|ClientSession|23Jan2023 16:19:18|Received message. payload='ViewStopMsg'|
|ClientSession|23Jan2023 16:19:18|Received message. payload='ClientActivityMsg'|
|ClientSession|23Jan2023 16:19:18|Received message. payload='ClientActivityMsg'|
|ClientSession|23Jan2023 16:19:18|Received message. payload='ClientActivityMsg'|
|Sync|23Jan2023 16:19:17|Sending sync 1 receipt|
|Sync|23Jan2023 16:19:17|Processed prop sync 1|
|ClientSession|23Jan2023 16:19:17|Received message. payload='PropertySyncMsg'|
|Sync|23Jan2023 16:19:17|Sending sync 0 receipt|
|ClientSession|23Jan2023 16:19:17|View 'MenuProjects@C' starting...|
|ClientSession|23Jan2023 16:19:17|Received message. payload='ViewStartMsg'|
|ClientSession|23Jan2023 16:19:17|Received message. payload='WriteSpecialMsg'|
|ClientSession|23Jan2023 16:19:17|Received message. payload='WriteSpecialMsg'|
|ClientSession|23Jan2023 16:19:17|Received message. payload='WriteSpecialMsg'|
|Sync|23Jan2023 16:19:17|Processed prop sync 0|
|ClientSession|23Jan2023 16:19:17|Received message. payload='PropertySyncMsg'|
|ClientSession|23Jan2023 16:19:16|Received message. payload='WriteSpecialMsg'|
|ClientSession|23Jan2023 16:19:16|Received message. payload='WriteSpecialMsg'|
|ClientSession|23Jan2023 16:19:16|Client Starting. Project='FocusSystem'.|
|ClientSession|23Jan2023 16:19:16|Received message. payload='ClientStartMsg'|
|ClientSession|23Jan2023 16:19:16|Socket connected to session. pageId=271e3a2|
|ClientSession|23Jan2023 16:19:16|Removing access token '(websocket,YUfD-tctYcbJ6r9tF7YRgPsC0_hV0Bx9g3YQl20jbUA)=null' from cache: EXPLICIT|
|Routes|23Jan2023 16:19:16|Encoded Message = AAAAEAhAe5-VCtDXQLQUBStNps3h9-Q5WfOmkBbkU7YW8aV2rz552M4DDc6jEuY5H_7anQU2pu5rmSaRqDttf2ft-Vs=|

DEBUG/2023-01-23 16:13:32 PerspectiveClientImpl: WebViewClient Error: Http(forceDisplay=false, message=Code 403: Forbidden

I believe this error can happen if you don't have the "Session" listen scope checkbox selected on the message handler, which might be the problem. Can you double-check that?

It is checked.
Below is the Message Handler

Code:

def onMessageReceived(self, payload):
	#getBarcodeScanned
	vSession = payload['vSession']
	vLabelScanned = payload['vLabelScanned']

	self.props.text = vLabelScanned
	self.getSibling("tfConsLabelScan").props.text = vLabelScanned
	Consult.ConsultMaterials.ConsultMaterial(self,vLabelScanned)

Below is the Session event

Code:
*system.tag.writeAsync I used as a test

def onBarcodeDataReceived(session, data, context):
	Consult.ConsultMaterials.scanCam([data.text])
	system.tag.writeAsync(['[default]Writable/scantest'], [data.text])

Below is the scanCam (system.perspective.sendMessage) code:

def scanCam(vCamSerial):
	system.perspective.sendMessage(
	'getBarcodeScanned'
	,payload = {
			 'vSession':123
			,'vLabelScanned':vCamSerial
				}
	,scope="session"
	)

Maybe the error is not related to my code, because the program just stopped working alone.

What about this error that shows on the log in the Perspective app?

ERROR/2023-01-23 16:13:32 r0$b: Couldn't find any suitable preview size
ERROR/2023-01-23 16:13:32 r0: Lock acquired openCamera
WARN/2023-01-23 16:13:32 r0: Camera switching was not able to complete
DEBUG/2023-01-23 16:13:32 PerspectiveClientImpl: WebViewClient Error: Http(forceDisplay=false, message=Code 403: Forbidden

At this line, the camera gets the value as I scanned (TB1223154JJ).

DEBUG/2023-01-23 16:13:36 a1: VisionBarcode: TB1223154JJ

I looked a bit further and I believe the 2 errors and warn in the application log are related to the legacy barcode scanner. It should not make a difference. So, we know the camera is getting the barcode. If the tag is being updated, then maybe the problem lies with your Consult.ConsultMaterials code. Maybe try removing that as a test -- in the Barcode Data Handling Script, just call system.perspective.sendMessage and reference the message handler on the text/label. That's what I did and it works great. Otherwise, I think I'm out of ideas and you'll need to contact Support.

I tried but still not working.
I did something simple like write the information in a tag and still not working.

def onBarcodeDataReceived(session, data, context):
	system.tag.writeAsync(['[default]Writable/test1'], 'xxxxx')

Has that ever worked? It might be beneficial to start with a new project, and follow the steps as outlined in Perspective Session Event Scripts - Ignition User Manual 8.1 - Ignition Documentation and see where that gets you.

1 Like

I started over as a new project and looks like works fine.
I don't understand whats happening but it is what it is. I will rebuild the program in this new project.

Thank you for all your support.