I watched this video, but I need a script to write to tags indirectly
I need the barcode data to write to the tag based on the machine number. I know how to write that in an expression but am not sure how to write it in the script. The machine number is currently on {view.params.MachineNumber} property.
The tag is Machine 01/Batch Number. I tried replacing the 01 with {view.params.MachineNumber} but no luck.
Youre supplying the literal tagpath ’[default]Machine {view.params.MachineNumber}/Batch Number’ to the tag write function. You need to evaluate the machine number part first and then add it to the string:
and I confirmed that there is no other part to the view/params reference. It did not work.
The view params is from the Machine template that is being repeated in the flex repeater. When I scan a barcode from the flex repeater it does not go to anywhere. If I put a single machine tag it works, so I know it can work, but I need it to be dynamic to see the machine number and apply it to the machine's tag based on the view that the Scan Barcode button is being opened on.
Sorry, my phone used the wrong apostrophes… or rather, I chose the wrong apostrophe on my phone.
You need to use ' instead of ’. I fixed it in my post.
Error running session.onBarcodeDataReceived(session, data, context): Traceback (most recent call last): File "function:onBarcodeDataReceived", line 3, in onBarcodeDataReceived at com.inductiveautomation.ignition.common.tags.paths.parser.TagPathParser._parse(TagPathParser.java:193) at com.inductiveautomation.ignition.common.tags.paths.parser.TagPathParser$ParseFunction.load(TagPathParser.java:365) at com.inductiveautomation.ignition.common.tags.paths.parser.TagPathParser$ParseFunction.load(TagPathParser.java:360) at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3708) at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2416) at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2299) at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2212) at com.google.common.cache.LocalCache.get(LocalCache.java:4147) at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4151) at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:5140) at com.inductiveautomation.ignition.common.tags.paths.parser.TagPathParser.parse(TagPathParser.java:149) at com.inductiveautomation.ignition.common.script.builtin.AbstractTagUtilities.parseTagPath(AbstractTagUtilities.java:81) at com.inductiveautomation.ignition.common.script.builtin.AbstractTagUtilities.parseTagPaths(AbstractTagUtilities.java:92) at com.inductiveautomation.ignition.common.script.builtin.AbstractTagUtilities.writeAsync(AbstractTagUtilities.java:370) at jdk.internal.reflect.GeneratedMethodAccessor449.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) com.inductiveautomation.ignition.common.tags.paths.parser.TagPathFormatException: com.inductiveautomation.ignition.common.tags.paths.parser.TagPathFormatException: Token PROPERTY_SEPARATOR found after property name.
Should there be a space after %s?
If that fails, before you write to the tag, write the tag path string you're creating to a component property or print it (when you use print in Perspective it will go into the wrapper.log, so make sure you have something in there unique to search for).
E.g.
This is the error I get: Error running session.onBarcodeDataReceived(session, data, context): Traceback (most recent call last): File "<function:onBarcodeDataReceived>", line 2, in onBarcodeDataReceived NameError: global name 'self' is not defined
Sorry, I misunderstood where you were calling this from.
You can’t read the view’s properties from a session script. What I would do is to create a session property and bi-directionally bind the MachineNumber that you select to that. Then in the onBarcodeDataReceived script, you’ll be able to reference it using e.g. session.custom.MachineNumber
Aha, thanks. I created the session property MachineNumber but I’m not sure where to bind it. When you say the MachineNumber that you select do you mean the Scan Barcode button?
I have the Scan Barcode button on the Machine template as well as the text field that has a bi-directional indirect binding using the view params MachineNumber to the tag I’m trying to write to.
Yes, you would write to it when you click on the scan barcode button. Instead of using your view param on the label text binding, you would use the session property and remove the view param altogether.
Hello, I’m having a similar problem here where I’m trying to build an inventory system using barcodes. I have a scan barcode button, and have “Quantity” tags linked to a value in a table. I wrote the script in the video but it seems like all barcodes change one output in my table. How do I write a dynamic script so that each barcode corresponds to specific tags in my system?