Example:
ValveDataset = system.tag.read("System1/Project1/HOA/Valves")
for rowRead in ValveDataset:
CRvalveTo[rowRead['id']] = rowRead['description']
or do datasets need to be read differently.
Example:
ValveDataset = system.tag.read("System1/Project1/HOA/Valves")
for rowRead in ValveDataset:
CRvalveTo[rowRead['id']] = rowRead['description']
or do datasets need to be read differently.
system.tag.read()
returns a Qualified Value, so you need to reference the value
attribute.
ValveDataset = system.tag.read("System1/Project1/HOA/Valves").value
for rowRead in ValveDataset:
CRvalveTo[rowRead['id']] = rowRead['description']
For anyone who comes by in the future, on V8.0 or later:
You should use system.tag.readBlocking. system.tag.read
is depreciated.
readBlocking returns a list of Qualified Values, so it’ll look like:
ValveDataset = system.tag.readBlocking([tagPath])[0].value
I don’t know what type of dataset the readBlocking will return, a regular dataset or a pydataset. The regular dataset isn’t iterable (I don’t think), so you’ll need to convert a regular dataset if readBlocking doesn’t return a pydataset by default. You can convert using:
pydata = system.dataset.toPyDataset(ValveDataset)
Then you can iterate over pydata as above.
Their system is Ignition 7.8, so system.tag.read()
is correct.
How did you figure this out? I don’t see a version tag.
Heh. (Spelling) Deprecated just means it isn't documented for new users. IA is unlikely to actually break these any time soon.
TIL. I didn’t know there was a defined difference.
It is a standard dataset. I failed to correct that part of the code.
This:
ValveDataset = system.tag.read("System1/Project1/HOA/Valves").value
for rowRead in range(ValveDataset.rowCount):
CRvalveTo[ValveDataset.getValueAt(rowRead,'id')] = ValveDataset.getValueAt(rowRead,'description')
or
ValveDataset = system.dataset.toPyDataset(system.tag.read("System1/Project1/HOA/Valves").value)
for rowRead in ValveDataset:
CRvalveTo[rowRead['id']] = rowRead['description']
@lrose I’m getting a an error when trying to use the snippets above. Bottom one gives keyerror, top one gives eof error.
The bottom script by itself, can not give a key error, because you are not referencing a value in a dictionary. You'll need to provide the rest of the script.
With the top one, you are not reading from a file, so an eof
doesn't really make since.
@lrose here it is
# Gets Valve
valve = event.source.parent.getComponent('Label').text
# List of vales with multiple locations.
ValveMultLocs =["AB_211220","XV_211102","AB_210720","XV_210402","XV_210502","XV_210102","XV_211002","XV_210603","XV_210803","XV_210903"]
if valve in ValveMultLocs:
# Get Tank Number
GetTank = event.source.parent.parent.Page
# Read the selected Transfer To for apropriate tank
TransferTo = system.tag.read("System1/Project1/Tank Details/"+GetTank+"/TransferTo").value
# validate transfer
message = "Do you want to open" + GetTank + "to" + TransferTo
system.gui.messageBox(message)
# ask user to verify transfer location
UserInputTransfer = system.gui.showTouchscreenKeyboard("Verify Transfer Location")
if UserInputTransfer == TransferTo:
message = GetTank + " will now open to " + TransferTo
system.gui.box(message)
value = event.source.Setvalue
event.source.parent.Set_tag_state = value
else:
system.gui.messageBox("Transfer input did not match Tank Details selection.")
else:
#Dictionary to place valve location dataset in.
CRvalveTo = {}
#Dataset of valve locations
ValveDataset = system.dataset.toPyDataSet(system.tag.read("System1/Project1/HOA/Valves").value)
#Puts dataset into a dict
for rowRead in ValveDataset:
CRvalveTo[rowRead['id']] = rowRead['description']
#Gets transfer location
valveCrossx = CRvalveTo[valve]
UserInputTransfere = system.gui.showTouchscreenKeyboard("Verify Transfer Location")
if UserInputTransfere == valveCrossx:
message = valve + " will now open to " + valveCrossx
system.gui.messageBox(message)
value = event.source.Setvalue
event.source.parent.Set_tag_state = value
else:
system.gui.messageBox("Transfer input did not match Tank Details selection.")
You would only get a key error on this line:
valveCrossx = CRvalveTo[valve]
This means that the value the of valve
(so event.source.parent.getComponent('Label').text
) is not a value in the ‘id’ column of the dataset. Key’s are case sensitive so, insure that the value of the label matches exactly the value and case of the id you’re looking for.