[Question] Scanning Barcode Data

I can’t seem to find where to retrieve the barcode information once scanned.

I have configured an action from a button and tried an array of combinations for object members. Im positive I am just not understanding how to do this.

Thanks in Advance (Loving it so far)

1 Like

I was trying to figure out the same thing and knew I saw mention of it somewhere. Turned out it was in this video. Skip to the 39 minute mark. Should show what you need. I would never have figured this out without the video. Perspective is definitely going to take some time to get used to!

Just as a heads up – we have a pretty big change in the works for how we handle data coming back from a native device. Currently barcode results are simply added to a session property called ‘barcodes’, and you (as the designer) can decide what to do with the values in that array. When this new update makes it into the nightly beta, handling is going to change to a message-style system that will make dealing with device data simpler and more uniform in general. No exact ETA, but keep an eye on the changelogs for these changes in the coming week or two.

1 Like

Looking for a different type of trigger…

I would like something that will trigger without being clicked/touched when the screen first starts up… would the onStartup trigger this?

Yes, the onStartup script would be the place to execute a Scan Barcode Action if you’d prefer to avoid a “manual” trigger (assuming you mean when the View first starts up).

Update:
No, Scan Barcode may not be used during the onStartup System Event in a View-level Event Configuration.

Yes… although I can’t get it to pass the scanned value back to the label text… It will pass into a text field if I select it (even without the event handler…)

I’m working on how to make this happen, but I’m waiting on internal network/device issues, so my reply might take some time.

IN the meantime, let me make sure I’m trying to do what you want…

You want to scan a barcode (ideally, as soon as the View starts up), and you would like that most recently scanned barcode to be posted in a Label on that same View after the scan?

That is correct… I am checking with the device sled manufacturer (Cognex) now for the most current firmware…

Ok, sled is up to date, as is the iOS

Will the onStartup trigger and then wait for input from the scan barcode action or will it fire off all at once before I can scan?

Okay, so this is how I managed your task:

  1. A Button has an onClick Event which triggers the Scan Barcode Action
  2. My View contains a label bound against session.props.device.barcodes.
  3. The Lable binding also has a script transform with the following code:
if len(value) == 0:
	return 'No Barcodes Scanned this Session'
else:
	return value[-1].data.text

ScanBarcode.json (1.6 KB)

With this setup, when I click the button (on a mobile device), I use the native barcode scanning to read a barcode.
On leaving the barcode scanning, I return to my View and the Label displays the scanned barcode value.

Unfortunately, the onStartup area I suggested will NOT work for client-side (session) actions like Scan Barcode at this time, as the onStartup and onShutdown events are Gateway-side. Short-term, we’ll look to remove the Scan Barcode Action from the View-level Event Configuration. Long-term, we’ll probably want to provide A View Events category which would include something like “onLoad” - and Scan barcode would go there.

Ok, this was pretty much the same as in the video link above, at about 38:45 to about 41:40ish…

1 Like

:white_check_mark:

I always forget that he did that walkthrough (even when it’s linked in the thread #shame) - it probably would have saved me some time…

Yes, his example is spot-on, although his example will only provide the first scanned barcode, whereas the code I supplied will get you the most recently scanned barcode.

something more like, as you mentioned, the View Events... or similar...
onLoad scan barcode, onInput set last barcode == text of specific label, trigger barcode listen again, onInput set last barcode == text of next specific label, and so on...

...With the variation being in the return value[-1].data.text instead of value[0].data.text

Would it be possible to do something where the onStartup event sets some property to the current datetime and then have a component in the view that checks the current datetime against this property? After 1-2 seconds initiate the Scan Barcode Action in the View? Basically the same functionality as having the Timer component from the Vision module.

1 Like

Long-term, nearly anything is possible, however, an important part of your question is that you’re using a script to initiate barcode scan; there’s no scripting API for that functionality at this time.

If our solution is to only add the appropriate scripting calls (system.perspective.scanBarcode() ), what you would most likely do is something along the following lines:

  1. In your View’s onStartup Event, perform self.view.custom.scan = int(self.view.custom.scan) + 1
  2. Provide an OnChange Script for the view.custom.scan property, and have that script invoke the barcode scan.

If our solution is instead to provide an Event more along the lines of onViewLoad, then you would be able to simply use the Scan Barcode Action when the Event occurs.

One last thing, just for clarity: the blocking factor here is not timing, so the 1-2 second wait will not alleviate anything - the blocking factor is where the script executes (even though it’s a View’s onStartup Event, the script will execute on the Gateway), combined with the limitations in what the Gateway can do vs what the Session can do (the Session can request access to the camera, but the Gateway is unable to do so).

2 Likes

The onViewLoad event is not available yet, correct?

Correct. At this point that’s only a concept that we’re looking into.

It does make sense to me to have the onViewLoad event handler though since Perspective handles things differently than Vision does. This will allow us to have triggers for those views that we won’t need to be initialized before that view loads and are ok to send to GC when we leave that view.

When trying the “self.view.custom.scan = int(self.view.custom.scan) + 1” in my onStartup Event, it gives me the following error:

INFO | jvm 1 | 2018/11/19 12:41:19 | File “function:runAction”, line 2, in runAction
INFO | jvm 1 | 2018/11/19 12:41:19 | AttributeError: ‘com.inductiveautomation.perspective.gateway.script’ object has no attribute ‘view’

if I change it to self.custom.props.scan I get the following…

INFO | jvm 1 | 2018/11/19 12:42:05 | File “function:runAction”, line 2, in runAction
INFO | jvm 1 | 2018/11/19 12:42:05 | AttributeError: ‘com.inductiveautomation.perspective.gateway.script’ object has no attribute ‘props’