YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Using PI-SDK with Python Options · View
APerson
#1 Posted : Thursday, January 26, 2012 8:26:54 PM
Rank: Newbie
Groups: Member

Joined: 1/26/2012
Posts: 3
Location: Hometown
Has anyone used Python to connect to PI? I am able to get connected to the database using this code:

Code:
import win32com.client
import time

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

pi_server = pi_sdk.Servers('pi-server') # PI server or collective name
conn.Login(pi_server,'pi_user','pi_pass',1,0)


However, at that point, I can't seem to query. For example:
Code:
### Attempt at a query
db_cmd = """tag LIKE 'NEWTA001%'"""
rec_vals = pi_server.GetPointsSQL(db_cmd)


This returns the following error:
Code:
    rec_vals = pi_server.GetPointsSQL(db_cmd)
  File "<COMObject <unknown>>", line 3, in GetPointsSQL
TypeError: The Python instance can not be converted to a COM object


Can anyone help?
Sponsor  
 

OSIsoft vCampus is a subscription-based, online offering that consists of providing everything people need to develop applications on the PI System.
We invite you to take a "tour" of the OSIsoft Virtual Campus - also feel free to consult the FAQ  or contact OSIsoft vCampus for more details.
zfima
#2 Posted : Thursday, January 26, 2012 9:21:37 PM
Rank: Advanced Member

Groups: Member

Joined: 11/13/2011
Posts: 77
Location: Middle East
Hello
I was never develop under Python for PI, but i found some information, how to get points: here
APerson
#3 Posted : Thursday, January 26, 2012 9:27:00 PM
Rank: Newbie
Groups: Member

Joined: 1/26/2012
Posts: 3
Location: Hometown
That's useful. Thank you.

Do you know how I'd modify the code to do a more complex query? This looks like it's just pulling a single tag. I actually have a query like this:

Code:
select c.tag, c.time, c.value, i.tag, i.value
    from piarchive..picomp2 c
    inner join piarchive..piinterp2 i
    on i.time = c.time
    where c.tag = 'NEWTA001_QRYS (142)'
    and c.time BETWEEN '01-JAN-2012' and '10-JAN-2012'
    and i.tag ='NEWTA009_CPU'
zfima
#4 Posted : Sunday, January 29, 2012 9:03:52 AM
Rank: Advanced Member

Groups: Member

Joined: 11/13/2011
Posts: 77
Location: Middle East
Hello, APerson

With GetPoints method, you can do simple queries. With GetPointsSQL query can by more complex. But, if python can not work with GetPointsSQL method, you can not use it.

With GetPoints you can build query, like
(x AND y) OR (z AND t AND p) OR ... etc.
You can write query, like:
Code:
PointList points = _piServer.GetPoints("changedate > '21-Dec-2011 15:52:30' AND tag = 'b*'");

Maybe, it will enough for Your needs, i don't know...

Differences (from pisdk.chm ver1.3.6):

GetPoints vs. GetPointsSQL

GetPointsSQL can implement complex queries, including joins with other PI tables. GetPoints cannot do such complex queries, but it is faster, and can use custom point attributes, which GetPointsSQL cannot. To convert between equivalent GetPoints and GetPointsSQL queries, note that GetPointsSQL uses attribute names as defined by PI ODBC, but GetPoints uses attribute names as defined internally in the PI Point Database. These names differ in some instances.

If no points are found by this method it returns an empty PointList collection. The Server.GetPointsSQL returns an error of pseNoPointsFound in this case.

Tell, if you can use GetPoints

Good luck

Kind Regards,
Efim
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.