PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB`  7Tc@sdZdZdddddgZddljZddlZddlZddljZddl Z e j d Z d Z d Z d efd YZdefdYZdefdYZdefdYZdefdYZdefdYZeeedZdS(s=usb.core - Core USB features. This module exports: Device - a class representing a USB device. Configuration - a class representing a configuration descriptor. Interface - a class representing an interface descriptor. Endpoint - a class representing an endpoint descriptor. find() - a function to find USB devices. sWander Lairson CostatDevicet Configurationt InterfacetEndpointtfindiNsusb.coreicCs.x'|D]}t||t||qWdS(N(tsetattrtgetattr(tinputtoutputtfieldstf((s,/usr/lib/python2.7/site-packages/usb/core.pyt _set_attr6s t_ResourceManagercBsweZdZdZdZdZdZdZdZdZ dZ d Z d Z e d ZRS( cCsI||_d|_||_d|_tj|_i|_i|_ dS(N( tbackendtNonet_active_cfg_indextdevthandlet_interopt_sett _claimed_intft_alt_sett _ep_type_map(tselfRR ((s,/usr/lib/python2.7/site-packages/usb/core.pyt__init__;s     cCs1|jdkr*|jj|j|_n|jS(N(RRR t open_deviceR(R((s,/usr/lib/python2.7/site-packages/usb/core.pyt managed_openDscCs2|jdk r.|jj|jd|_ndS(N(RRR t close_device(R((s,/usr/lib/python2.7/site-packages/usb/core.pyt managed_closeIscCs|dkr|d}n[t|tr1|}nC|dkr_dtfdY}|}ntj|d|}|j|jj|j |j |j |_ |j j|jjdS(NitFakeConfigurationcBseZdZRS(cSsd|_d|_dS(Ni(RtindextbConfigurationValue(R((s,/usr/lib/python2.7/site-packages/usb/core.pyRUs (t__name__t __module__R(((s,/usr/lib/python2.7/site-packages/usb/core.pyRTsR(Rt isinstanceRtobjecttutiltfind_descriptorRR tset_configurationRRRRRtclearR(RtdevicetconfigtcfgR((s,/usr/lib/python2.7/site-packages/usb/core.pytmanaged_set_configurationNs        cCs|j|dkr5|j|}|dj}n!t|trP|j}n|}||jkr|jj|j ||jj |ndS(Ni(ii( RRtget_active_configurationtbInterfaceNumberR"RRR tclaim_interfaceRtadd(RR(tintfR*ti((s,/usr/lib/python2.7/site-packages/usb/core.pytmanaged_claim_interfacefs   cCs|dkr+|j|}|dj}n!t|trF|j}n|}||jkr|jj|j||jj |ndS(Ni(ii( RR,R-R"RRR trelease_interfaceRtremove(RR(R0R*R1((s,/usr/lib/python2.7/site-packages/usb/core.pytmanaged_release_interfacess  cCst|tr|}nj|j|}|dkrC|dj}n|dk rmtj|d|d|}ntj|d|}|j|||dkr|j}n|j j |j |j|||j |j|dj}n||jkrmtj|d|d|j|Stj|d|SdS(NiR-R6(ii(R"RR,RR-RR$R%(RR(R0R*((s,/usr/lib/python2.7/site-packages/usb/core.pyt get_interfaces  cCss|jdkrh|jtj|d|jj|j}|dkrXtdn|j |_|S||jS(NRsConfiguration not set( RRRR$R%R tget_configurationRtUSBErrorR(RR(R*((s,/usr/lib/python2.7/site-packages/usb/core.pyR,s   cCs|j||}||j|jf}y|j|SWnFtk r~tj|d|}tj|j}||j|<|SXdS(NtbEndpointAddress( R:R-R6RtKeyErrorR$R%t endpoint_typet bmAttributes(RR(taddressR0tkeytetetype((s,/usr/lib/python2.7/site-packages/usb/core.pytget_endpoint_types  cCs7tj|j}x|D]}|j||qWdS(N(tcopyRR5(RR(tclaimedR1((s,/usr/lib/python2.7/site-packages/usb/core.pytrelease_all_interfacess cCsG|j||r |jn|jj|jjd|_dS(N(RHRRR'RRR(RR(t close_handle((s,/usr/lib/python2.7/site-packages/usb/core.pytdisposes     (R R!RRRR+R2R5R9R:R,RERHtTrueRJ(((s,/usr/lib/python2.7/site-packages/usb/core.pyR :s      R<cBseZdZdddZRS(sException class for USB errors. Backends must raise this exception when USB related errors occur. The backend specific error code is available through the 'backend_error_code' member variable. cCs tj|||||_dS(sInitialize the object. This initializes the USBError object. The strerror and errno are passed to the parent object. The error_code parameter is attributed to the backend_error_code member variable. N(tIOErrorRtbackend_error_code(Rtstrerrort error_codeterrno((s,/usr/lib/python2.7/site-packages/usb/core.pyRsN(R R!t__doc__RR(((s,/usr/lib/python2.7/site-packages/usb/core.pyR<scBs8eZdZddddZddZddZRS(sRepresent an endpoint object. This class contains all fields of the Endpoint Descriptor according to the USB Specification. You may access them as class properties. For example, to access the field bEndpointAddress of the endpoint descriptor: >>> import usb.core >>> dev = usb.core.find() >>> for cfg in dev: >>> for i in cfg: >>> for e in i: >>> print e.bEndpointAddress ic Cst||_t||||}|j|_||_|jj}|j|jj||||}t ||d d S( s)Initialize the Endpoint object. The device parameter is the device object returned by the find() function. endpoint is the endpoint logical index (not the endpoint address). The configuration parameter is the logical index of the configuration (not the bConfigurationValue field). The interface parameter is the interface logical index (not the bInterfaceNumber field) and alternate_setting is the alternate setting logical index (not the bAlternateSetting value). Not every interface has more than one alternate setting. In this case, the alternate_setting parameter should be zero. By "logical index" we mean the relative order of the configurations returned by the peripheral as a result of GET_DESCRIPTOR request. tbLengthtbDescriptorTypeR=R@twMaxPacketSizet bIntervaltbRefresht bSynchAddressN(RRRSsbEndpointAddresss bmAttributesRTRURVRW( R(RR-t interfaceRt_ctxR tget_endpoint_descriptorRR ( RR(tendpointRXtalternate_settingt configurationR0R tdesc((s,/usr/lib/python2.7/site-packages/usb/core.pyRs,      cCs|jj|j||j|S(s^Write data to the endpoint. The parameter data contains the data to be sent to the endpoint and timeout is the time limit of the operation. The transfer type and endpoint address are automatically inferred. The method returns the number of bytes written. For details, see the Device.write() method. (R(twriteR=RX(Rtdatattimeout((s,/usr/lib/python2.7/site-packages/usb/core.pyR_s cCs|jj|j||j|S(s\Read data from the endpoint. The parameter size is the number of bytes to read and timeout is the time limit of the operation.The transfer type and endpoint address are automatically inferred. The method returns an array.array object with the data read. For details, see the Device.read() method. (R(treadR=RX(RtsizeRa((s,/usr/lib/python2.7/site-packages/usb/core.pyRb!s N(R R!RQRRR_Rb(((s,/usr/lib/python2.7/site-packages/usb/core.pyRs , cBs;eZdZddddZdZdZdZRS(sRepresent an interface object. This class contains all fields of the Interface Descriptor according to the USB Specification. You may access them as class properties. For example, to access the field bInterfaceNumber of the interface descriptor: >>> import usb.core >>> dev = usb.core.find() >>> for cfg in dev: >>> for i in cfg: >>> print i.bInterfaceNumber ic Cse||_||_||_||_|jj}|j|jjj|||}t||d d S( sInitialize the interface object. The device parameter is the device object returned by the find() function. The configuration parameter is the logical index of the configuration (not the bConfigurationValue field). The interface parameter is the interface logical index (not the bInterfaceNumber field) and alternate_setting is the alternate setting logical index (not the bAlternateSetting value). Not every interface has more than one alternate setting. In this case, the alternate_setting parameter should be zero. By "logical index" we mean the relative order of the configurations returned by the peripheral as a result of GET_DESCRIPTOR request. RRRSR-R6t bNumEndpointstbInterfaceClasstbInterfaceSubClasstbInterfaceProtocolt iInterfaceN( sbLengthsbDescriptorTypesbInterfaceNumbersbAlternateSettings bNumEndpointsReRfRgRh( R(talternate_indexRR]RYR tget_interface_descriptorRR (RR(RXR\R]R R^((s,/usr/lib/python2.7/site-packages/usb/core.pyR=s,       cCs|jj|j|jdS(s$Set the interface alternate setting.N(R(R7R-R6(R((s,/usr/lib/python2.7/site-packages/usb/core.pytset_altsettingis ccsAx:t|jD])}t|j||j|j|jVqWdS(s,Iterate over all endpoints of the interface.N(trangeRdRR(RRiR](RR1((s,/usr/lib/python2.7/site-packages/usb/core.pyt__iter__pscCs"t|j||j|j|jS(s1Return the Endpoint object in the given position.(RR(RRiR](RR((s,/usr/lib/python2.7/site-packages/usb/core.pyt __getitem__zs (R R!RQRRkRmRn(((s,/usr/lib/python2.7/site-packages/usb/core.pyR.s  +  cBs5eZdZddZdZdZdZRS(sRepresent a configuration object. This class contains all fields of the Configuration Descriptor according to the USB Specification. You may access them as class properties. For example, to access the field bConfigurationValue of the configuration descriptor: >>> import usb.core >>> dev = usb.core.find() >>> for cfg in dev: >>> print cfg.bConfigurationValue ic CsM||_||_|jj}|j|jjj|}t||d d S( sInitialize the configuration object. The device parameter is the device object returned by the find() function. The configuration parameter is the logical index of the configuration (not the bConfigurationValue field). By "logical index" we mean the relative order of the configurations returned by the peripheral as a result of GET_DESCRIPTOR request. RRRSt wTotalLengthtbNumInterfacesRtiConfigurationR@t bMaxPowerN(sbLengthsbDescriptorTypeRosbNumInterfacessbConfigurationValueRqs bmAttributesRr(R(RRYR tget_configuration_descriptorRR (RR(R]R R^((s,/usr/lib/python2.7/site-packages/usb/core.pyRs"     cCs|jj|jdS(s)Set this configuration as the active one.N(R(R&R(R((s,/usr/lib/python2.7/site-packages/usb/core.pytsetsccssxlt|jD][}d}y5x.trOt|j|||jV|d7}q"WWqttfk rjqXqWdS(s1Iterate over all interfaces of the configuration.iiN(RlRpRKRR(RR<t IndexError(RR1R8((s,/usr/lib/python2.7/site-packages/usb/core.pyRms cCs!t|j|d|d|jS(sReturn the Interface object in the given position. index is a tuple of two values with interface index and alternate setting index, respectivally. Example: >>> interface = config[(0, 0)] ii(RR(R(RR((s,/usr/lib/python2.7/site-packages/usb/core.pyRns(R R!RQRRtRmRn(((s,/usr/lib/python2.7/site-packages/usb/core.pyRs   "  cBseZdZdZddZdZdddZdZdddZ dddZ ddddd Z d Z d Z d Zd ZdZdZdZdZdZeeeddZRS(sDevice object. This class contains all fields of the Device Descriptor according to the USB Specification. You may access them as class properties. For example, to access the field bDescriptorType of the device descriptor: >>> import usb.core >>> dev = usb.core.find() >>> dev.bDescriptorType Additionally, the class provides methods to communicate with the hardware. Typically, an application will first call the set_configuration() method to put the device in a known configured state, optionally call the set_interface_altsetting() to select the alternate setting (if there is more than one) of the interface used, and call the write() and read() method to send and receive data. When working in a new hardware, one first try would be like this: >>> import usb.core >>> dev = usb.core.find(idVendor=myVendorId, idProduct=myProductId) >>> dev.set_configuration() >>> dev.write(1, 'test') This sample finds the device of interest (myVendorId and myProductId should be replaced by the corresponding values of your device), then configures the device (by default, the configuration value is 1, which is a typical value for most devices) and then writes some data to the endpoint 0x01. Timeout values for the write, read and ctrl_transfer methods are specified in miliseconds. If the parameter is omitted, Device.default_timeout value will be used instead. This property can be set by the user at anytime. cCst|||_t|_|j|}t||d|jdk r^t|j|_n d|_|j dk rt|j |_ n d|_ |j dk rt|j |_ n d|_ dS(sCInitialize the Device object. Library users should normally get a Device instance through the find function. The dev parameter is the identification of a device to the backend and its meaning is opaque outside of it. The backend parameter is a instance of a backend object. RRRStbcdUSBt bDeviceClasstbDeviceSubClasstbDeviceProtocoltbMaxPacketSize0tidVendort idProductt bcdDevicet iManufacturertiProductt iSerialNumbertbNumConfigurationsRAtbust port_numberN(sbLengthsbDescriptorTypeRvRwRxRyRzR{R|R}R~RRsbNumConfigurationssaddresssbuss port_number( R RYt_DEFAULT_TIMEOUTt_Device__default_timeouttget_device_descriptorR RRtintRAR(RRR R^((s,/usr/lib/python2.7/site-packages/usb/core.pyRs@    cCs|jj||dS(sSet the active configuration. The configuration parameter is the bConfigurationValue field of the configuration you want to set as active. If you call this method without parameter, it will use the first configuration found. As a device hardly ever has more than one configuration, calling the method without parameter is enough to get the device ready. N(RYR+(RR]((s,/usr/lib/python2.7/site-packages/usb/core.pyR&&s cCs|jj|S(sIReturn a Configuration object representing the current configuration set.(RYR,(R((s,/usr/lib/python2.7/site-packages/usb/core.pyR,1scCs|jj|||dS(sSet the alternate setting for an interface. When you want to use an interface and it has more than one alternate setting, you should call this method to select the alternate setting you would like to use. If you call the method without one or the two parameters, it will be selected the first one found in the Device in the same way of set_configuration method. Commonly, an interface has only one alternate setting and this call is not necessary. For most of the devices, either it has more than one alternate setting or not, it is not harmful to make a call to this method with no arguments, as devices will silently ignore the request when there is only one alternate setting, though the USB Spec allows devices with no additional alternate setting return an error to the Host in response to a SET_INTERFACE request. If you are in doubt, you may want to call it with no arguments wrapped by a try/except clause: >>> try: >>> dev.set_interface_altsetting() >>> except usb.core.USBError: >>> pass N(RYR9(RRXR\((s,/usr/lib/python2.7/site-packages/usb/core.pyR75scCsP|jj|jj|t|jjj|jj|jj|tdS(sReset the device.N(RYRRJtFalseR t reset_deviceRRK(R((s,/usr/lib/python2.7/site-packages/usb/core.pytresetOs c Cs|jj}i|jtj6|jtj6|jtj6}|jj ||}||jj |||}|jj ||||jj ||j tj||j|S(sWrite data to the endpoint. This method is used to send data to the device. The endpoint parameter corresponds to the bEndpointAddress member whose endpoint you want to communicate with. The interface parameter is the bInterfaceNumber field of the interface descriptor which contains the endpoint. If you do not provide one, the first one found will be used, as explained in the set_interface_altsetting() method. The bInterfaceNumber parameter is not used for most backends, and often can be ignored. The data parameter should be a sequence like type convertible to array type (see array module). The timeout is specified in miliseconds. The method returns the number of bytes written. (RYR t bulk_writeR$tENDPOINT_TYPE_BULKt intr_writetENDPOINT_TYPE_INTRt iso_writetENDPOINT_TYPE_ISOR:RER2RR-Rtas_arrayt_Device__get_timeout( RR[R`RXRaR tfn_mapR0tfn((s,/usr/lib/python2.7/site-packages/usb/core.pyR_Vs     c Cs|jj}i|jtj6|jtj6|jtj6}|jj ||}||jj |||}|jj ||||jj ||j ||j|S(sRead data from the endpoint. This method is used to receive data from the device. The endpoint parameter corresponds to the bEndpointAddress member whose endpoint you want to communicate with. The interface parameter is the bInterfaceNumber field of the interface descriptor which contains the endpoint. If you do not provide one, the first one found will be used, as explained in the set_interface_altsetting() method. The bInterfaceNumber parameter is not used for most backends, and often can be ignored. The size parameter tells how many bytes you want to read. The timeout is specified in miliseconds. The method returns an array object with the data read. (RYR t bulk_readR$Rt intr_readRtiso_readRR:RER2RR-R( RR[RcRXRaR RR0R((s,/usr/lib/python2.7/site-packages/usb/core.pyRb|s    ic Cstj|tjkr*tj|}n|dkr?d}n|}|jj|jjj |jj ||||||j |S(sDo a control transfer on the endpoint 0. This method is used to issue a control transfer over the endpoint 0(endpoint 0 is required to always be a control endpoint). The parameters bmRequestType, bRequest, wValue and wIndex are the same of the USB Standard Control Request format. Control requests may or may not have a data payload to write/read. In cases which it has, the direction bit of the bmRequestType field is used to infere the desired request direction. For host to device requests (OUT), data_or_wLength parameter is the data payload to send, and it must be a sequence type convertible to an array object. In this case, the return value is the number of data payload written. For device to host requests (IN), data_or_wLength is the wLength parameter of the control request specifying the number of bytes to read in data payload. In this case, the return value is the data payload read, as an array object. iN( R$tctrl_directiontCTRL_OUTRRRRYRR t ctrl_transferRR(Rt bmRequestTypetbRequesttwValuetwIndextdata_or_wLengthRata((s,/usr/lib/python2.7/site-packages/usb/core.pyRs     cCs;|jj|jjj|jj|jj||jS(sDetermine if there is kernel driver associated with the interface. If a kernel driver is active, and the object will be unable to perform I/O. (RYRR tis_kernel_driver_activeRR:R-(RRX((s,/usr/lib/python2.7/site-packages/usb/core.pyRs cCs?|jj|jjj|jj|jj||jdS(s^Detach a kernel driver. If successful, you will then be able to perform I/O. N(RYRR tdetach_kernel_driverRR:R-(RRX((s,/usr/lib/python2.7/site-packages/usb/core.pyRs cCs?|jj|jjj|jj|jj||jdS(skRe-attach an interface's kernel driver, which was previously detached using detach_kernel_driver().N(RYRR tattach_kernel_driverRR:R-(RRX((s,/usr/lib/python2.7/site-packages/usb/core.pyRs ccs,x%t|jD]}t||VqWdS(s.Iterate over all configurations of the device.N(RlRR(RR1((s,/usr/lib/python2.7/site-packages/usb/core.pyRmscCs t||S(s6Return the Configuration object in the given position.(R(RR((s,/usr/lib/python2.7/site-packages/usb/core.pyRnscCs|jj|dS(N(RYRJ(R((s,/usr/lib/python2.7/site-packages/usb/core.pyt__del__scCs|dk r|S|jS(N(RR(RRa((s,/usr/lib/python2.7/site-packages/usb/core.pyt __get_timeouts cCs(|dkrtdn||_dS(Nis"Timeout cannot be a negative value(t ValueErrorR(Rttmo((s,/usr/lib/python2.7/site-packages/usb/core.pyt __set_def_tmos cCs|jS(N(R(R((s,/usr/lib/python2.7/site-packages/usb/core.pyt __get_def_tmostdocs*Default timeout for transfer I/O functionsN(R R!RQRRR&R,R7RR_RbRRRRRmRnRRt_Device__set_def_tmot_Device__get_def_tmotpropertytdefault_timeout(((s,/usr/lib/python2.7/site-packages/usb/core.pyRs." 5  &&'       c  sfd}dkrddljj}ddljj}ddljj}xU|||fD]5}|jdk rdt j d|j PqdqdWt dn|j |j} } |rg|| | D] } | ^qSytj|| | SWntk rdSXdS(s Find an USB device and return it. find() is the function used to discover USB devices. You can pass as arguments any combination of the USB Device Descriptor fields to match a device. For example: find(idVendor=0x3f4, idProduct=0x2009) will return the Device object for the device with idVendor Device descriptor field equals to 0x3f4 and idProduct equals to 0x2009. If there is more than one device which matchs the criteria, the first one found will be returned. If a matching device cannot be found the function returns None. If you want to get all devices, you can set the parameter find_all to True, then find will return an list with all matched devices. If no matching device is found, it will return an empty list. Example: printers = find(find_all=True, bDeviceClass=7) This call will get all the USB printers connected to the system. (actually may be not, because some devices put their class information in the Interface Descriptor). You can also use a customized match criteria: dev = find(custom_match = lambda d: d.idProduct=0x3f4 and d.idvendor=0x2009) A more accurate printer finder using a customized match would be like so: def is_printer(dev): import usb.util if dev.bDeviceClass == 7: return True for cfg in dev: if usb.util.find_descriptor(cfg, bInterfaceClass=7) is not None: return True printers = find(find_all=True, custom_match = is_printer) Now even if the device class code is in the interface descriptor the printer will be found. You can combine a customized match with device descriptor fields. In this case, the fields must match and the custom_match must return True. In the our previous example, if we would like to get all printers belonging to the manufacturer 0x3f4, the code would be like so: printers = find(find_all=True, idVendor=0x3f4, custom_match=is_printer) If you want to use find as a 'list all devices' function, just call it with find_all = True: devices = find(find_all=True) Finally, you may pass a custom backend to the find function: find(backend = MyBackend()) PyUSB has builtin backends for libusb 0.1, libusb 1.0 and OpenUSB. If you do not supply a backend explicitly, find() function will select one of the predefineds backends according to system availability. Backends are explained in the usb.backend module. c 3sx|jD]n}t|tjdttj|tfd|tr dkssr Vq q WdS(NcSs |o |S(N((Rtb((s,/usr/lib/python2.7/site-packages/usb/core.pytKscs t|S(N(R(R1(td(s,/usr/lib/python2.7/site-packages/usb/core.pyROs( tenumerate_devicesRRt_reducetmaptoperatorteqRKR(tktvR(R t custom_match(Rs,/usr/lib/python2.7/site-packages/usb/core.pyt device_iterGs iNsfind(): using backend "%s"sNo backend available(Rtusb.backend.libusb1R tlibusb1tusb.backend.libusb0tlibusb0tusb.backend.openusbtopenusbt get_backendt_loggertinfoR RtkeystvaluesRt_nextt StopIteration( tfind_allR RtargsRRRRtmRRR((R Rs,/usr/lib/python2.7/site-packages/usb/core.pyRs$E     (RQt __author__t__all__tusb.utilR$RFRt usb._interopRtloggingt getLoggerRRR R#R RLR<RRRRRRR(((s,/usr/lib/python2.7/site-packages/usb/core.pyt&s$    WVI6