I'm working with Python and trying to talk to this simple USB device using WinUSB (from Microsoft). I'm having a problem since in order to find the device, calling the setupAPI function SetupDiEnumDeviceInterfaces takes a struct object, which I defined as a class:
class _SP_DEVINFO_DATA:
def __init__(self, ClassGUID, DevInst = ""):
'''flags = SPINT_DEFAULT, SPINT_REMOVED, or SPINT_ACTIVE'''
self._ClassGUID = None
self._DevInst = None
self._Reserved = None
self._cbSize = None
###Getters:
def getClassGUID(self):
return self._ClassGUID
def getDevInst(self):
return self._DevInst
def getReserved(self):
return self._Reserved
def getcbSize(self):
return self._cbSize
###Setters:
def setClassGUID(self, value):
self._ClassGUID = value
def setDevInst(self, value):
self._DevInst = value
def setReserved(self, value):
self._Reserved = value
def setcbSize(self):
self._cbSize = sys.getsizeinfo(self)
ClassGUID = property(getClassGUID, setClassGUID, None, "Class GUID")
DevInst = property(getDevInst, setDevInst, None, "Device Instance")
Reserved = property(getReserved, setReserved, None, "RESERVED: DO NOT USE")
cbSize = property(getcbSize, setcbSize, None, "CB Size. Set automatically")
I tried using the property because it gave me the error :
<type 'exceptions.TypeError'>: Don't know how to convert parameter
otherwise, and I'd read that defining parameters like this would resolve the problem, but it doesn't, and I'm not certain what to do here.
I want to use WinUSB because I only need to read from the device and write to the device, and that's it, and WinUSB seems to have what I need, but until I can get past this problem, I'm kind of stuck
Any suggestions? How do I pass a class object to a DLL function loaded with ctypes.windll.LoadLibrary(DLL)?
And if there's an easier way to do this, I'm all for that too.
Thanks.