# Barcode Data Handling Script - stopped working

**URL:** <https://forum.inductiveautomation.com/t/barcode-data-handling-script-stopped-working/68865>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [January 20, 2023, 7:50pm UTC](https://forum.inductiveautomation.com/t/barcode-data-handling-script-stopped-working/68865 "2023-01-20T19:50:56Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [January 20, 2023, 7:50pm UTC](https://forum.inductiveautomation.com/t/barcode-data-handling-script-stopped-working/68865/1 "2023-01-20T19:50:56Z")

</div>

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:

```auto
def onBarcodeDataReceived(session, data, context):
	Consult.ConsultMaterials.scanCam(data.text)

```

```auto
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:

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

```

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [January 20, 2023, 8:34pm UTC](https://forum.inductiveautomation.com/t/barcode-data-handling-script-stopped-working/68865/2 "2023-01-20T20:34:36Z")

</div>

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:

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

```

I recommend removing it.

---

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [January 20, 2023, 8:56pm UTC](https://forum.inductiveautomation.com/t/barcode-data-handling-script-stopped-working/68865/3 "2023-01-20T20:56:22Z")

</div>

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](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/4/c42ad96050d4cba23391d63cd1790dff38dfc0b4.gif)

---

<div class="post-metadata">

**Author:** ![Ken\_Pace](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken_pace/32/36092_2.png) [@Ken\_Pace](https://forum.inductiveautomation.com/u/Ken_Pace)\
**Post date:** [January 20, 2023, 9:34pm UTC](https://forum.inductiveautomation.com/t/barcode-data-handling-script-stopped-working/68865/4 "2023-01-20T21:34:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [January 23, 2023, 1:04pm UTC](https://forum.inductiveautomation.com/t/barcode-data-handling-script-stopped-working/68865/5 "2023-01-23T13:04:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ken\_Pace](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken_pace/32/36092_2.png) [@Ken\_Pace](https://forum.inductiveautomation.com/u/Ken_Pace)\
**Post date:** [January 23, 2023, 5:06pm UTC](https://forum.inductiveautomation.com/t/barcode-data-handling-script-stopped-working/68865/6 "2023-01-23T17:06:55Z")

</div>

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..."

---

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [January 23, 2023, 9:26pm UTC](https://forum.inductiveautomation.com/t/barcode-data-handling-script-stopped-working/68865/7 "2023-01-23T21:26:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [January 23, 2023, 9:28pm UTC](https://forum.inductiveautomation.com/t/barcode-data-handling-script-stopped-working/68865/8 "2023-01-23T21:28:34Z")

</div>

**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=|

---

<div class="post-metadata">

**Author:** ![Ken\_Pace](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken_pace/32/36092_2.png) [@Ken\_Pace](https://forum.inductiveautomation.com/u/Ken_Pace)\
**Post date:** [January 23, 2023, 10:42pm UTC](https://forum.inductiveautomation.com/t/barcode-data-handling-script-stopped-working/68865/9 "2023-01-23T22:42:56Z")

</div>

> 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?

---

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [January 24, 2023, 1:04pm UTC](https://forum.inductiveautomation.com/t/barcode-data-handling-script-stopped-working/68865/10 "2023-01-24T13:04:18Z")

</div>

It is checked.  
**Below is the Message Handler**

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/6/66c2b53e675d73f05984df4fcb1401dfa145f1ab.png)

Code:

```auto
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**

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/c/4c2cc1523a15feb1bd668789f623996e66c3894d.png)

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

```auto
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:**

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

```

---

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [January 24, 2023, 1:15pm UTC](https://forum.inductiveautomation.com/t/barcode-data-handling-script-stopped-working/68865/11 "2023-01-24T13:15:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ken\_Pace](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken_pace/32/36092_2.png) [@Ken\_Pace](https://forum.inductiveautomation.com/u/Ken_Pace)\
**Post date:** [January 24, 2023, 4:45pm UTC](https://forum.inductiveautomation.com/t/barcode-data-handling-script-stopped-working/68865/12 "2023-01-24T16:45:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [January 24, 2023, 9:07pm UTC](https://forum.inductiveautomation.com/t/barcode-data-handling-script-stopped-working/68865/13 "2023-01-24T21:07:07Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![Ken\_Pace](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken_pace/32/36092_2.png) [@Ken\_Pace](https://forum.inductiveautomation.com/u/Ken_Pace)\
**Post date:** [January 25, 2023, 1:38pm UTC](https://forum.inductiveautomation.com/t/barcode-data-handling-script-stopped-working/68865/14 "2023-01-25T13:38:48Z")

</div>

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](https://docs.inductiveautomation.com/display/DOC81/Perspective+Session+Event+Scripts#PerspectiveSessionEventScripts-BarcodeScanned) and see where that gets you.

---

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [January 25, 2023, 3:17pm UTC](https://forum.inductiveautomation.com/t/barcode-data-handling-script-stopped-working/68865/16 "2023-01-25T15:17:55Z")

</div>

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.
