Exemplo n.º 1
0
 def close(self):
     """
     Close the connection to this card.
     """
     usb.release_interface(self.handle, 0)
     usb.close(self.handle)
     self.handle = None
Exemplo n.º 2
0
 def close(self):
     """
     Close usb device.
     
     Arguments: None
     
     Return: None
     """
     ret = usb.close(self.libusb_handle)
     return
Exemplo n.º 3
0
 def close(self):
     """
     Close usb device.
     
     Arguments: None
     
     Return: None
     """
     ret = usb.release_interface(self.libusb_handle, self.interface_nr)
     ret = usb.close(self.libusb_handle)
     return
Exemplo n.º 4
0
 def close(self):
     """
     Close usb device.
     
     Arguments: None
     
     Return: None
     """
     ret = usb.release_interface(self.libusb_handle,self.interface_nr)
     ret = usb.close(self.libusb_handle)
     return
Exemplo n.º 5
0
 def close(self):
     """ Release NIA interface
     """  ###
     usb.close(self.handle)  #self.handle.reset()
     # self.handle.releaseInterface()
     self.handle, self.device = None, None
Exemplo n.º 6
0
    def __init__(
        self,
        serial_number=None,
        usb_product_id=DEFAULT_USB_PRODUCT_ID,
        usb_vendor_id=DEFAULT_USB_VENDOR_ID,
        usb_bulkout_ep_address=DEFAULT_USB_BULKOUT_EP_ADDRESS,
        usb_bulkin_ep_address=DEFAULT_USB_BULKIN_EP_ADDRESS,
        usb_buffer_out_size=DEFAULT_USB_BUFFER_OUT_SIZE,
        usb_buffer_in_size=DEFAULT_USB_BUFFER_IN_SIZE,
    ):
        """
        Open and initialize usb device.
        
        Arguments: None
        
        Return: None.
        """
        self.serial_number = serial_number
        self.usb_product_id = usb_product_id
        self.usb_vendor_id = usb_vendor_id
        self.usb_bulkout_ep_address = usb_bulkout_ep_address
        self.usb_bulkin_ep_address = usb_bulkin_ep_address
        self.usb_buffer_out_size = usb_buffer_out_size
        self.usb_buffer_in_size = usb_buffer_in_size
        usb.init()

        # Get usb busses
        if not usb.get_busses():
            usb.find_busses()
            usb.find_devices()
        busses = usb.get_busses()

        # Find device by IDs
        found = False
        dev_list = []
        for bus in busses:
            for dev in bus.devices:
                if (dev.descriptor.idVendor == self.usb_vendor_id
                        and dev.descriptor.idProduct == self.usb_product_id):
                    dev_list.append(dev)
                    found = True
        if not found:
            raise RuntimeError("Cannot find device.")

        if serial_number == None:
            # No serial number specified - take first device
            dev = dev_list[0]
            self.libusb_handle = usb.open(dev)
            self.dev = dev
        else:
            # Try and find device with specified serial number
            found = False
            for dev in dev_list:
                self.dev = dev
                self.libusb_handle = usb.open(dev)
                sn = self.get_serial_number()
                if sn == serial_number:
                    found = True
                    break
                else:
                    ret = usb.close(self.libusb_handle)
            if not found:
                raise RuntimeError("Cannot find device w/ serial number %s." %
                                   (serial_number, ))

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

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

        usb.set_configuration(self.libusb_handle,
                              self.dev.config[0].bConfigurationValue)
        usb.claim_interface(self.libusb_handle, self.interface_nr)

        self.output_buffer = ctypes.create_string_buffer(
            self.usb_buffer_out_size)
        self.input_buffer = ctypes.create_string_buffer(
            self.usb_buffer_in_size)
        for i in range(self.usb_buffer_in_size):
            self.input_buffer[i] = chr(0x00)
        for i in range(self.usb_buffer_out_size):
            self.output_buffer[i] = chr(0x00)

        # Clear any possible halt on the endpoints
        ret = usb.clear_halt(self.libusb_handle, self.usb_bulkout_ep_address)
        ret = usb.clear_halt(self.libusb_handle, self.usb_bulkin_ep_address)

        # Buffer position marker for reading from and writing to buffer
        self.output_buffer_pos = 0
        self.input_buffer_pos = 0

        # Set bref function based on python version
        if get_python_vnum() >= BYREF_EXISTS_VNUM:
            self.byref = ctypes.byref
        else:
            self.byref = byref_via_pointer
 def close(self):
     """ Release NIA interface
     """###
     usb.close(self.handle)      											#self.handle.reset()
     																		# self.handle.releaseInterface()
     self.handle, self.device = None, None
