I’m struggling to figure out how to make the connection to the PI server to python,
I’m struggling to figure out how to make the connection to the PI server to python,
You do not specify which developer technology you wish to use.
The preferred and supported developer technology for Python is PI Web API. It is not the only one - RTQP is also supported.
AF SDK, which is restricted to Windows and .NET Framework, is an option BUT it is not officially supported for Python by Tech Support. You may ask questions here but AVEVA may not answer. Other customers might be able to help, but that is not something I would rely on.
Which developer technology are you using with Python?
Hi
Have you checked out the samples available in AVEVA's GitHub?
https://github.com/AVEVA/sample-pi_web_api-common_actions-python
Previously, I used PowerShell and the code worked fine. However, I'm unsure how to connect Python 3.10 to the Pi server. Could you please help me with this?
Many would be glad to help IF they knew which PI Developer Technology you are using?
What were you using when you used PowerShell? What have you done or tried so far with Python? Can you post the relevant code here?
hello sir , could you please help me on this
below code power shell code
folder
$filePath = "C:\Users\VODDUSR1\Decrypt\Final_goldenbatches\334 - Singapore test script showcase\"
$start = (Get-Date)
and pull frequency (minutes)
$my_variables = Import-Excel -path ($filePath + "01 - Data in\PSCODES_CRYO.xlsx") -EndColumn 4 -EndRow 57 -WorksheetName Data
$my_tags = Import-Excel -path ($filePath + "01 - Data in\PSCODES_CRYO.xlsx") -EndColumn 14 -EndRow 3 -WorksheetName Tags
#$my_recordConditions = Import-Excel -path ($filePath + "01 - Data in\PSCODES.xlsx") -EndColumn 3 -EndRow 6 -WorksheetName StartConditions
$piServerName="PHSGBO-HISCOL"
$minutes = 10
# ___________________________________________________
# local function
# ___________________________________________________
function Get-PIPoint($tagName){
try{
$pt = [OSIsoft.AF.PI.PIPoint]::FindPIPoint($global:piServer,[string]$tagName)
("TagName found: {0}" -f $tagName)
}
catch{
Write-host("Not found: {0}" -f $tagName)
}
return $pt
}
# ___________________________________________________
# data models
# ___________________________________________________
# add the data tags as columns
$simca=[PSCustomObject]@{
PIBatchId = ""
Time = ""
Unit = ""
}
Datatag array and pull column headers.
$dataTags = @()
$my_tags[1].PSObject.Properties | ForEach-Object {
if($_.Name -ne "Line"){
$dataTags += $_.Name
}
}
$dataTags | foreach{
$simca | Add-Member NoteProperty $_ ""
}
simcadata table for export data type
$simcaList = @()
# connect to PIServer using AFSDK (unlike that other connection used for AF data!)
$AFSDKAssembly = [Reflection.Assembly]::LoadWithPartialName("OSIsoft.AFSDK")
$piServers = New-Object OSIsoft.AF.PI.PIServers
$piServer = $piServers[$piServerName]
$span=New-Object OSIsoft.AF.Time.AFTimeSpan(New-TimeSpan -minutes $minutes)
# check connection
if(-not $piServer.ConnectionInfo.IsConnected){
$piServer.Connect()
}
foreach($ef in $my_variables){
write-host $ef
$currentVessel= $ef.Line
# get all events for the time period
$batchRange = New-Object OSIsoft.AF.Time.AFTimeRange($ef.StartTime, $ef.EndTime)
# set up a templist for the points