Hello,
I'm hoping to find some information on using comtypes for an OPC library
I am writing (opclib on bitbucket). So far I am using pywin32
it is working ok other than some memory leaks that occur and the fact pywin32
has to be installed (not pip installable). I would like to avoid both....
In trying to use comtypes as a replacement, I find that not all the return
values are not converted as they were in pywin32.
Here is a sample:
opc_item = opc_items.GetOPCItem(ServerHandle=item_tup.server_handle)
value, quality, timestamp = opc_item.Read(Source=source)
print(value)
<comtypes.automation.LP_tagVARIANT object at 0x03380710>
The opc_item object appears to work, but when calling the method Read it
does not seem to know what the value is. I have taken a look at the generated
python to see if I can figure out how to get the real value. The Read
method is defined as follows in the file:
COMMETHOD([dispid(1610743825)], HRESULT, 'Read',
( ['in'], c_short, 'Source' ),
( ['out', 'optional'], POINTER(VARIANT), 'Value' ),
( ['out', 'optional'], POINTER(VARIANT), 'Quality' ),
( ['out', 'optional'], POINTER(VARIANT), 'TimeStamp' )),
I found a note somewhere on the net that said that referencing
value[0] of a variant would cause it to convert... if I try that I get:
print(value[0])
Traceback (most recent call last):
File "test_2.py", line 24, in <module>
main()
File "test_2.py", line 17, in main
client.read_item("_System._TotalTagCount")
File "C:\programs\python\opclib_comtypes\opclib\client.py", line 314, in
read_item
print(value[0])
File "C:\Python34\lib\site-packages\comtypes\automation.py", line 198, in
__repr__
return "VARIANT(vt=0x%x, %r)" % (self.vt, self.value)
File "C:\Python34\lib\site-packages\comtypes\automation.py", line 459, in
_get_value
raise NotImplementedError("typecode %d = 0x%x)" % (vt, vt))
NotImplementedError: typecode 10 = 0xa)
So in short my questions are:
1) How can I get the actual values returned by the Read method?
2) If I can get that working, would comtypes be able to handle passing a
1-based array without leaking memory as pywin32 does?
Thanks
Cory Lutton
------------------------------------------------------------------------------
_______________________________________________
comtypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/comtypes-users