
    1_+                        d dl mZ d dlZd dlmZ ej
                  j                  d      Zej
                  j                  d      Zd Z	ej                  j                  ed      Zd ZdZdZd	Zd
Zd Zej&                  Zej                  ej*                  _        ej                  ej                  ej                  gej.                  _        eej.                  _        ej                  ej                  ej                  gej2                  _        eej.                  _        ej                  ej                  ej                  ej4                  gej6                  _        ej                  ej6                  _        ej                  ej                  ej                  gej8                  _        eej8                  _        ej                  ej                  gej:                  _        eej:                  _        ej                  ej                  gej<                  _        eej<                  _        ej                  gej>                  _        ej                  ej@                  ejB                  gejD                  _        ej                  ejD                  _        ej                  ej4                  gejF                  _        ej@                  ejF                  _        ej                  ej                  ejH                  ej4                  gejJ                  _        ejL                  ejJ                  _        ej                  ej4                  ej                  gejN                  _        ej                  ejN                  _        ej                  gejP                  _        dejP                  _        dZ)dZ*dZ+dZ,d Z-d Z.d Zd Zd Z/d Z0d Z1 G d de2      Z3d Z4d Z5ddZ6e7dk(  r0 e8 e6             D ]  \  Z9Z:Z; e<dj{                  e9e:e;             ! yy)    )absolute_importN)list_ports_commonz0/System/Library/Frameworks/IOKit.framework/IOKitzB/System/Library/Frameworks/CoreFoundation.framework/CoreFoundationkCFAllocatorDefaulti  zUSB Vendor NamezUSB Serial Number               c                    t         j                  t        |j                  d      t              }t
        j                  | |t        d      }d}|rt         j                  |d      }||j                  d      }nit        j                  t              }t         j                  |t        j                  |      t        t              }|r|j                  j                  d      }t         j                  |       |S )z
    Search the given device for the specified string property

    @param device_type Type of Device
    @param property String to search for
    @return Python string containing the value, or None if not found.
    utf-8r   N)cfCFStringCreateWithCStringr   encodekCFStringEncodingUTF8iokitIORegistryEntryCreateCFPropertyCFStringGetCStringPtrdecodectypescreate_string_bufferio_name_sizeCFStringGetCStringbyrefvalue	CFRelease)device_typepropertykeyCFContaineroutputbuffersuccesss          =/usr/lib/python3/dist-packages/serial/tools/list_ports_osx.pyget_string_propertyr$   c   s     
&
&OOG$!#C
 77	K
 F))+q9]]7+F00>F++Kf9M|]rsG,,W5
[!M    c                    t         j                  t        |j                  d      t              }t
        j                  | |t        d      }|r|t        k(  rt        j                         }n|t        k(  rt        j                         }t         j                  ||t        j                               t         j                  |       |j                  S y)a  
    Search the given device for the specified string property

    @param device_type Device to search
    @param property String to search for
    @param cf_number_type CFType number

    @return Python string containing the value, or None if not found.
    r   r   N)r   r   r   r   r   r   r   kCFNumberSInt32Typer   c_uint32kCFNumberSInt16Typec_uint16CFNumberGetValuer   r   r   )r   r   cf_number_typer   r   numbers         r#   get_int_propertyr.      s     
&
&OOG$!#C
 77	K 11__&F 33__&F
Kf9MN
[!||r%   c                     t        j                  t              }t        j	                  | t        j
                  |            }|t        k7  ry |j                  j                  d      S )Nr   )	r   r   r   r   IORegistryEntryGetNamer   KERN_SUCCESSr   r   )device
devicenameress      r#   r0   r0      sQ    ,,\:J

&
&vv||J/G
HC
l ""7++r%   c                     t        j                  t              }t        j	                  | t        j
                  |             |j                  S N)r   r   r   r   IOObjectGetClassr   r   )r2   	classnames     r#   r7   r7      s5    ++L9I	66<<	#:;??r%   c                    |j                  d      }t        |       |k7  rht        j                         }t        j                  | dj                  d      t        j                  |            }|t        k7  ry|} t        |       |k7  rh| S )z Find the first parent of a device that implements the parent_type
        @param IOService Service to inspect
        @return Pointer to the parent type, or None if it was not found.
    r   	IOServiceN)r   r7   r   c_void_pr   IORegistryEntryGetParentEntryr   r1   )r2   parent_typeparentresponses       r#   GetParentDeviceByTyper@      s     $$W-K
