I have a system that goes through about 30 serial numbers per batch, at the current time the operator is scanning in the serial numbers into the system. To prevent duplicate serial numbers from being scanned, I want to track the serial numbers that have been entered and if a duplicate is scanned, display something on the screen.
I am debating using a document tag and storing the serial numbers in a JSON format. I was thinking it would be a quick tag write as the serial number tag changed and then I could just read the document values and see if the serial number was there. It would be easy to clear at the end of the batch too. I could also just store them as an array.
I also thought about using a database but I don’t need to keep them after the batch is done so I felt this was a good but unnecessary storage.
Does anyone have any suggestions or pushes to get me off the paralysis from analysis stage! thanks
Others will know better but you could also use a dataset tag for this. Not sure if it's more efficient than JSON in a document tag though.
We have used this with datasets, JSON seems to be heavier on the gateway due to the inefficiencies of string operations.
1 Like
Document tags internal form is not JSON, and should be relatively efficient. Particularly if you are using the serial numbers as keys in your document.
1 Like
i was going to use integers as the keys and the serial numbers as the value but I can reverse it. Would you recommend using the document tag over a dataset tag? Thanks!
My seat-of-my-pants rule of thumb:
<=100 keys, sure, use a document.
Up to ~1000-10000 rows, use a dataset.
>=10000 values, use a real database.
6 Likes
is there a faster way than system.tag.readBlocking, then looping the result to get the json?
In a document tag it works like a dictionary. To test for an existing serial (assuming they are used as keys), the .get() method returns a fallback value:
if serialDoc.get(serialNumber, None) is None:
or
if serialNumber not in serialDoc.keys():
1 Like
Thanks, looks like I still have to use a readBlocking to get the value and a DICT to convert it. I was hoping there was some super fancy way to just get the JSON from the tag without doing the tag read and parse.
I didn't have to do that under 8.3.1. What version are you working with?
If it's a document tag you should be directly able to work with it after a read. As in:
doc = system.tag.readBlocking(["path/to/docTag"])[0].value
someValue = doc.get("someKey")
That worked for me, not sure why it was throwing an error before. It said unicode object has no function get when it was an empty dict
I did notice there is no len() function and I cant add items with myjson[‘newKey’] = ‘myval’ without making it a dict. I guess that makes sense as its a doc, not a dict? Thanks
if this can be implemented in a view, consider a standard tag binding on a prop to the document tag (or part of it) like [default]myDocumentTag['sub-object.deep-object.key'] - Tag Paths | Ignition User Manual
can then parse the param via script or expression transform (lookup perhaps?)
I’m using gateway scripts right now but I’ll keep that in mind for any views. thanks