Ercan Çetgen
Ercan Çetgen

Reputation: 1

osisoft updating values ​with python

I want to get the data from Excel and update the values ​​of the data between certain dates in the osisoft system. But I don't know how to code AfTimeRange. I get the error "value cannot be converted to OSIsoft.AF.Time.AFTime".

enter image description here

Upvotes: 0

Views: 496

Answers (2)

Jason Molina
Jason Molina

Reputation: 1

It seems that you have the timestamp into your data. The point is that you should give a single timestamp for each piece of data:

val.Timestamp = AFTime('whatever date as string')

While AFTime accepts the input as time-string, datetime or PI-like strings (like 'y', 't', '*', 't+2h'), I think the easiest is to set it as strings, having that your data comes from Excel.

If there is a column with timestamps in your Excel spreadsheet, then it is done, if not, you still need to figure out how to determine them: as an example, 't' for the first data, assuming it started from 'Today at 00:00' and then increments of 5 minutes come until the spreadsheet is traversed:

span = AFTimeSpan(0, 0, 0, 0, 5, 0)
t = AFTime('t')

And then, inside the for each loop:

val.Timestamp = t
t = t + span

Hope it helps... such a long time.

Upvotes: 0

Steve can help
Steve can help

Reputation: 512

Good news: You've constructed your [AFTimeRange] correctly!

Notice that the error being thrown is not by the [AFTimeRange] constructor, but from something else.

The issue is that you are trying to set the 'Timestamp' attribute [OSIsoft.AF.Time.AFTime] to a value of type [OSIsoft.AF.Time.AFTimeRange], and so it's failing. A PI event has a single timestamp, not a time range.

I'm not familiar with Python, but it should work if you input the value as an AFTime object using its string constructor, assuming you're intending to use yesterday midnight as your timestamp:

val.timestamp = AFTime("y")

See the documentation on AFTime for more detail.

Upvotes: 0

Related Questions