Have searched the help and the forums, cannot find an example of creating an array tag…I am probably overlooking something simple…anyway, I have a control logix array…600 reals…lets call it BottomRaw…
I create a new OPC tag, select float array as the type…the first issue is that it will not let me select the main “folder” for the tag, if I type in the root name (folder name) it doesnt work, and I have tried various ways with the name and empty brackets…BottomRay, BottomRaw[0], etc
That’s because Ignition doesn’t support actual arrays of primitive types. Due to an unfortunate and non-intuitive naming decision, the feature that exposes the individual bits of primitive types is called an array of that primitive. One primitive element at a time.
BTW, if you don’t really need an array type, just access to all of those elements, drag the OPC Item folder to the Tag Browser and release in the spot you want – Ignition will create all 600 tags.
The main reason for bringing these tags in (temporarily) is to graph them…should I start a new topic or can someone direct me how link an array like this to a chart of some type?
You’ll have to construct a dataset with the values in a column. Something like this:
tagpattern = '[default]path/to/array/_%d_'
headers = ['Samples']
rows = [[x.value] for x in system.tag.readAll([tagpattern % d for d in range(600)])]
ds = system.dataset.toDataSet(headers, rows)
Got the dataset portion working, struggling with the code to assign the ds to a charts dataset…
(PS…I used (‘Chart1’).Data above, I copied it when I was trying something else)
I can use this code for a table object, but the three different charts complain…
Easy Chart…no data property, and I tried DB Pens and Calculated Pens
Chart complains no attribute data
Sparkiline says the same…
I thought all charts needed a timestamp?!? Just looking at the way to assign the dataset to a chart…
Use the classic chart. Use its chart configurator to add a dataset. Which will be a custom property name you can use in your script. If you use an XYplot, you’ll need a timestamp column before the value column, which you’d have to create programmatically knowing the interval between your samples. But the other plot types shouldn’t care. You just wouldn’t have an X-axis label/timespan.
Making sure I understand, when you say classic chart, you mean “Chart” from the components menu correct? (nothing listed as “classic chart”).
I am really confused, I can only make it an xy chart or a category chart…I got it changed to a category chart and it will still not display, any lines. The dataset for the chart contains a single column of data (it contains the correct data) which I have set for the Y axis in the configurator…the only thing I have been able to do was to manually add a column, and put a few dates in, this worked. IF I must use a date field, can you assist me in the code to, for example, start with now, and add one minute to each record, at least I could get it to display! I under stand that I need to add another field to the headers line
such as…
headers =[‘DtTime’, ‘BottomRaw’]
just not certain how to step thru the rows and write and increment the date.
startMillis = system.date.now().time-600*60000L
tagpattern = '[default]path/to/array/_%d_'
headers = ['t_stamp', 'Samples']
samples = [x.value for x in system.tag.readAll([tagpattern % d for d in range(600)])]
rows = [[system.date.fromMillis(startMillis+60000L*i), v] for i, v in enumerate(samples)]
ds = system.dataset.toDataSet(headers, rows)
It is working as expected, Thank You! I would like to add another column added to the dataset in the same fasion as the current column…have been playing with it and one of the things I cannot get is the v…thought it might be a variable placeholder, but if I add any other letter, it complains that it is not defined, so maybe it is a type, but when I duplicate it, complains still…how are the i and v used without being defined?!? Anyway, here is the code that I think SHOULD work, am I missing something small? syntax?
Those variables are defined by the for i, v clause of the list comprehension. You cannot combine two lists in parallel with the syntax you attempted. You need to use python’s zip() function. Like so:
rows = [[system.date.fromMillis(startMillis+60000L*i), v[0], v[1]] for i, v in enumerate(zip(samples, samples2))]
I’ve got almost the same issue, but even with your code I can’t get it working.
I’ve got an array with 100 values and want to visualize it in a Bar Chart.
So 100 values numbered from 0 till 99.
I adjusted your code:
The line “tagpattern” is pointing to the tags in my array like the example in the beginning of this topic
The rest of the code is a combination from above.
Imho I need also something to write the data from the array to the dataset.
tagpattern = ‘FluidFill/AmountOfFluid/AmountOfFluid_%d_’
headers = [‘Label’, ‘Last_Fillings’]
samples = [x.value for x in system.tag.readAll([tagpattern % d for d in range(100)])]
rows = [(100)]
ds = system.dataset.toDataSet(headers, rows)
event.source.parent.getComponent(‘BarChart’).AmoutOfFluid = ds
Can you point me in the right direction?
I’ve got this script running in a timer script like you mentioned.