Access PI from Python
# 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)
2 Comments
→
# Print Snapshot value
pv = pi_point.Data.Snapshot
print (pv.Value)
# Print Snapshot value
pv = pi_point.Data.Snapshot
print (pv.Value)