imuehlenhoff

Using PI-SDK method 'RecordedValues' and/or 'ArcValue' in Powershell.

Discussion created by imuehlenhoff on Feb 10, 2012
Latest reply on Apr 18, 2016 by gregor

Hi there, I'm new with PowerShell: I'm trying to figure out how to use PI-SDK objects and methods in PowerShell.
Therefore I wrote a little ps-script to get some snapshots and archive values from PI-SDK.
I have no problem to get values from sinusoid's Snapshot property.
But I don't know, how to call the SDK-Methods RecordedValues() or ArcValue() correctly.
I tested several different combinations of arguments. Most attempts leaded to "Type mismatch" errors.  

Here is the script and its output: Has anybody an idea?:

 

[reflection.assembly]::loadwithpartialname("OSIsoft.PISDK") | out-null
$pisdk = new-object PISDK.PISDKClass;
 
$myTagName = 'Sinusoid'
write-host "Snapshot-Value for Tag:" $myTagName
$srv = $pisdk.Servers.DefaultServer
write-host -foregroundcolor Blue "My default PI-Server: " $srv.Name
$myPIPoint = $srv.PIPoints.Item($myTagName)
$myPIValue1 = $myPIPoint.Data.Snapshot
write-host -foregroundcolor Green $myTagName '-Snapshot:' $myPIValue1.Value','$myPIValue1.TimeStamp.LocalDate

write-host 'Archive-values for'$myTagName ':'
$btType = [PISDK.BoundaryTypeConstants]::btInside
write-host "My BoundaryTypeConstant =" $btType  ## Test this enumeration-type...
$rtType = [PISDK.RetrievalTypeConstants]::rtAtOrBefore
write-host "My RetrievalTypeConstant =" $rtType ## Test this enumeration-type...
$et = get-date   ## get Endtime "now()"
$st = $et.date   ## get Starttime "end()"
write-host 'My Timerange:' $st ';' $et

## So far so good: Up to this point my little script works as expected.


$myPIValue2 = $myPIPoint.Data.ArcValue('*',[PISDK.RetrievalTypeConstants]::rtAtOrBefore)

 

##$myPIValue2 = $myPIPoint.Data.ArcValue("*",[PISDK.RetrievalTypeConstants]::rtAtOrBefore,[void]$Null)
##$myPIValue2 = $myPIPoint.Data.ArcValue($et,[PISDK.RetrievalTypeConstants]::rtAtOrBefore,[void]$Null)

##Write Archive-Value:
##write-host -foregroundcolor Green $myTagName ':' $myPIValue2.Value','$myPIValue2.TimeStamp.LocalDate

 

$myPIValues = $myPIPoint.Data.RecordedValues('T','*',0,'1')

 

##$myPIValues = $myPIPoint.Data.RecordedValues('01.02.2012','02.02.2012',0,'1',1,0)
##$myPIValues = $myPIPoint.Data.RecordedValues($st,$et,[OSIsoft.PISDK.BoundaryTypeConstants]::btInside,"1",True,False)
##$myPIValues = $myPIPoint.Data.RecordedValues($st,$et,[PISDK.BoundaryTypeConstants]::btInside,"1",1,0)

##Write Archive-Valus:
##foreach( $myPIValue3 in $myPIValues ){
## write-host -foregroundcolor Green $myTagName ':' $myPIValue3.Value',' $myPIValue3.TimeStamp.LocalDate
##}


==> Script-output:
Snapshot-Value for Tag: Sinusoid
My default PI-Server:  PICollective
Sinusoid -Snapshot: 1,820472 , 10.02.2012 08:28:59
Archive-values for Sinusoid :
My BoundaryTypeConstant = btInside
My RetrievalTypeConstant = rtAtOrBefore
My Timerange: 10.02.2012 00:00:00 ; 10.02.2012 08:33:44

Exception calling "ArcValue" with "2" argument(s): "Type mismatch. (Exception from HRESULT: 0x80020
005 (DISP_E_TYPEMISMATCH))"
At C:\Documents and Settings\muehlenh\Desktop\PowerShellTestScript2.ps1:38 char:39
+ $myPIValue2 = $myPIPoint.Data.ArcValue <<<< ('*',[PISDK.RetrievalTypeConstants]::rtAtOrBefore)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

Exception calling "RecordedValues" with "4" argument(s): "Type mismatch. (Exception from HRESULT: 0
x80020005 (DISP_E_TYPEMISMATCH))"
At C:\Documents and Settings\muehlenh\Desktop\PowerShellTestScript2.ps1:45 char:45
+ $myPIValues = $myPIPoint.Data.RecordedValues <<<< ('T','*',0,'1')
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

Outcomes