Hello,
I have the barcode scanner input component configured but would like to take the value of the first element array write it to a memory tag and delete the element so that each scan will always be the first element in the array. I've tried scripting this out on key press and on actionPerformed but it doesn't seem to work. Any suggestions?
Mutating the prop element in place isn't a good idea, because that mutation never makes it back to the actual property tree structure in the component. Instead explicitly set the data property to a new empty list.
I changed it to this following:
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
value = self.props.data[0]
system.tag.writeBlocking('[C1Y]RackLabel/ScannedValue', str(value))
emptyList =
self.props.data = emptyList
But i'm getting the following error:
com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
File "function:valueChanged", line 2, in valueChanged
IndexError: index out of range: 0
Sorry this is my first ignition project.
Oh I got it, I took out
value = self.props.data[0]
system.tag.writeBlocking('[C1Y]RackLabel/ScannedValue', str(value))
and put it inside of the actionPerformed event.
Thanks for your help, property change events are awesome!
You were probably causing two changes to happen in rapid succession.
In the first change, the scanned barcode adds a value to the data array.
That triggers your property change event.
Then your property change event fires, and resets the data array to an empty array.
That triggers your property change event
Then that property change throws an error, because there's no index 0 on an empty list/array - which is the only thing saving you from an infinite loop (a risk in property change scripts, if they write back to themselves).
actionPerformed is a perfectly fine solution, but you could probably make the property change work as well; you would just have to filter off the origin parameter that's provided in your property change script; a scan will have a different value for origin than your script clearing it out will.