I'm working on a program that pings an IP device and modifies a boolean value based on the result within a gateway timer script. I am well aware that Datasets and Pydatasets cannot be modified without creating an entirely new dataset, so I have converted these values to a dictionary of lists shown below:
event = system.dataset.toPyDataSet(system.tag.read("[default]Tyler/Guardian/Line2Devices").value)
row = 0
col = 0
newdict = {}
for row in range(event.getRowCount()):
newdict[row] = [str(event[row][0]), str(event[row][1]), event[row][2]]
row = row + 1
row =0
for row in range(event.getRowCount()):
x = newdict.get(row)
ip = x[1]
result = ping.ping(ip)
x[2] = result
newdict[row] = x
print(newdict)
After the print() executes, here is the result in the console (for security reasons, I have blocked the IP addresses, but I can verify they are showing up as expected):
The reason I chose to use a dataset tag is that I want the column and row sizes to be dynamic in that if we decide to add other devices(rows) or new data pertaining to each device(columns), that the script could remain unchanged. I am having difficulty finding a method to write this dictionary of lists back to the dataset tag after the values are modified. I tried this code snippet following the one above(I apologize in advance for the redundancy within):
row = 0
col = 0
for row in range(event.getRowCount()):
row = []
for col in range(event.getColumnCount()):
row.append(col)
datawrite.append(row)
headers = ["Name", "IP", "Online"]
ds = system.dataset.toDataSet(headers,datawrite)
last = system.dataset.toPyDataSet(ds)
system.tag.write("[default]Tyler/Guardian/Line2Devices", last)
Unfortunately, this simply wrote the memory addresses of the values to the tag instead of the values themselves.
Thank you in advance for any insight you might be able to give.