Unitech

Using PISDK in Python: How do I access PISDK constants?

Discussion created by Unitech on Sep 9, 2011
Latest reply on Nov 22, 2018 by gregor

Hi,

 

I'm trying to retrieve data from a PI server using Python (2.5) and the following (simplified) code seems to work:

 

# Python PISDK test
import win32com.client

 

pi_sdk = win32com.client.Dispatch('PISDK.PISDK')
conn   = win32com.client.Dispatch('PISDKDlg.Connections')

 

pi_server = pi_sdk.Servers('WIN-SERVER2008') # server host name, must be configured in the "known servers table"
conn.Login(pi_server,'pidemo','',1,0)

 

# using point tag: SINUSOID (pre-configured by default in demo PI server)
pi_point = piserver.PIPoints['SINUSOID']

 

# retriving recorded data for the last 6 hours:
recorded_values = pi_point.Data.RecordedValues('*-6h','*',3,"",0,None)
time.sleep(0.1) # allow time for the call to complete.

 

print "recorded_values.Count = ", recorded_values.Count
for sample in recorded_values:
    v = sample.Value
    t = sample.TimeStamp.LocalDate
    print "Value =",v, " (timestamp =",t,")"

 

Program output:

 

>>>
recorded_values.Count =  7
Value = 4.74060535431  (timestamp = 09/09/11 08:19:44 )
Value = 0.769782066345  (timestamp = 09/09/11 08:39:52 )
Value = 3.78370571136  (timestamp = 09/09/11 09:44:52 )
Value = 24.1980323792  (timestamp = 09/09/11 10:57:52 )
Value = 85.7742614746  (timestamp = 09/09/11 13:31:22 )
Value = 96.3372421265  (timestamp = 09/09/11 14:15:52 )
Value = 96.3372421265  (timestamp = 09/09/11 14:19:44 )
>>>

 

SUCCESS! However,  I have used numbers as arguments in the .Data.RecordedValues(,,,,,) - call.  I would like to used the PISDK constants instead, with  something like:

 

bt = btAuto  # (not working)
bt = win32com.client.Constants.btAuto  # (not working)
bt = win32com.client.Constants.BoundaryTypeConstants.btAuto  # (not working)
bt= 0    # working 
fv = 3    # working
recorded_values = pi_point.Data.RecordedValues('*-6h','*', bt ,"", fv ,None)

 

But this is not working, and I haven't found documentation on how to do this. So, how do I access the SDK constants?

 

Any help would be appreciated.

 

regards Andreas østrem

 

 

 

 

Outcomes