
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
M]W                 @   sn   d dl Z d dlZd dlmZ G dd dejZdd Zedkrjx*ee D ]\Z	Z
Zedje	e
e qJW dS )	    N)list_ports_commonc                   s(   e Zd ZdZ fddZdd Z  ZS )SysFSz-Wrapper for easy sysfs access and device infoc                s  t t| j| tjj|| _d | _tjjdj	| jrrtjj
dj	| j| _tjjtjj
tjj| jd| _nd | _d | _| jdkrtjjtjj| j| _n"| jdkrtjj| j| _nd | _| jd k	rLt| j| jdd| _t| j| jdd| _| j| jd| _tjj| j| _| j| jd	| _| j| jd
| _| j| jd| _| jdkrb| j  nJ| jdkr| j| _| j| jd| _n$| jdkr| j| _tjj| j| _d S )Nz/sys/class/tty/{}/device	subsystem
usb-serialusbZidVendor   Z	idProductserialmanufacturerproduct	interfaceZpnpidZamba)r   r   )superr   __init__ospathbasenamenameZusb_device_pathexistsformatrealpathZdevice_pathjoinr   dirnameint	read_lineZvidpidZserial_numberlocationr	   r
   r   Zapply_usb_infodescriptionhwid)selfZdevice)	__class__ &/usr/lib/python3.6/list_ports_linux.pyr      s:    $


zSysFS.__init__c             G   sF   y,t tjj| }|j j }W dQ R X |S  tk
r@   dS X dS )z        Helper function to read a single line from a file.
        One or more parameters are allowed, they are joined with os.path.join.
        Returns None on errors..
        N)openr   r   r   readlinestripIOError)r   argsfliner    r    r!   r   8   s    zSysFS.read_line)__name__
__module____qualname____doc__r   r   __classcell__r    r    )r   r!   r      s   %r   c              C   sb   t j d} | jt j d | jt j d | jt j d | jt j d dd dd | D D S )	Nz
/dev/ttyS*z/dev/ttyUSB*z/dev/ttyACM*z/dev/ttyAMA*z/dev/rfcomm*c             S   s   g | ]}|j d kr|qS )platform)r   ).0infor    r    r!   
<listcomp>L   s   zcomports.<locals>.<listcomp>c             S   s   g | ]}t |qS r    )r   )r/   dr    r    r!   r1   M   s    )globextend)Zdevicesr    r    r!   comportsF   s    
r5   __main__z{}: {} [{}])r3   r   Zserial.toolsr   ZListPortInfor   r5   r)   sortedZportZdescr   printr   r    r    r    r!   <module>   s   6