[python-win32] Access to PI-db from Python :

FJ fjanoos at yahoo.com
Mon Jan 14 21:28:26 CET 2013


Hello,
 
 
I've been write some code to access a PI system (OSI soft) database from Python code and I keep running into a "Python instance can not be converted to a COM object" error everytime I try to access a method on the PI COM objects.
 
Specifically, I followed the example from http://oracleabc.com/b/archives/2850 as :
 
 importwin32com.clientimportpythoncomimporttime
 pi_sdk 
pi_time_start =win32com.client.Dispatch('PISDK.PISDK')=win32com.client.Dispatch('PITimeServer.PITime')pi_time_end =win32com.client.Dispatch('PITimeServer.PITime')win32com.client.Dispatch('PISDKCommon.NamedValues')pi_server =pi_sdk.Servers('myservername')# PI server or collective name pi_server.Open();pi_pt pi_data =pi_pt.Data;
 print# This read only property returns the most recent value stored on the server for the associated PIPoint as a PIValue object.pi_pt.Data.Snapshot();
 
 
 
 
>> 0.0756051763892
 # PIData methods returns a reference to a single PIValue object from the server for the associated PIPoint based on the passed time and mode. Accepts a VT_BSTR argumentpi_data
 > ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
> file://pythonapplication1/%3Cipython-input-34-a8bfc6a08db7> in <module>()
> ----> 1 pi_data.ArcValue("10-JAN-2013 1:00:00.")
> C:\ProgramData\Python27\lib\site-packages\win32com\gen_py\0EE075CE-8C31-11D1-BD73-0060B0290178x0x1x1.pyc in > ArcValue(sel
> f, TimeStamp, Mode, asynchStatus)
>    8039                 'Retrieve a single value from the server based on the input time and retrieval type.'
>    8040                 ret = self._oleobj_.InvokeTypes(9, LCID, 1, (9, 0), ((12, 1), (3, 1), (9, 49)),TimeStamp
> -> 8041                         , Mode, asynchStatus)
>    8042                 if ret is not None:
>    8043                         ret = Dispatch(ret, u'ArcValue', '{F293A839-D998-11D3-853F-00C04F45D1DA}')
> TypeError: The Python instance can not be converted to a COM object
> > c:\programdata\python27\lib\site-packages\win32com\gen_py\0ee075ce-8c31-11d1-bd73-0060b0290178x0x1x1.py(8041)> ArcValue(
> )
>    8040                 ret = self._oleobj_.InvokeTypes(9, LCID, 1, (9, 0), ((12, 1), (3, 1), (9, 49)),TimeStamp
> -> 8041                         , Mode, asynchStatus)
>    8042                 if ret is not None:
 
As this code-snippet shows, calling a property on the object works fine, but calling *any* method consistently throws the "The Python instance can not be converted to a COM object" error.

I don't have much (any) experience using COM / OLE / ODBC in Python and any help would be appreciated.
 
Environment:
Python 2.7.3 (32-bit, EPD) with pywin32 build 218 (32-bit) .
Windows 7, 64-bit
 
Thanks,
-fj .ArcValue("10-JAN-2013 1:00:00.")=pi_server.PIPoints.Item('mytag');
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20130114/8ead3370/attachment.html>


More information about the python-win32 mailing list