a CXV$@s,ddlZddlZddlmZejejdZejejdZ ej edZ ej e dZ dZej ej_ej ej ej gej_ej ej_ej ej ej gej_ej ej ej ejgej_ej ej_ej ej ej gej_ej ej_ej ej gej_ej ej_ej ej gej_ej ej_ej gej_ej ejejge j_ej e j_ej ejge j_eje j_ej ejej ge j_ej e j_ej ge j_de j_dZ dZ!d Z"d Z#d d Z$d dZ%ddZddZ&ddZ'ddZ(Gddde)Z*ddZ+ddZ,d"ddZ-e.d kr(e/e-D]\Z0Z1Z2e3d!4e0e1e2qdS)#N)list_ports_commonZIOKitZCoreFoundationkIOMasterPortDefaultkCFAllocatorDefaultcCsXtt|dt}t||td}d}|rTt|d}|durJ|d}t ||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. mac_romanrN) cfCFStringCreateWithCStringrencodekCFStringEncodingMacRomaniokitIORegistryEntryCreateCFPropertyCFStringGetCStringPtrdecode CFRelease) device_typepropertykey CFContaineroutputr?/usr/lib/python3.9/site-packages/serial/tools/list_ports_osx.pyget_string_propertyOs$   rcCsrtt|dt}t||td}|rn|tkr:t }n|t krJt }t ||t |t||jSdS)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 rN)r r rr r rrkCFNumberSInt32Typectypesc_uint32kCFNumberSInt16TypeZc_uint16CFNumberGetValuebyrefrvalue)rrZcf_number_typerrZnumberrrrget_int_propertyks(   r"cCs"td}t|t||jS)Nd)rZcreate_string_bufferrIOObjectGetClassr r!)devicepathnamerrrIORegistryEntryGetNames r'cCsN|d}t||krJt}t|ddt|}|dkrDdS|}q |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 Z IOServicerN)r r'rc_void_prIORegistryEntryGetParentEntryr )r%Z parent_typeparentZresponserrrGetParentDeviceByTypes  r+cCs`t}ttt|dt|g}t|rRt |}|sFqR| |q,t ||S)z6 returns iterator over specified service_type r ) rr(rIOServiceGetMatchingServicesrIOServiceMatchingr r ZIOIteratorIsValidZIOIteratorNextappendIOObjectRelease)Z service_typeZserial_port_iteratorservicesservicerrrGetIOServicesByTypes    r2cCsZd|d?g}|d@rPt|dkr.|d|d|d?d@|d K}qd |S) zA helper to calculate port and bus number from locationID z{}-ir.z{}r)formatlenr.join) locationIDlocrrrlocation_to_strings   r=c@s eZdZdS)SuitableSerialInterfaceN)__name__ __module__ __qualname__rrrrr>sr>cCslg}tdD]Z}t|d}|r t|d}|r t|dp8d}t|dtpHd}t}||_||_||q |S)z helper function to scan USB interfaces returns a list of SuitableSerialInterface objects with name and id attributes IOSerialBSDClientIOCalloutDeviceZIOUSBInterfacezUSB Interface NameNr;r7) r2rr+r"rr>idnamer.)Z interfacesr1r% usb_devicerEr;irrrscan_interfacess    rHcCs"|D]}|j|kr|jSqdS)N)rDrE)serial_interfacesr; interfacerrr#search_for_locationID_in_interfacess  rKFc Cstd}g}t}|D]}t|d}|rt|}t|d}|rt|dt|_t|dt|_ t|d|_ t|dptd|_ t|d |_ t|d t }t||_t|||_|||q|S) NrBrCZ IOUSBDeviceZidVendorZ idProductzUSB Serial NumberzUSB Product Namezn/azUSB Vendor Namer;)r2rHrrZ ListPortInfor+r"rZvidpidZ serial_numberproductZ manufacturerrr=locationrKrJZapply_usb_infor.) Z include_linksr0ZportsrIr1r%inforFr;rrrcomportss(         rP__main__z {}: {} [{}])F)5rZ ctypes.utilZ serial.toolsrZcdllZ LoadLibraryutilZ find_libraryrr r(Zin_dllrrr r-Zrestyper,argtypesr)rrZIORegistryEntryGetPathr'r$r/Zc_char_pZc_int32r rrrZkCFNumberSInt8TyperrZkCFNumberSInt64Typerr"r+r2r=objectr>rHrKrPr?sortedportZdescZhwidprintr8rrrrsZ