Anybody have an example of using PIPutValX to write an AF Attribute from Excel? The provided example shows how to write a PI Tag but not an attribute.
Yes I got it working:
Dim ValueCell As Range
Range("Data!C14").Value = ""
Range("Data!C15").Value = ""
AFRoot = Range("Data!C10").Value
AFAttr = Range("Data!C12").Value
Set ValueCell = Range("Data!C13")
Set ResultCell = Range("Data!C14")
TimeStamp = Format(Range("Data!C11").Value, "dd-mmm-yy hh:mm:ss")
MacroResult = Application.Run("PIPutVal", AFAttr, ValueCell, TimeStamp, AFRoot, ResultCell)
Range("Data!C15").Value = MacroResult
If any parameter is not just right, you get an error and the error messages are not very helpful. But it works wonderfully!
For example, I still get this as my “MacroResult”: Object reference not set to an instance of an object.
Not sure what that means exactly.
Accenture Data & Analytics
North America Resources
IIoT. Analytics. Data Management.
Works pretty much same way as with writing to PI. You can either use the full path to the attribute where you would normally pass the tag name and leave the server blank, or you can pass just the attribute name and pass the root path to the Attribute where you would normally pass the PI server name.
Set ValueCell = Range("A1")
Set ResultCell = Range("A2")
timestamp = "*"
AFRoot = "\\SERVER\DATABASE\Element"
AFAttr = "Attibute"
macroResult = Application.Run("PIPutVal", AFAttr, ValueCell, timestamp, AFRoot, ResultCell)
AFAttr = "\\SERVER\Element|Attibute"
macroResult = Application.Run("PIPutVal", AFAttr, ValueCell, timestamp, , ResultCell)
Note: you can't write to a configuration item. Also, Excel seems to cache everything in AF so if you are updating your attributes/elements while testing your code, best to save everything, close all instances of Excel and open it up again to clear any caching. I've only used this with Datalink 2015, not tested other versions but pretty sure it's worked since Datalink 2013.
Yep I tried that… I’m getting a weird error:
"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
Here’s my code:
macroResult = Application.Run("PIPutValx", DataItem, ValueCell, stime, RootPath, ResultCell)
DataItem (cell reference), contains: Last_In_Service (attribute name)
ValueCell (cell reference), contains:
stime (cell reference), contains the Excel formula =now() and is formatted dd-mmm-yy h:mm
RootPath (cell reference), contains an Excel formula with string concatentation with value: AFNode\AFDataBase\Entity
ResultCell (cell reference),… where the above error shows up.
1) In your example below you have
Don’t you need the database?
2) i get the same error with your example or mine
Yes, that was a typo missing the database off, I have edited that now!
What is the value type and data reference of the attribute?
No data ref
I have tried integer 16 and datetime
I tried writing to a datetime and it didn't work at first, but I got an error about it not being able to convert an Excel date to AF time. Having the value cell being a text cell resolved that, could that be the issue?
i tried that also
i also tried “*”
Maybe one for tech support then I’m afraid, as even that works for me. I’ve attached my excel sheet here in case it helps but I doubt it’s any different to what you’re already trying. Are you using Datalink 2015?
let me try re-installing DataLink 2015A
thanks for your help so far!
i didn’t get the attachment
can you send again?
Well I got it to work…
at least I have something working.
I can write a DateTime to an attribute.
But PI is very picky about the format and the data type of the cell.
I’ll post a working copy when I finish...
I just wanted to check in with you regarding this post. Were you able to get a solution up and running? Let us know if you have any more questions, otherwise go ahead and feel free to mark one of the above posts as the 'Correct Answer'. Thanks!
can you pass and will AF accept the timestamp instead of simply "*" for current time?
Retrieving data ...