Write data to multiple Pi tags over a wide data range

I need to write data(0s) to more than 100 tags over the span of 10 years. I only need one value per day, but that is still over 3500 values per tag.

PiImport will take too long, so I'm using piexam32. I populate the Timestamp column with a date per cell for 10 years, the Data Item column with the same tag and 0s in the Value column. Rinse and repeat for each tag.

Is there a simpler way to do this? Maybe one where I state the time range in a cell then reference it to have the data written for all the tags?

 

Edit: PiImport actually writes the data faster. I guess I'm just looking for a way to set this up and go to bed so I don't need to make any input until it is done

  • If the timestamp for all tags is the same for each day over the 10 years, then I would write a simple script (either PowerShell or C#) that only takes the input of tags, start date, end date, time of day for the value, and the value. Have the script iterate over it. It'll be faster than using the other tooling, and you don't have to create multiple files or do any other management.

  • Thanks. The timestamp is indeed the same. Can you share a sample of this script please?

  • I wrote this prompt to copilot:

    "I need a powershell script to write values to Aveva PI tags. There are more than 100 tags and they each need a 0 value to be inserted for the same time each day over a time period of 10 years."

    It came back with this:

    # Load the necessary PI AF SDK assembly
    Add-Type -Path "C:\Program Files\PIPC\AF\PublicAssemblies\4.0\OSIsoft.AFSDK.dll"
    
    # Connect to the PI Data Archive
    $piServers = New-Object OSIsoft.AF.PI.PIServers
    $piServer = $piServers["YourPIServerName"]
    
    # List of PI tags
    $tags = @("Tag1", "Tag2", "Tag3", ..., "Tag100")  # Replace with your actual tag names
    
    # Define the start and end dates
    $startDate = [datetime]::Parse("2014-01-01")
    $endDate = [datetime]::Parse("2024-01-01")
    
    # Loop through each day in the date range
    $currentDate = $startDate
    while ($currentDate -lt $endDate) {
        foreach ($tag in $tags) {
            # Find the PI Point
            $piPoint = [OSIsoft.AF.PI.PIPoint]::FindPIPoint($piServer, $tag)
    
            # Create the AFValue object with the value 0
            $afTime = New-Object OSIsoft.AF.Time.AFTime($currentDate)
            $afValue = New-Object OSIsoft.AF.Asset.AFValue(0, $afTime)
    
            # Write the value to the PI Point
            $piPoint.UpdateValue($afValue, [OSIsoft.AF.Data.AFUpdateOption]::Replace, [OSIsoft.AF.Data.AFBufferOption]::BufferIfPossible)
        }
    
        # Move to the next day
        $currentDate = $currentDate.AddDays(1)
    }
    
    Write-Host "Values inserted successfully."

    I've not tried it out at all and I've found that Copilot code sometimes needs a little adjusting but generally it can give a good place to start.

    An alternative, as you've already played with piexam32, is to take a copy of that and adjust the VBA code behind it to do similarly to the above Powershell script.

    This all depends on your programming experience of course!

  • Worked like a charm! Took about 2 minutes.

    Thanks!