I have scanner ScanSKU. This scanner has build in scanner and button to trigger scanner.
I just wonder if I can use this to scan barcode and write in to tag.
So I was able to use button event and scan barcode with camera - but this is not what I want.
I was able to use Input text and build in scanner and button and write it to tag. However, it means somebody need to always keep text field in focus.
So ideal scenario is to scan barcode with build in scanner and button and write in to tag.
This is working when I have button in the app and use scanner camera as per the instruction in article.
But, when I use build in scanner and build in button nothing has changed.
I is working when I create input text field and use build in scanner and button but when text field lost focus then nothing is scanned.
Based on this I know that app received data just want pass this to the tag.
If I am understanding you correctly, it sounds like what you are looking for is the Barcode Scanner Input component. This component doesnât require focus and can be configured to accept a keyboard wedge scanner as long as the scanner can be configured to send itâs data with the appropriate prefix/suffix or regex.
If you get the component accepting the scanner data, you can either have a button in the app or create a property change script on the componentâs data property to write to the tag.
Hi osolorzano
Thanks for replay.
Yes, I am trying to make Barcode Scanner Input to work.
Not sure what do you mean by appropriate prefix/suffix. I thought I need this only if I like to modify barcodes by adding prefix or suffix. In my example barcodes or 2D matrix does not have prefix or suffix just string characters such us âGLW1234567â. So when I used input text field built in scanner and button working find, however it required continuous focus and I think it acting as standard keyboard.
When I used Barcode Scanner Input and app button it opens camera and scan barcodes with no problem.
What I want, is to be able to scan using build in scanner and button. Not sure however how to check if scanner is sending data to app. It does when I used input text field.
The scanner I am using is ScanSKU Android scanner.
The way the input works is if you configure the prefix/suffix property with a character, it will listen and record characters between them. For example, if you set prefix to ! and the suffix property to @. Then start preview mode and type !asdf@, asdf will get recorded.
Your ScanSKU app should have a setting to add prefixes and suffixes. If you set the prefix and suffix for the scanner to be the same as the Barcode Scanner Input, it should then start working because your scanner will send a string of characters like !GLW1234567@ instead of just GLW1234567.
Thanks for your help it is working now. I can see string go through this property,
However, I canât make Session Event Barcode Scanned to write in to the tag as suggested on Perspective manual. system.tag.writeAsync(['[default]EVAP/Station_7/Scanner_Input'], [data.text])
Unfortunately this is not working.
So, I tried to set up Barcode scanner input and it works partially as I have scanned only GLW7227932. But it updates Tag with this string [[GLW7227932, Good, Thu Jan 01 01:00...
So I added custom property to format this in to GLW7227932
Then I have script to add this number in to sql as part of âchange scriptâ.
Sorry for the late reply, the reason the Session Event doesnât work is because that is specifically for the Scan Barcode Action. That session event is really just meant for mobile devices that have cameras attached to be used like a barcode scanner. An actual barcode scanner like the one you have would use the Barcode Scanner Input and change scripts like you have tried.
That said, I have been unable to reproduce the issue you are seeing of the query being run multiple times. Would you able able to provide a copy of the view you are working with so I can take a look?
Thanks for getting back to me as I stuck with this project.
So here is how I set this up.
I have barcode scanner input. Which is linked to a String Tag.
However, when I scan any barcode it also fetches, quality, timestamp information.
I will expect only GLW1232797
So I have created Custom property to give me only barcode string.
On this Custom property I have setup change script to add value in to SQL DB.
All working fine except script below is runned few times, usually about 3 times every time I scan new barcode.
Script:
def valueChanged(self, previousValue, currentValue, origin):
"""
This function will be called when the value of the property changes.
Arguments:
self: A reference to the component that is invoking this function.
previousValue: The previous value, as a qualified value object.
currentValue: The new value, as a qualified value object.
origin: The origin of the property value. Possible origin values include
Browser, Binding, BindingWriteback, Script, Delegate, Session
"""
import datetime
from time import sleep
GLW_Current = self.custom.CurrentGLW
GLW_Last = self.custom.LastGLW
if GLW_Current != GLW_Last:
sleep (2)
SerialNO = GLW_Current
id_Component = 32
Status = 1
t_stamp = datetime.datetime.utcnow()
query = "INSERT INTO Production_Progress (Serial_Number, id_Component, Status, t_stamp ) VALUES (?,?,?,?)"
args = [SerialNO, id_Component, Status, t_stamp ]
system.db.runPrepUpdate(query, args)
table = self.getSibling("Table")
table.refreshBinding("props.data")
self.custom.LastGLW = GLW_Current
else:
Status = 0
So I would like to address 2 things.
Why when I scan barcode it also puts info in to tag about quality and timestamp?
Why script is run more than once. Even if the previous value and current is the same?
These are the results in SQL DB:
Almost every value you interact with within Ignition is actually a Qualified Value of some sort. Qualified Value is an important concept because this is how quality and timing are conveyed throughout the project. If you look at the docstring of valueChanged in the code you provided above, you'll see that it clearly defines that you will receive a Qualified Value. If you ONLY want your string, try looking at currentValue.value, which will give you the value attribute of the Qualified Value.
THIS is because the QUALIFIED VALUE is NOT the same. See the time stamps in your Database? What happened is you received three entries which were all not equal to one another. The first entry has a Serial_Number of one of our Object classes, the second had a different Serial_Number, and the third had a different t_stamp.
You can probably boil your script down to something simpler, like:
if currentValue.value != previousValue.value:
# do some stuff
This would only perform the logic if the new value scanned was not equal to the last value scanned.
One thing I want to point out with how this is all set up. The binding to the string tag you have is taking what it scanned and turning that qualified value into the value of the tag, which itself will have a qualified value with the value being a stringified qualified value. While not really the source of your issues considering the queries are done from the custom property, I think this can be simplified a bit.
What you can do is put the change script directly onto the props.data property and do a script like:
import datetime
# Ignore the change script when setting the value to an empty list
if(len(currentValue.value)>0):
# Get the currently scanned option and set that to SerialNo
SerialNo = currentValue.value[0].value
GLW_Last = self.custom.LastGLW
if(GLW_Last != SerialNo):
# Set the other variables
id_Component = 32
Status = 1
t_stamp = datetime.datetime.utcnow()
# Do your sql query here and table refresh
# Set LastGLW
self.custom.LastGLW = SerialNo
else:
Status = 0
# Clear the props.data since it seems like you are
# just using the most recently completed barcode scan
self.props.data = []
line 5, in valueChanged AttributeError: âunicodeâ object has no attribute âvalueâ
import datetime
if(len(currentValue.value)>0):
# Get the currently scanned option and set that to SerialNo
SerialNo = currentValue.value[0].value
GLW_Last = self.custom.LastGLW.value
if(GLW_Last != SerialNo):
# Set the other variables
id_Component = 32
Status = 1
t_stamp = datetime.datetime.utcnow()
query = "INSERT INTO Production_Progress (Serial_Number, id_Component, Status, t_stamp ) VALUES (?,?,?,?)"
args = [SerialNo, id_Component, Status, t_stamp ]
system.db.runPrepUpdate(query, args)
table = self.getSibling("Table")
table.refreshBinding("props.data")
# Set LastGLW
self.custom.LastGLW = SerialNo
else:
Status = 0
# Clear the props.data since it seems like you are
# just using the most recently completed barcode scan
self.props.data = []
Simple answer: GLW_Last = self.custom.LastGLW.value is attempting to reference something which is a str and then get the value attribute. When I mentioned that
What I should have said is "Usually, when you're referencing something which is not a visible property". What I mean by that is this: if you can see the property in a property editor, then you can (99%) of the time reference it as a straight value (str, int, float, list), but if you're looking at currentValue, previousValue, or anything returned from a system.tag scripting call, you're probably dealing with a QualifiedValue object.
TLDR; change GLW_Last = self.custom.LastGLW.value to GLW_Last = self.custom.LastGLW. When we provide scripts, please always take our suggestion with a grain of salt - we don't have the same setup and data you have, so there's almost no chance we've actually run the script ourselves, and it is only meant as an example or suggestion.
Continuing the topic. I have one scanner connected to PC and it is not connected to Ignition but ignition and Scanner will work on same PC.
So when operator scans the barcode then i need to read this scanned data in Ignition text field. I have gone through the above chats but maybe my requirement are different given above. So i need to use barcode scanner component with input field as i am not using ignition build in mobile device scanner.
If anyone has done this before, do share the experience
We just played with this today using an Alacrity MJ-2020R Scanner. The steps were.
Consult your scanner's user manual and assign a prefix AND suffix. We chose a prefix of $ and a suffix of " for our testing.
Place the perspective BarcodeScanner Input component on a view and set its props.prefix and props.suffix with the same characters. They must be string characters and not numbers.
Lauch a perspective session to the page URL that has the BarcodeScanner component on it, click the screen so that you are focused on the session, and scan away.