Ejemplo n.º 1
0
    def relance_transfert(self, transfer_i):
        """
        relance (ou pas) le transfert du buffer courant

        :param transfer_i:
        :return:
        """

        # calcul du numero du pkt si on le relance
        id_futur = self.num_pkt + self.n_tdf
        if id_futur == self.n_pkt - 1:
            # le paquet sera le dernier de la liste :
            # avant de le relancer, il faut changer la taille du buffer attendu
            # on allonge egalement la taille du timeout pour avoir le temps de lancer l instruction packend
            libusb1.libusb_fill_bulk_transfer(transfer_i, self.usbh.handle, self._ADDR,
                                              self.bbuffer_p[self.num_pkt % self.n_tdf],
                                              self.s_l_pkt, self.fn_callback_c, NULL, 10 * self.TIMEOUT)
            # on relance le transfert
            retour = libusb1.libusb_submit_transfer(transfer_i)
            if retour:
                print (".....Erreur " + str(retour) + " au lancement transfert du dernier paquet " + str(self.num_pkt))
                # else:
                #    print "dernier paquet, s_pkt = " + str(self.s_l_pkt)
        elif id_futur < self.n_pkt - 1:
            # le paquet sera un paquet (normal) dans la liste :
            # on relance le transfert
            retour = libusb1.libusb_submit_transfer(transfer_i)
            if retour:
                print (".....Erreur " + str(retour) + " au lancement du paquet " + str(self.num_pkt))
                # else:
                #    print "paquet standard"
        elif id_futur > self.n_pkt - 1 or self.etat==0:
            # le paquet ne sera pas un paquet de la liste :
            # on ne relance pas le transfert
            pass
Ejemplo n.º 2
0
 def init_transfert_usb(self):
     print ("initialisation du transfert usb <-> Mm")
     for i in range(self.n_tdf):
         self.transfert[i] = libusb1.libusb_alloc_transfer(0)
         libusb1.libusb_fill_bulk_transfer(self.transfert[i], self.usbh.handle, self._ADDR, self.bbuffer_p[i],
                                           self.s_pkt,
                                           self.fn_callback_c, self.NULL, self.TIMEOUT)
         retour = libusb1.libusb_submit_transfer(self.transfert[i])
         if retour:
             print ("Erreur " + str(retour) + " au lancement du paquet" + str(i))
             # else:
             #    print "Pret a recevoir"
     print ("initialisation du transfert usb <-> Mm .................... ok")
     self.etat=1
Ejemplo n.º 3
0
    def setBulk(self, endpoint, buffer_or_len, callback=None, user_data=None,
            timeout=0):
        """
        Setup transfer for bulk use.

        endpoint: endpoint to submit transfer to (implicitly sets transfer
          direction).
        buffer_or_len: either a string (when sending data), or expected data
          length (when receiving data)
        callback: function to call upon event. Called with transfer as
          parameter, return value ignored.
        user_data: to pass some data to/from callback
        timeout: in milliseconds, how long to wait for devices acknowledgement
          or data. Set to 0 to disable.
        """
        if self.__submitted:
            raise ValueError('Cannot alter a submitted transfer')
        string_buffer = create_binary_buffer(buffer_or_len)
        self.__initialized = False
        libusb1.libusb_fill_bulk_transfer(self.__transfer, self.__handle,
            endpoint, string_buffer, sizeof(string_buffer),
            self.__ctypesCallbackWrapper, user_data, timeout)
        self.__callback = callback
        self.__initialized = True
Ejemplo n.º 4
0
 def fillBulkTransfer(self, transfer, endpoint, string_buffer,
                      callback, user_data, timeout):
     libusb1.libusb_fill_bulk_transfer(transfer, self.handle,
         endpoint, string_buffer, sizeof(string_buffer),
         libusb1.libusb_transfer_cb_fn_p(callback), user_data,
         timeout)