Hello,
I posted this email to the win32 list as well, I’m not sure which is the correct place. Anyhow,
I’m getting in a bit over my head here and need some help. I’m having problems with a wxpython application that runs a thread in the background. The thread is supposed to read and write data to/from an OPC server - which I use to communicate to a PLC (programmable logic controller, for process automation). The thread works well, the program works well, and my OPC module works well for reading and writing to the OPC server when it is not used from within the thread. If I call a read or write or actually any function from my OPC mudule it fails. Here’s the code I use from within my thread:
connect to server
opcServerName = ‘the server name goes here’
opcItemName = ‘the opc item goes here’
(server, group) = myOPC.connectServer(opcServerName)
item
= myOPC.addItem(opcItemName, group)
value = myOPC.readItemValue(item)
the value return a tuple of info including a value and timestamp and quality
Here’s the error that’s returned:
line 124, in readItemValue
return opcItem.Read(0x1)
File “”, line 3, in Read
File “C:\Python25\lib\site-packages\win32com\client\dynamic.py”, line 258, in ApplyTypes
result = self.oleobj.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
com_error: (-2147352567, ‘Exception occurred.’, (0, None, None, None, 0, -2147221008), None)
I attached my OPC module, if its important to include the wxapp I can do that to, but it’s pretty apparent that the problem only happens when I call my OPC funcitons from within the thread…
I suppose its also
worthwhile to mention that I need to access the OPC module from within a thread (thats not the main applications thread) because I’m trying to aquire data from a PLC and I want to do that continuously and not lock up my program.
Any ideas on how I might get this thing to work within the thread? Thanks!
Jeff
myOPC.py (4.62 KB)