[python-win32] Problem with Dispatch in normal Python shell

Mark Hammond skippy.hammond at gmail.com
Mon Dec 19 22:29:41 CET 2011


I'm afraid it looks like the object itself has a problem when running 
outside a GUI environment.  You might like to see if you can use Windows 
Scripting Host (cscript.exe) to load the object but I suspect that might 
fail in the same way.  If so, your best bet might be to talk to the vendor.

Mark

On 17/12/2011 2:25 AM, Marco Nawijn wrote:
> Dear All,
>
> I hope someone can assist me with a dispatch problem that I am facing.
> Let me briefly explain my case. I am implementing a monitoring and
> reporting application for one of our manufacturing machines. I use the
> COM interface provided by the PLC manufacturer (Siemens). Since it is
> a long running program and the PythonWin GUI becomes sort of
> unresponsive I would like to run the data extraction operation through
> a normal Python shell (DOS/PowerShell terminal). The problem that I
> face is that I cannot dispatch the automation object through the
> normal Python shell (see traceback below). It works fine in the
> interactive PythonWin console (see at the bottom of the post). I would
> be very gratefull if someone can provide me with some hints on how to
> solve this problem. Maybe somebody knows the difference in running an
> interactive console or a normal Python shell?
>
> I have been struggling with the issue for a few days now. It is
> becoming quite urgent now, because we are required to log the
> manufacturing data on a higher rate than we do now. We have a tool
> implemented in VB, but is is completely hardcoded to only run at a one
> minute time interval. We would like to be more flexible, but use
> Python to do so.
>
> Thanks in advance,
>
> Marco
>
>
>
> Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win
> 32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from win32com.client import Dispatch
>>>> server = Dispatch('OPC.Automation.1')
> Traceback (most recent call last):
>    File "<stdin>", line 1, in<module>
>    File "c:\python27\lib\site-packages\win32com\client\__init__.py", line 95, in
> Dispatch
>      dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,c
> lsctx)
>    File "c:\python27\lib\site-packages\win32com\client\dynamic.py", line 108, in
> _GetGoodDispatchAndUserName
>      return (_GetGoodDispatch(IDispatch, clsctx), userName)
>    File "c:\python27\lib\site-packages\win32com\client\dynamic.py", line 85, in _
> GetGoodDispatch
>      IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.II
> D_IDispatch)
> pywintypes.com_error: (-2147023898, 'Invalid access to memory location.', None,
> None)
>
>
>
> PythonWin 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit
> (Intel)] on win32.
> Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin'
> for further copyright
> information.
>
>>>> from win32com.client import Dispatch
>
>>>> server = Dispatch('OPC.Automation.1')
>
>>>> print server
>
> <win32com.gen_py.OPC DA Automation Wrapper 2.02.IOPCGroups instance at
> 0x16331400>
>
>>>>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32



More information about the python-win32 mailing list