summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzsquareplusc <cliechti@gmx.net>2015-08-13 23:11:02 +0200
committerzsquareplusc <cliechti@gmx.net>2015-08-13 23:11:02 +0200
commit49550ac0930a0f5c1ebde530394295ecf53b0fc3 (patch)
tree603f580585f56b7c18a2bb14af84d1217ce4dc05
parentcbb00b291a8690aeea9e6c507f386a6c6b049c15 (diff)
parentc7e3db60bbdf696d464c290cb1026a5945f45338 (diff)
downloadpyserial-git-49550ac0930a0f5c1ebde530394295ecf53b0fc3.tar.gz
Merge pull request #6 from hardkrash/feature/osx_32bit_num_iokit
Feature/osx 32bit num iokit
-rw-r--r--serial/tools/list_ports_osx.py42
1 files changed, 41 insertions, 1 deletions
diff --git a/serial/tools/list_ports_osx.py b/serial/tools/list_ports_osx.py
index a451ae6..939ede4 100644
--- a/serial/tools/list_ports_osx.py
+++ b/serial/tools/list_ports_osx.py
@@ -66,6 +66,15 @@ cf.CFStringGetCStringPtr.restype = ctypes.c_char_p
cf.CFNumberGetValue.argtypes = [ctypes.c_void_p, ctypes.c_uint32, ctypes.c_void_p]
cf.CFNumberGetValue.restype = ctypes.c_void_p
+
+class HexInt(int):
+
+ """Class to pretty print a integer in a hex representation."""
+
+ def __repr__(self):
+ return "0x{0:X}".format(self)
+
+
def get_string_property(device_t, property):
""" Search the given device for the specified string property
@@ -117,8 +126,39 @@ def get_int_property(device_t, property):
if CFContainer:
output = cf.CFNumberGetValue(CFContainer, 2, ctypes.byref(number))
+ # The Number 2 is defined as kCFNumberSInt16Type in MacTypes.h
+
+ return HexInt(number.value)
+
+
+def get_int32_property(device_t, property):
+ """ Search the given device for the specified string property
+
+ @param device_t Device to search
+ @param property String to search for.
+ @return Python string containing the value, or None if not found.
+ """
+ key = cf.CFStringCreateWithCString(
+ kCFAllocatorDefault,
+ property.encode("mac_roman"),
+ kCFStringEncodingMacRoman
+ )
+
+ CFContainer = iokit.IORegistryEntryCreateCFProperty(
+ device_t,
+ key,
+ kCFAllocatorDefault,
+ 0
+ )
+
+ number = ctypes.c_uint32()
+
+ if CFContainer:
+ output = cf.CFNumberGetValue(CFContainer, 3, ctypes.byref(number))
+ # The Number 3 is defined as kCFNumberSInt32Type in MacTypes.h
+
+ return HexInt(number.value)
- return number.value
def IORegistryEntryGetName(device):
pathname = ctypes.create_string_buffer(100) # TODO: Is this ok?