Hi all,
I’m doing a screen that switch information every 15 sekund.
I have an array of struct in my PLC with 4 values (string, string, string, int). The array can be quite long so i have done it so that every time there is a status change, the PLC the code runs the code to update the values.
The array are then stored in a dataset in Ignition.
My plan is now that i want to show 5 row at the time on a power table. To do this I have tried to saved the five rows from stopDataSet to newData behind a timer. But for some reason I gett the hole stopDataSet-1.
Is there some function in Ignition where I can pick which rows to copy to my new dataset?
import math
#number of instances from the PLC, rows that will fill the dataset.
nrOfInstances=system.tag.read("[default]OPCServer/LineSpecials/fullScreenTB/nrOfInstances").value
#formula to keep track of the number of screens that will be shown, 5 rows per screen
nrOfPages=math.ceil(float(nrOfInstances)/5)
#loop nr Screens
for pageNr in range(1, int(nrOfPages)+1):
#formula for what row in the dataset that we will start copy from
func=(pageNr-1)*5
newData=[]
#loop 5 times sinces one screens shows 5 rows
for stopIndex in range(5):
row=stopIndex+func
#copy to new dataset, should only copy 5 rows
newData=system.dataset.deleteRow(event.source.parent.stopDataSet, row)
#put newData to power table
event.source.parent.getComponent('Power Table').data=newData
Is stopDataSet the entire dataset?
Yes, it is.
Just started to move the first part of the loop outside the timer. Since i don’t want to display the all the data every time the timer runs.
BR
Sample window done under 8.1.4
paged_8_1_4.zip (8.0 KB)
propertyChange Script on Timer
if event.propertyName == 'value':
def getPage(dataIn, page, rowsPerPage):
import math
# get column names
headers = list(dataIn.getColumnNames())
nRows = dataIn.getRowCount()
nCols = dataIn.getColumnCount()
pages = int(math.ceil(nRows / float(rowsPerPage)))
startRow = page * rowsPerPage
endRow = min(startRow + rowsPerPage, nRows)
data = []
for r in range(startRow, endRow):
newRow = []
for c in range(nCols):
newRow.append(dataIn.getValueAt(r, c))
data.append(newRow)
return system.dataset.toDataSet(headers, data)
event.source.parent.getComponent('Power Table').data = getPage(event.source.parent.stopDataSet, event.newValue, event.source.parent.rowsPerPage)
Hi,
Tanks for the replay, this worked fine. I did some changes, for the better, I don’t know, but now it works the way i want to. I made two timers. One holding the the logic for filling in the dataSet as you showed
tagPathNrOfInstances=event.source.parent.OPCServer+"/LineSpecials/fullScreenTB/nrOfInstances"
nrOfInstances2=system.tag.read(tagPathNrOfInstances).value
event.source.parent.stopDataSet=shared.global.showStops(event.source.parent.OPCServer, nrOfInstances2)
if event.propertyName == 'value':
def getPage(dataIn, page, rowsPerPage):
import math
nrOfInstances=system.tag.read("[default]OPCServerName/LineSpecials/fullScreenTB/nrOfInstances").value
# get column names
headers= ["Station", "Position", "Equipment", "Andon"]
nRows = nrOfInstances
nCols = 4
#pages = int(math.ceil(nRows / float(rowsPerPage)))
#pages=int(math.ceil(float(nrOfInstances)/event.source.parent.getComponent('Power Table').rowsPerPage))
startRow = page * rowsPerPage
endRow = min(startRow + rowsPerPage, nRows)
data = []
for r in range(startRow, endRow):
newRow = []
for c in range(nCols):
newRow.append(dataIn.getValueAt(r, c))
data.append(newRow)
return system.dataset.toDataSet(headers, data)
event.source.parent.getComponent('Power Table').data = getPage(event.source.parent.stopDataSet, event.source.parent.getComponent('Power Table').**activePageNr** ,event.source.parent.getComponent('Power Table').rowsPerPage)
And then a timer keeping track of where in the in the dataset it should start copying to the dataset.
activePageNr
import math
if event.propertyName == 'value':
sendPage=event.source.parent.getComponent('Power Table').activePageNr
nrOfInstances=system.tag.read("OPCServer/LineSpecials/fullScreenTB/nrOfInstances").value
pages=int(math.ceil(float(nrOfInstances)/event.source.parent.getComponent('Power Table').rowsPerPage))-1
if sendPage >= pages:
sendPage=pages
for loop in range(sendPage, pages+1):
#print 'looping'
if pages > sendPage:
#öka sendPage med 1 och exit
sendPage=sendPage+1
#print 'loop1'
break
elif pages == sendPage:
#nolla sendPage och exit
sendPage=0
#print 'loop2'
break
event.source.parent.getComponent('Power Table').**activePageNr**=sendPage
I have 2 costume properies in the power table
activePageNr
rowsPerPage
and in the root container 1
StopDataSet
rest of the data in coming from the PLC