PI-UFL Write multiple events at same timestamp - but only once

We need to interface our Asset Management System (AMS) with PI. OPC DA is available, but not recommended for such a connection - this is meant only for internal AMS tools.

So we have been asked to use the published web-services.

One of the pieces of information that will be required in PI is the health of a piece of equipment. I have successfully queried AMS for a list of active alerts using powershell and I was going to use PI-UFL to write this to PI.

In the example above you can see that for asset PBSIM3 we have 3 events at the same timestamp. I would like to store all 3 events.

I can set location5 on the PI Tag to 2, which will add the 3 events at the same time, and I guess that I would also have to set the /AM settings in UFL to ARCAPPEND.

This will work fine the first time the powershell runs and generates the XML response. But next time it runs chances are the same events will still be in the list and I only want to add NEW events, not the same 3 again.

Is it possible to somehow check to see if an event exists first and to not write if this is the case? The /RBO switch is available but I don't think this will work with the multiple entries at the same timestamp.

The alternative might be to implement the feature used in RDBMS interface whereby I keep track of the latest timestamp in the XML file and to only process events that are newer. It would be possible to write this to a tag in PI, but again I don't think that it is possible to read the current value of a tag in the UFL INI file to be able to get at this time.

The /RBO switch should work for your situation. Based on the description, it means, "Read archive before writing value, to see if event already exists at same timestamp. Write a new value only if value is different from existing value. To enable this option, points must have Location5 set to 1, and neither the /lb or /lbs flags can be configured. Does not work if values include annotation, which are written using the PI SDK." This means that in your example, 2 of the values would be written since there are two unique values. If the new XML file contains the same entries, they will be passed over.

Would there be a reason that you need all three entries saved even though two of them are the same? If so, we can look for another option.

You are right that the example above is not a good one because there are two statuses with the same text, even though they relate to different things in AMS. In this case then yes, events with the same value at the same timestamp should be compressed out.

If the /RBO switch is clever enough to deal with multiple events at the same timestamp then it would probably work as you say. If it only looks for any event at the timestamp given, that would be a problem because as you can see it might already find one there and not add a new event.

I will setup a test to see what happens.

I will set /AM=ARCAPPEND, location5=1 (However I think that this should be set to 2 because otherwise it will just overwrite one of the other events)

I do not know of a good solution here. You could use RDBMS in append mode with a P1=TS placeholder and a "WHERE TIME > ?" clause that filters out the events already added. It would append all events and never get those events again. However, if a new value was added at the same timestamp, it would miss that event since you are filtering by TS.

And if you need the annotations, RDBMS will also use the PI SDK, which means RBO will not apply either, just like with UFL.

In your Powershell, surely you are doing some kind of filtering?! Otherwise, the data will grow to infinity? Or is it purged at the source? You could keep an internal Powershell structure with a processed data item for each record.

I would solve it with small trick to avoid multiple events with the same timestamp. If you query your data and create an intermediate text file, try to use milliseconds as a counter of events with the same timestamp. In your case, I would prepare timestamps:

This would only work if the values are consecutive in the data file. If another tag is between the values, it would append or replace (based on /LB and /AM=n -> Archive mode - 4: (ARCAPPEND) Add event regardless of existing events - page 49). If there are never any instances of other tags "in-between", I believe you could combine the above IF logic along with /AM=5 (ARCREPLACE Default: Add event, replace if event at this same time) with /RBO switch and achieve a satisfactory result.

Worthy of consideration.

NOTES for /AM:

This startup parameter does not apply when values sent

to the PI Data Archive include annotations, because such

values are sent using the PI SDK. If annotations are

required and you need this feature, set Location5 for the

target points.

NOTES FOR /RBO:

Use location5= 1

Disables exception reporting, and for multiple

values collected for a single time stamp, use the

mode replace.

Regarding your comment on the learning curve for powershell, I would like to point you to a free 7 day trial at cbtnuggets.com. The nuggets (videos) on powershell are quite good and they break up the training into 20-30 minutes, making them "lunchable".

Cheers,

Richard

Please help improve PI Square by using the "Like" and "Helpful" options, when appropriate. It can help others when "skimming" the conversation threads.

Yes I use the usual fonts of knowledge for training - youtube and google. It's an extremely powerful tool - programming features without the need for visual studio.

I will try the different suggestions. I have got my PI Server on the same network now as AMS Server. I have also made contact internally within Emerson for questions relating to the specific web-services. The documentation for these fall short of being entirely useful!