6
"k
1"66""7+V$&
 |# 6
"k
1 Mr%   c                    t        j                         }t        j                  t        t        j                  | j                  d            t        j                  |             g }t        j                  |      r?t        j                  |      }|sn'|j                  |       t        j                  |      r?t        j                  |       |S )z6
    returns iterator over specified service_type
    r   )r   r;   r   IOServiceGetMatchingServiceskIOMasterPortDefaultIOServiceMatchingr   r   IOIteratorIsValidIOIteratorNextappendIOObjectRelease)service_typeserial_port_iteratorservicesservices       r#   GetIOServicesByTyperM      s     "??,	&& ##L$7$7$@ALL-.0
 H

!
!"6
7&&';< 	 
!
!"6
7
 
./Or%   c                     dj                  | dz	        g}| dz  rPt        |      dkD  r|j                  d       |j                  dj                  | dz	  dz               | d	z  } | dz  rPd
j                  |      S )zA
    helper to calculate port and bus number from locationID
    z{}-   i   r   .z{}      r
    )formatlenrG   join)
locationIDlocs     r#   location_to_stringrY      s{     <<
b()
*C
x
s8a<JJsO

4;;
b 0C789q
	 x

 773<r%   c                       e Zd Zy)SuitableSerialInterfaceN)__name__
__module____qualname__ r%   r#   r[   r[      s    r%   r[   c                     g } t        d      D ]n  }t        |d      }|st        |d      }|s!t        |d      xs d}t        |dt              xs d}t               }||_        ||_        | j                  |       p | S )z
    helper function to scan USB interfaces
    returns a list of SuitableSerialInterface objects with name and id attributes
    IOSerialBSDClientIOCalloutDeviceIOUSBInterfacezUSB Interface NameNrW   rS   )	rM   r$   r@   r.   r'   r[   idnamerG   )
interfacesrL   r2   
usb_devicere   rW   is          r#   scan_interfacesri      s    
 J&':; 
%$W.?@.w8HIJ*:7KLTPT-j,H[\b`b
+-!!!!$
% r%   c                 L    | D ]  }|j                   |k(  s|j                  c S  y r6   )rd   re   )serial_interfacesrW   	interfaces      r#   #search_for_locationID_in_interfacesrm      s,    & "	LLJ&>>!" r%   c                 @   t        d      }g }t               }|D ]   }t        |d      }|st        j                  |      }t        |d      }|st        |d      }|rt        |dt              |_        t        |dt              |_	        t        |t              |_        t        |      xs d|_        t        |t              |_        t        |dt               }t#        |      |_        t'        ||      |_        |j+                          |j-                  |        |S )	Nra   rb   IOUSBHostDeviceIOUSBDeviceidVendor	idProductzn/arW   )rM   ri   r$   r   ListPortInfor@   r.   r)   vidpidkUSBSerialNumberStringserial_numberr0   productkUSBVendorStringmanufacturerr'   rY   locationrm   rl   apply_usb_inforG   )	include_linksrK   portsrk   rL   r2   inforg   rW   s	            r#   comportsr     s    ##67HE') $W.?@$11&9D /w8IJJ27MJ
+J
DWX+JEXY%8E[%\"  6jAJU$7
DT$U!-j,H[\
 2: >!DEVXb!c##%LL34 Lr%   __main__z{}: {} [{}])F)>
__future__r   r   serial.toolsr   cdllLoadLibraryr   r   rC   r;   in_dllr   kCFStringEncodingMacRomanr   ry   rv   r   r1   c_intkern_return_trD   restyperB   argtypesr<   r(   r   IORegistryEntryGetPathr0   r7   rH   c_char_pc_int32r   r   c_longr   c_boolr+   r   kCFNumberSInt8Typer)   r'   kCFNumberSInt64Typer$   r.   r@   rM   rY   objectr[   ri   rm   r   r\   sortedportdeschwidprintrT   r_   r%   r#   <module>r      se  0 '  * RS[[ab  oo,,R1FG  "  % ,   "(//   /5QWQ`Q`.a " " +-: " " *06RXRaRa/b # # ,-: " " *28//6??TZTcTceketet1u % % .06 % % -)/&//6??([   %'4   $)/&//(J   %'4   $#)??FOO"D   !.   "(//!2    *0&//6>>(Z   %'-   $%+__foo$F   !#)??    "(//6??FMMSYSbSb!c    &    &&//R   $oo     )       B>,
(*
	f 	( F z"8:. 6dDm""4t456 r%   