私はPythonで作業しており、かなり単純なUSBデバイスとの間で読み書きする単純なプログラムを作成しようとしています. 私が抱えている問題は、PyWinUSB と PyUSB には必要なものがないように見えるため (デバイスに書き込もうとすると爆発する)、ctypes python モジュールと生の dll 関数を使用してゼロから作業する必要があることです。 WinUSB と SetupAPI。
関数に渡す構造体を定義する方法についての質問には答えることができましたが、現在の問題は、関数の仕様によると...まあ、私は'そのまま引用します。
"DeviceInterfaceData [out]
A pointer to a caller-allocated buffer that contains, on successful return, a
completed SP_DEVICE_INTERFACE_DATA structure that identifies an interface that meets
the search parameters. The caller must set DeviceInterfaceData.cbSize to
sizeof(SP_DEVICE_INTERFACE_DATA) before calling this function."
これらの要件を Python に変換するにはどうすればよいですか?
私が現在取り組んでいる構造クラスは次のようになります。
class _SP_DEVINFO_DATA(ctypes.Structure):
_fields_ = [("cbSize", wintypes.DWORD),
("ClassGuid", (ctypes.c_char * 16)),
("DevInst", wintypes.DWORD),
("Reserved", wintypes.LPVOID)]
def __init__(self, guid, inst):
self.cbSize = ctypes.sizeof(self)
self.ClassGuid = uuid.UUID(guid).get_bytes()
self.DevInst = (wintypes.DWORD)(inst)
self.Reserved = None
def __repr__(self):
return "_SP_DEV_INFO_DATA(cbsize={}, ClassGuid={}, DevInst={})".format(
self.cbSize, uuid.UUID(bytes=self.ClassGuid), hex(self.DevInst))
以前の質問への回答で知らされたことによると。
ありがとう。