diff options
author | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2011-08-25 01:24:49 +0000 |
---|---|---|
committer | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2011-08-25 01:24:49 +0000 |
commit | a5d98897ab9eb043f15f5ed0aceb5dae0cd42965 (patch) | |
tree | c3e8305baf91d7e7518b32e9bd9cb116c8a83e83 | |
parent | 128072f37ad078447d88d8ca640ca713f35b9793 (diff) | |
download | pyserial-a5d98897ab9eb043f15f5ed0aceb5dae0cd42965.tar.gz |
apply patch from cjgohlke, add is_64bit detection function
git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@430 f19166aa-fa4f-0410-85c2-fa1106f25c8a
-rw-r--r-- | serial/tools/list_ports_windows.py | 23 | ||||
-rw-r--r-- | serial/win32.py | 13 |
2 files changed, 23 insertions, 13 deletions
diff --git a/serial/tools/list_ports_windows.py b/serial/tools/list_ports_windows.py index 92a9406..e4e822c 100644 --- a/serial/tools/list_ports_windows.py +++ b/serial/tools/list_ports_windows.py @@ -1,13 +1,13 @@ import ctypes
import re
-def ValidHandle(value):
+def ValidHandle(value, func, arguments):
if value == 0:
raise ctypes.WinError()
return value
import serial
-from serial.win32 import ULONG_PTR
+from serial.win32 import ULONG_PTR, is_64bit
from ctypes.wintypes import HANDLE
from ctypes.wintypes import BOOL
from ctypes.wintypes import HWND
@@ -46,10 +46,11 @@ def string(buffer): class GUID(ctypes.Structure):
_fields_ = [
- ('Data1', ctypes.c_ulong),
- ('Data2', ctypes.c_ushort),
- ('Data3', ctypes.c_ushort),
- ('Data4', ctypes.c_ubyte*8),
+ ('Data1', DWORD),
+ ('Data2', WORD),
+ ('Data3', WORD),
+ ('Data4', BYTE*8),
+),
]
def __str__(self):
return "{%08x-%04x-%04x-%s-%s}" % (
@@ -91,7 +92,8 @@ SetupDiDestroyDeviceInfoList.restype = BOOL SetupDiGetClassDevs = setupapi.SetupDiGetClassDevsA
SetupDiGetClassDevs.argtypes = [ctypes.POINTER(GUID), PCTSTR, HWND, DWORD]
-SetupDiGetClassDevs.restype = ValidHandle #HDEVINFO
+SetupDiGetClassDevs.restype = HDEVINFO
+SetupDiGetClassDevs.errcheck = ValidHandle
SetupDiEnumDeviceInterfaces = setupapi.SetupDiEnumDeviceInterfaces
SetupDiEnumDeviceInterfaces.argtypes = [HDEVINFO, PSP_DEVINFO_DATA, ctypes.POINTER(GUID), DWORD, PSP_DEVICE_INTERFACE_DATA]
@@ -120,7 +122,7 @@ RegQueryValueEx.restype = LONG GUID_CLASS_COMPORT = GUID(0x86e0d1e0L, 0x8089, 0x11d0,
- (ctypes.c_ubyte*8)(0x9c, 0xe4, 0x08, 0x00, 0x3e, 0x30, 0x1f, 0x73))
+ (BYTE*8)(0x9c, 0xe4, 0x08, 0x00, 0x3e, 0x30, 0x1f, 0x73))
DIGCF_PRESENT = 2
DIGCF_DEVICEINTERFACE = 16
@@ -165,7 +167,10 @@ def comports(): def __str__(self):
return "DevicePath:%s" % (self.DevicePath,)
idd = SP_DEVICE_INTERFACE_DETAIL_DATA_A()
- idd.cbSize = 5
+ if is_64bit():
+ idd.cbSize = 8
+ else:
+ idd.cbSize = 5
devinfo = SP_DEVINFO_DATA()
devinfo.cbSize = ctypes.sizeof(devinfo)
if not SetupDiGetDeviceInterfaceDetail(g_hdi, ctypes.byref(did), ctypes.byref(idd), dwNeeded, None, ctypes.byref(devinfo)):
diff --git a/serial/win32.py b/serial/win32.py index eaa31f3..61b3d7a 100644 --- a/serial/win32.py +++ b/serial/win32.py @@ -10,15 +10,20 @@ from ctypes.wintypes import BYTE INVALID_HANDLE_VALUE = HANDLE(-1).value +# some details of the windows API differ between 32 and 64 bit systems.. +def is_64bit(): + """Returns true when running on a 64 bit system""" + return sizeof(c_ulong) != sizeof(c_void_p) + # ULONG_PTR is a an ordinary number, not a pointer and contrary to the name it # is either 32 or 64 bits, depending on the type of windows... # so test if this a 32 bit windows... -if sizeof(c_ulong) == sizeof(c_void_p): - # 32 bits - ULONG_PTR = c_ulong -else: +if is_64bit(): # assume 64 bits ULONG_PTR = c_int64 +else: + # 32 bits + ULONG_PTR = c_ulong class _SECURITY_ATTRIBUTES(Structure): |