Exemplo n.º 1
0
    def _open_device(self):
        usb.init()
        if not usb.get_busses():
            usb.find_busses()
            usb.find_devices()

        busses = usb.get_busses()

        found = False
        for bus in busses:
            for dev in bus.devices:
                debug('idVendor: 0x%04x idProduct: 0x%04x'%
                      (dev.descriptor.idVendor,dev.descriptor.idProduct))
                if (dev.descriptor.idVendor == 0x1781 and
                    dev.descriptor.idProduct == 0x0BAF):
                    found = True
                    break
            if found:
                break
        if not found:
            if int(os.environ.get('REQUIRE_TRIGGER','1')):
                raise RuntimeError("Cannot find device. (Perhaps run with "
                                   "environment variable REQUIRE_TRIGGER=0.)")
            else:
                self._have_trigger = False
                return
        with self._lock:
            self._libusb_handle = usb.open(dev)

            manufacturer = usb.get_string_simple(self._libusb_handle,dev.descriptor.iManufacturer)
            product = usb.get_string_simple(self._libusb_handle,dev.descriptor.iProduct)
            serial = usb.get_string_simple(self._libusb_handle,dev.descriptor.iSerialNumber)

            assert manufacturer == 'Strawman', 'Wrong manufacturer: %s'%manufacturer
            valid_product = 'Camera Trigger 1.0'
            if product != valid_product:
                errmsg = 'Expected product "%s", but you have "%s"'%(
                    valid_product,product)
                if self.ignore_version_mismatch:
                    print 'WARNING:',errmsg
                else:
                    raise ValueError(errmsg)

            interface_nr = 0
            if hasattr(usb,'get_driver_np'):
                # non-portable libusb extension
                name = usb.get_driver_np(self._libusb_handle,interface_nr)
                if name != '':
                    usb.detach_kernel_driver_np(self._libusb_handle,interface_nr)

            if dev.descriptor.bNumConfigurations > 1:
                debug("WARNING: more than one configuration, choosing first")

            config = dev.config[0]
            usb.set_configuration(self._libusb_handle, config.bConfigurationValue)
            usb.claim_interface(self._libusb_handle, interface_nr)
Exemplo n.º 2
0
    def get_product(self):
        """
        Get decive product string

        Arguments: None

        Return: product string
        """
        return usb.get_string_simple(self.libusb_handle, self.dev.descriptor.iProduct)
Exemplo n.º 3
0
    def get_manufacturer(self):
        """
        Get manufacturer of device

        Arguments: None

        Return: manufacturer string
        """
        return usb.get_string_simple(self.libusb_handle, self.dev.descriptor.iManufacturer)
Exemplo n.º 4
0
    def get_serial_number(self):
        """
        Get serial number of device.
        
        Arguments: None

        Return: serial number of device - a string
        """
        return  usb.get_string_simple(self.libusb_handle, self.dev.descriptor.iSerialNumber)
Exemplo n.º 5
0
    def get_product(self):
        """
        Get decive product string

        Arguments: None

        Return: product string
        """
        return usb.get_string_simple(self.libusb_handle,
                                     self.dev.descriptor.iProduct)
Exemplo n.º 6
0
    def get_manufacturer(self):
        """
        Get manufacturer of device

        Arguments: None

        Return: manufacturer string
        """
        return usb.get_string_simple(self.libusb_handle,
                                     self.dev.descriptor.iManufacturer)
Exemplo n.º 7
0
    def get_serial_number(self):
        """
        Get serial number of device.
        
        Arguments: None

        Return: serial number of device - a string
        """
        return usb.get_string_simple(self.libusb_handle,
                                     self.dev.descriptor.iSerialNumber)
Exemplo n.º 8
0
    def _open_device(self):
        require_trigger = int(os.environ.get('REQUIRE_TRIGGER','1'))
        if require_trigger:

            usb.init()
            if not usb.get_busses():
                usb.find_busses()
                usb.find_devices()

            busses = usb.get_busses()

            found = False
            for bus in busses:
                for dev in bus.devices:
                    debug('idVendor: 0x%04x idProduct: 0x%04x'%
                          (dev.descriptor.idVendor,dev.descriptor.idProduct))
                    if (dev.descriptor.idVendor == 0x1781 and
                        dev.descriptor.idProduct == 0x0BAF):
                        found = True
                        break
                if found:
                    break
            if not found:
                raise RuntimeError("Cannot find device. (Perhaps run with "
                                   "environment variable REQUIRE_TRIGGER=0.)")
        else:
            self.real_device = False
            return
        with self._lock:
            self._libusb_handle = usb.open(dev)

            manufacturer = usb.get_string_simple(self._libusb_handle,dev.descriptor.iManufacturer)
            product = usb.get_string_simple(self._libusb_handle,dev.descriptor.iProduct)
            serial = usb.get_string_simple(self._libusb_handle,dev.descriptor.iSerialNumber)

            assert manufacturer == 'Strawman', 'Wrong manufacturer: %s'%manufacturer
            valid_product = 'Camera Trigger 1.0'
            if product == valid_product:
                self.FOSC = 8000000.0
            elif product.startswith('Camera Trigger 1.01'):
                osc_re = r'Camera Trigger 1.01 \(F_CPU = (.*)\)\w*'
                match = re.search(osc_re,product)
                fosc_str = match.groups()[0]
                if fosc_str.endswith('UL'):
                    fosc_str = fosc_str[:-2]
                self.FOSC = float(fosc_str)
            else:
                errmsg = 'Expected product "%s", but you have "%s"'%(
                    valid_product,product)
                if self.ignore_version_mismatch:
                    print 'WARNING:',errmsg
                    self.FOSC = 8000000.0
                    print ' assuming FOSC=',self.FOSC
                else:
                    raise ValueError(errmsg)

            interface_nr = 0
            if hasattr(usb,'get_driver_np'):
                # non-portable libusb extension
                name = usb.get_driver_np(self._libusb_handle,interface_nr)
                if name != '':
                    usb.detach_kernel_driver_np(self._libusb_handle,interface_nr)

            if dev.descriptor.bNumConfigurations > 1:
                debug("WARNING: more than one configuration, choosing first")

            config = dev.config[0]
            usb.set_configuration(self._libusb_handle, config.bConfigurationValue)
            usb.claim_interface(self._libusb_handle, interface_nr)
        self.real_device = True
Exemplo n.º 9
0
    except:
        sys.stderr.write("ERR Can't use UDisks interface\n")

# Trying to get devices via libusb
try:
    import pylibusb as usb
    usb.init()
    if not usb.get_busses():
        usb.find_busses()
        usb.find_devices()
    busses = usb.get_busses()
    for bus in busses:
        for dev in bus.devices:
            if (dev.descriptor.idVendor == 0x1949 and
                dev.descriptor.idProduct == 0x0004):
                libusb_handle = usb.open(dev)
                try:
                    s = usb.get_string_simple(libusb_handle,dev.descriptor.iSerialNumber)
                    if not s in serials:
                        serials.append(s)
                except usb.USBError, error:
                    sys.stderr.write("ERR Libusb error: %s\nERR May be you is not root?\n"%str(error))
except:
    sys.stderr.write("ERR Can't use libusb interface\n")

if len(serials)==0:
    print "No Kindle devices found"
else:
    for serial in serials:
        print "Device: %s\nSerial: %s\nPassword: %s"%(getKindleModel(serial),serial,getKindlePassword(serial))
Exemplo n.º 10
0
    def __init__(self,ignore_version_mismatch=False):
        usb.init()

        if not usb.get_busses():
            usb.find_busses()
            usb.find_devices()

        busses = usb.get_busses()

        found = False
        for bus in busses:
            for dev in bus.devices:
                debug('idVendor: 0x%04x idProduct: 0x%04x'%(dev.descriptor.idVendor,
                                                            dev.descriptor.idProduct))
                if (dev.descriptor.idVendor == 0x1781 and
                    dev.descriptor.idProduct == 0x0BAF):
                    found = True
                    break
            if found:
                break
        if not found:
            raise RuntimeError("Cannot find device. (Perhaps run with environment variable REQUIRE_TRIGGER=0.)")

        debug('found device',dev)
        self.libusb_handle = usb.open(dev)

        manufacturer = usb.get_string_simple(self.libusb_handle,dev.descriptor.iManufacturer)
        product = usb.get_string_simple(self.libusb_handle,dev.descriptor.iProduct)
        serial = usb.get_string_simple(self.libusb_handle,dev.descriptor.iSerialNumber)

        assert manufacturer == 'Strawman', 'Wrong manufacturer: %s'%manufacturer
        valid_product = 'Camera Trigger 1.0'
        if product != valid_product:
            errmsg = 'Expected product "%s", but you have "%s"'%(
                valid_product,product)
            if ignore_version_mismatch:
                print 'WARNING:',errmsg
            else:
                raise ValueError(errmsg)

        interface_nr = 0
        if hasattr(usb,'get_driver_np'):
            # non-portable libusb extension
            name = usb.get_driver_np(self.libusb_handle,interface_nr)
            if name != '':
                debug("attached to kernel driver '%s', detaching."%name )
                usb.detach_kernel_driver_np(self.libusb_handle,interface_nr)

        if dev.descriptor.bNumConfigurations > 1:
            debug("WARNING: more than one configuration, choosing first")

        debug('setting configuration')
        debug('dev.config[0]',dev.config[0])
        config = dev.config[0]
        debug('config.bConfigurationValue',config.bConfigurationValue)
        usb.set_configuration(self.libusb_handle, config.bConfigurationValue)
        debug('claiming interface')
        debug('config.bNumInterfaces',config.bNumInterfaces)
        #print 'config.interface',config.interface
##        for i in range(config.bNumInterfaces):
##            iface = config.interface[i]
##            print iface
##            print iface.altsetting

        usb.claim_interface(self.libusb_handle, interface_nr)

        self.OUTPUT_BUFFER = ctypes.create_string_buffer(16)

        self.FOSC = 8000000 # 8 MHz
        trigger_carrier_freq = 0.0 # stopped

        self.timer3_TOP = None # unknown
        self.timer3_CS = 8
        #print 'set A self.timer3_CS to',self.timer3_CS
        self._set_timer3_metadata(trigger_carrier_freq)
Exemplo n.º 11
0
    def __init__(self, ignore_version_mismatch=False):
        usb.init()

        if not usb.get_busses():
            usb.find_busses()
            usb.find_devices()

        busses = usb.get_busses()

        found = False
        for bus in busses:
            for dev in bus.devices:
                debug('idVendor: 0x%04x idProduct: 0x%04x' %
                      (dev.descriptor.idVendor, dev.descriptor.idProduct))
                if (dev.descriptor.idVendor == 0x1781
                        and dev.descriptor.idProduct == 0x0BAF):
                    found = True
                    break
            if found:
                break
        if not found:
            raise RuntimeError(
                "Cannot find device. (Perhaps run with environment variable REQUIRE_TRIGGER=0.)"
            )

        debug('found device', dev)
        self.libusb_handle = usb.open(dev)

        manufacturer = usb.get_string_simple(self.libusb_handle,
                                             dev.descriptor.iManufacturer)
        product = usb.get_string_simple(self.libusb_handle,
                                        dev.descriptor.iProduct)
        serial = usb.get_string_simple(self.libusb_handle,
                                       dev.descriptor.iSerialNumber)

        assert manufacturer == 'Strawman', 'Wrong manufacturer: %s' % manufacturer
        valid_product = 'Camera Trigger 1.0'
        if product == valid_product:
            self.FOSC = 8000000.0
        elif product.startswith('Camera Trigger 1.01'):
            osc_re = r'Camera Trigger 1.01 \(F_CPU = (.*)\)\w*'
            match = re.search(osc_re, product)
            fosc_str = match.groups()[0]
            if fosc_str.endswith('UL'):
                fosc_str = fosc_str[:-2]
            self.FOSC = float(fosc_str)
        else:
            errmsg = 'Expected product "%s", but you have "%s"' % (
                valid_product, product)
            if ignore_version_mismatch:
                print 'WARNING:', errmsg
            else:
                raise ValueError(errmsg)

        interface_nr = 0
        if hasattr(usb, 'get_driver_np'):
            # non-portable libusb extension
            name = usb.get_driver_np(self.libusb_handle, interface_nr)
            if name != '':
                debug("attached to kernel driver '%s', detaching." % name)
                usb.detach_kernel_driver_np(self.libusb_handle, interface_nr)

        if dev.descriptor.bNumConfigurations > 1:
            debug("WARNING: more than one configuration, choosing first")

        debug('setting configuration')
        debug('dev.config[0]', dev.config[0])
        config = dev.config[0]
        debug('config.bConfigurationValue', config.bConfigurationValue)
        usb.set_configuration(self.libusb_handle, config.bConfigurationValue)
        debug('claiming interface')
        debug('config.bNumInterfaces', config.bNumInterfaces)
        #print 'config.interface',config.interface
        ##        for i in range(config.bNumInterfaces):
        ##            iface = config.interface[i]
        ##            print iface
        ##            print iface.altsetting

        usb.claim_interface(self.libusb_handle, interface_nr)

        self.OUTPUT_BUFFER = ctypes.create_string_buffer(16)

        trigger_carrier_freq = 0.0  # stopped

        self.timer3_TOP = None  # unknown
        self.timer3_CS = 8
        #print 'set A self.timer3_CS to',self.timer3_CS
        self._set_timer3_metadata(trigger_carrier_freq)
Exemplo n.º 12
0
    def _open_device(self):
        if require_trigger:

            usb.init()
            if not usb.get_busses():
                usb.find_busses()
                usb.find_devices()

            busses = usb.get_busses()

            found = False
            for bus in busses:
                for dev in bus.devices:
                    debug('idVendor: 0x%04x idProduct: 0x%04x'%
                          (dev.descriptor.idVendor,dev.descriptor.idProduct))
                    if (dev.descriptor.idVendor == 0x1781 and
                        dev.descriptor.idProduct == 0x0BAF):
                        found = True
                        break
                if found:
                    break
            if not found:
                raise RuntimeError("Cannot find device. (Perhaps run with "
                                   "environment variable REQUIRE_TRIGGER=0.)")
        else:
            self.real_device = False
            return
        with self._lock:
            self._libusb_handle = usb.open(dev)

            manufacturer = usb.get_string_simple(self._libusb_handle,dev.descriptor.iManufacturer)
            product = usb.get_string_simple(self._libusb_handle,dev.descriptor.iProduct)
            serial = usb.get_string_simple(self._libusb_handle,dev.descriptor.iSerialNumber)

            assert manufacturer == 'Strawman', 'Wrong manufacturer: %s'%manufacturer
            valid_product = 'Camera Trigger 1.0'
            if product == valid_product:
                self.FOSC = 8000000.0
            elif product.startswith('Camera Trigger 1.01'):
                osc_re = r'Camera Trigger 1.01 \(F_CPU = (.*)\)\w*'
                match = re.search(osc_re,product)
                fosc_str = match.groups()[0]
                if fosc_str.endswith('UL'):
                    fosc_str = fosc_str[:-2]
                self.FOSC = float(fosc_str)
            else:
                errmsg = 'Expected product "%s", but you have "%s"'%(
                    valid_product,product)
                if self.ignore_version_mismatch:
                    print 'WARNING:',errmsg
                    self.FOSC = 8000000.0
                    print ' assuming FOSC=',self.FOSC
                else:
                    raise ValueError(errmsg)

            interface_nr = 0
            if hasattr(usb,'get_driver_np'):
                # non-portable libusb extension
                name = usb.get_driver_np(self._libusb_handle,interface_nr)
                if name != '':
                    usb.detach_kernel_driver_np(self._libusb_handle,interface_nr)

            if dev.descriptor.bNumConfigurations > 1:
                debug("WARNING: more than one configuration, choosing first")

            config = dev.config[0]
            usb.set_configuration(self._libusb_handle, config.bConfigurationValue)
            usb.claim_interface(self._libusb_handle, interface_nr)
        self.real_device = True