Exemplo n.º 8
0
    def __init__(self, serial_number=None):
        """
        Open and initialize usb device.
        
        Arguments: None
        
        Return: None.
        """
        usb.init()

        #usb.set_debug(3)

        # Get usb busses
        if not usb.get_busses():
            usb.find_busses()
            usb.find_devices()
        busses = usb.get_busses()

        # Find device by IDs
        found = False
        dev_list = []
        for bus in busses:
            for dev in bus.devices:
                if (dev.descriptor.idVendor == USB_VENDOR_ID
                        and dev.descriptor.idProduct == USB_PRODUCT_ID):
                    dev_list.append(dev)
                    found = True
                    #break
            #if found:
            #    break
        if not found:
            raise RuntimeError("Cannot find device.")

        if serial_number == None:
            # No serial number specified - take first device
            dev = dev_list[0]
            self.libusb_handle = usb.open(dev)
            self.dev = dev
        else:
            # Try and find device with specified serial number
            found = False
            for dev in dev_list:
                self.dev = dev
                self.libusb_handle = usb.open(dev)
                sn = self.get_serial_number()
                if sn == serial_number:
                    found = True
                    break
                else:
                    ret = usb.close(self.libusb_handle)
            if not found:
                raise RuntimeError("Cannot find device w/ serial number %s." %
                                   (serial_number, ))

        interface_nr = 0
        if hasattr(usb, 'get_driver_np'):
            # non-portable libusb function available
            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")

        usb.set_configuration(self.libusb_handle,
                              dev.config[0].bConfigurationValue)
        usb.claim_interface(self.libusb_handle, interface_nr)

        self.output_buffer = ctypes.create_string_buffer(USB_BUFFER_SIZE)
        self.input_buffer = ctypes.create_string_buffer(USB_BUFFER_SIZE)
        for i in range(USB_BUFFER_SIZE):
            self.output_buffer[i] = chr(0x00)
            self.input_buffer[i] = chr(0x00)

        # Get max and min velocities
        self.max_vel = self.get_max_vel()
        self.min_vel = self.get_min_vel()
Exemplo n.º 9
0
 def close(self):
     ret = usb.close(self.libusb_handle)
Exemplo n.º 10
0
    def __init__(
            self,
            serial_number=None,
            usb_product_id=DEFAULT_USB_PRODUCT_ID,
            usb_vendor_id=DEFAULT_USB_VENDOR_ID,
            usb_bulkout_ep_address=DEFAULT_USB_BULKOUT_EP_ADDRESS,
            usb_bulkin_ep_address=DEFAULT_USB_BULKIN_EP_ADDRESS,
            usb_buffer_out_size = DEFAULT_USB_BUFFER_OUT_SIZE,
            usb_buffer_in_size = DEFAULT_USB_BUFFER_IN_SIZE,
            ):
        """
        Open and initialize usb device.
        
        Arguments: None
        
        Return: None.
        """
        self.serial_number = serial_number
        self.usb_product_id = usb_product_id
        self.usb_vendor_id = usb_vendor_id
        self.usb_bulkout_ep_address = usb_bulkout_ep_address
        self.usb_bulkin_ep_address = usb_bulkin_ep_address
        self.usb_buffer_out_size = usb_buffer_out_size
        self.usb_buffer_in_size = usb_buffer_in_size
        usb.init()
        
        # Get usb busses
        if not usb.get_busses():
            usb.find_busses()            
            usb.find_devices()
        busses = usb.get_busses()

        # Find device by IDs
        found = False
        dev_list = []
        for bus in busses:
            for dev in bus.devices:
                if (dev.descriptor.idVendor == self.usb_vendor_id and
                    dev.descriptor.idProduct == self.usb_product_id):
                    dev_list.append(dev)
                    found = True
        if not found:
            raise RuntimeError("Cannot find device.")

        if serial_number == None:
            # No serial number specified - take first device
            dev = dev_list[0]
            self.libusb_handle = usb.open(dev)
            self.dev = dev
        else:
            # Try and find device with specified serial number
            found = False
            for dev in dev_list:
                self.dev = dev
                self.libusb_handle = usb.open(dev)
                sn = self.get_serial_number()
                if sn == serial_number:
                    found = True
                    break
                else:
                    ret = usb.close(self.libusb_handle)
            if not found:
                raise RuntimeError("Cannot find device w/ serial number %s."%(serial_number,))

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

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

        usb.set_configuration(self.libusb_handle, self.dev.config[0].bConfigurationValue)
        usb.claim_interface(self.libusb_handle, self.interface_nr)

        self.output_buffer = ctypes.create_string_buffer(self.usb_buffer_out_size)
        self.input_buffer = ctypes.create_string_buffer(self.usb_buffer_in_size)
        for i in range(self.usb_buffer_in_size):
            self.input_buffer[i] = chr(0x00)
        for i in range(self.usb_buffer_out_size):
            self.output_buffer[i] = chr(0x00)

        # Clear any possible halt on the endpoints
        ret = usb.clear_halt(self.libusb_handle,self.usb_bulkout_ep_address)
        ret = usb.clear_halt(self.libusb_handle,self.usb_bulkin_ep_address)

        # Buffer position marker for reading from and writing to buffer
        self.output_buffer_pos = 0
        self.input_buffer_pos = 0

        # Set bref function based on python version
        if get_python_vnum() >= BYREF_EXISTS_VNUM:
            self.byref = ctypes.byref
        else:
            self.byref = byref_via_pointer