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.
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.
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?
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.
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.
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:
In your View’s onStartup Event, perform self.view.custom.scan = int(self.view.custom.scan) + 1
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).
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’