Skip to content

Access PI from Python

by admin on November 13th, 2011

# Python PISDK test on Python 3.x
# Install Python extension for Windows

import win32com.client
import time

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

pi_server = pi_sdk.Servers('my_pi_server') # PI server or collective name
conn.Login(pi_server,'pidemo','',1,0)

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

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

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

# Print Snapshot value
pv = pi_point.Data.Snapshot
print (pv.Value)

From → PI, Python

2 Comments
  1. Admin permalink

    # Print Snapshot value
    pv = pi_point.Data.Snapshot
    print (pv.Value)

  2. # Print Snapshot value
    pv = pi_point.Data.Snapshot
    print (pv.Value)

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS