Python Forum
Pyusb freeze when using Dev.read(nr,nr,timeout=1000)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pyusb freeze when using Dev.read(nr,nr,timeout=1000)
#1
Shouldn't timeout release after 1sek ? As of now the code just halt with no error or anything.
Reply
#2
?? Is there a question here?

How about some code,
an error traceback,
and a question
Reply
#3
Well, why do python freeze when I call: self.dev2.read(self.endpoint2.bEndpointAddress,self.endpoint2.wMaxPacketSize,timeout=120)  ? What can I do to find out ? The call is in function: readUsbDPS()
 

import usb.core
import os
import usb.util
import time
import sys
from commandParser import commandParser_Class
from commandParserDPS import command_ParserDPS
os.environ['PYUSB_DEBUG'] = 'debug'
#import d2xx
#VENDOR_ID = 0x0922
#PRODUCT_ID = 0x8003

class slider_DPS_Class:

    def __init__(self):
        self.devT = usb.core.find(find_all=True, idVendor=7931)

        for d in self.devT:
            print (usb.util.get_string(d,2))
            x=usb.util.get_string(d,2)
            print (d.idProduct,d.idVendor)

            if (x.find('SLID')>=0):
                self.dev=d
                self.dev.reset()
                print('satt slid')

            elif (x.find('DPS')>=0):
                self.dev2=d
                print(d)
                usb.util.dispose_resources(self.dev2)
                self.dev2.reset()
                print('satt dps')

# ----------------------  usb setup ------------------------------------
        #self.dev2=usb.core.find(idVendor=0x1efb, idProduct=0x1590)
        self.endpoint = self.dev[0][(0, 0)][0]

        if self.dev is None:
            raise ValueError('Device not found')
            reattach = False
        if self.dev.is_kernel_driver_active(0):
            reattach = True
            self.dev.detach_kernel_driver(0)

        self.dev.set_configuration()

        # get an endpoint instance
        cfg = self.dev.get_active_configuration()
        intf = cfg[(0, 0)]

        self.ep = usb.util.find_descriptor(
            intf,
            # match the first OUT endpoint
            custom_match=lambda e: \
            usb.util.endpoint_direction(e.bEndpointAddress) == \
            usb.util.ENDPOINT_OUT)

        assert self.ep is not None
        self.commandX = commandParser_Class()

        #print('satt dpssss')
# ------------------------------end ---------------------------------------

# -----------------------------dps usb setup -------------------------------

#self.dev2=usb.core.find(idVendor=0x1efb, idProduct=0x1590)
        self.endpoint2 = self.dev2[0][(0, 0)][0]

        if self.dev2 is None:
            raise ValueError('Device not found')
            reattach = False
        if self.dev2.is_kernel_driver_active(0):
            reattach = True
            self.dev2.detach_kernel_driver(0)

        self.dev2.set_configuration()

        # get an endpoint instance
        cfg2 = self.dev2.get_active_configuration()
        intf2 = cfg2[(0, 0)]

        self.ep2 = usb.util.find_descriptor(
            intf,
            # match the first OUT endpoint
            custom_match=lambda e: \
            usb.util.endpoint_direction(e.bEndpointAddress) == \
            usb.util.ENDPOINT_OUT)

        assert self.ep2 is not None
        self.commandXdps = command_ParserDPS()
        self.get_L_dps()
#-------------------------------end ------------------------------------------

# --------------------------------- sli ----------------------------------

    def init1(self):
        hexCommand = (self.commandX.sendCommand(
            "SETUSEFORCEDPOSITION", 1))  # sld obey pos-values
        self.ep.write(hexCommand)
        time.sleep(0.2)
        self.get_L_Cstrokeum()
        self.get_L_Cstrokeum()
        # hexCommand = (commandX.sendCommand("SETUSEFORCEDPOSITION", 0)) # sld obey pos-values
        # ep.write(hexCommand)

        time.sleep(1)


    def readUsb(self):
        data = None
        attempts = 10
        while data is None and attempts > 0:
            try:
                data = self.dev.read(self.endpoint.bEndpointAddress,
                                self.endpoint.wMaxPacketSize)
            except usb.core.USBError as e:
                data = None
                if e.args == ('Operation timed out',):
                    attempts -= 1
                    continue
        # print(data)
        return data


    



# -------------------------------- dps -------------------------------------
    def readUsbDPS(self):
        data = None
        attempts = 10
        while data is None and attempts > 0:
            try:

                data = self.dev2.read(self.endpoint2.bEndpointAddress,
                                self.endpoint2.wMaxPacketSize,timeout=120)
            except usb.core.USBError as e:
                data = None
                if e.args == ('Operation timed out',):
                    attempts -= 1
                    continue
        return data

    def get_L_dps(self):
        try:
            hexCommand = (self.commandXdps.getCommand('T_GET_DP_PHYS'))
            print('hexcommand')
            print(hexCommand)
            #'\x01\x36\x04\x00\x00\x13\x88'
            print('bytestring')
            print('\xFC\x16')
            for i in range(1,2):
                self.ep2.write('\xFC\x16\xFC\x16\xFC\x16\xFC\x16\xFC\x16')
                #self.ep2.write(64534)
                #self.ep2.write(hexCommand)
                print(self.endpoint2.bEndpointAddress)
                print(self.endpoint2.wMaxPacketSize)
            data = self.readUsbDPS()
            #return data
        except(usb.core.USBError):
            print('USBError get_L_command')
            self.commandX.iError()
Reply
#4
Heres the output from python about the device:

INTERFACE 0: Human Interface Device ====================
    bLength            :    0x9 (9 bytes)
    bDescriptorType    :    0x4 Interface
    bInterfaceNumber   :    0x0
    bAlternateSetting  :    0x0
    bNumEndpoints      :    0x2
    bInterfaceClass    :    0x3 Human Interface Device
    bInterfaceSubClass :    0x0
    bInterfaceProtocol :    0x0
    iInterface         :    0x0
     ENDPOINT 0x81: Interrupt IN ==========================
      bLength          :    0x7 (7 bytes)
      bDescriptorType  :    0x5 Endpoint
      bEndpointAddress :   0x81 IN
      bmAttributes     :    0x3 Interrupt
      wMaxPacketSize   :   0x40 (64 bytes)
      bInterval        :   0x20
     ENDPOINT 0x1: Interrupt OUT ==========================
      bLength          :    0x7 (7 bytes)
      bDescriptorType  :    0x5 Endpoint
      bEndpointAddress :    0x1 OUT
      bmAttributes     :    0x3 Interrupt
      wMaxPacketSize   :   0x40 (64 bytes)
      bInterval        :   0x20
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000 Pleiades 8 15,437 Jan-05-2024, 08:30 PM
Last Post: sgrey
  Tkinter + Multiprocessing startmap makes UI Freeze sunny9495 4 1,322 Nov-13-2022, 12:49 PM
Last Post: sunny9495
  FTp timeout except korenron 2 3,503 Feb-01-2022, 06:51 AM
Last Post: korenron
  Found input variables with inconsistent numbers of samples: [1000, 200] jenya56 2 2,806 Sep-15-2021, 12:48 PM
Last Post: jenya56
  Python Pandas: How do I average ONLY the data >1000 from several columns? JaneTan 0 1,447 Jul-17-2021, 01:34 PM
Last Post: JaneTan
  Python Pandas: How do I extract all the >1000 data from a certain column? JaneTan 0 1,529 Jul-17-2021, 09:09 AM
Last Post: JaneTan
  mpv window freeze before video end rfeyer 18 6,899 Mar-09-2021, 06:12 PM
Last Post: rfeyer
  Install Python 3.8 for EduPython and Cx-Freeze mederic39 1 1,751 Jul-24-2020, 01:24 PM
Last Post: Larz60+
  Cx Freeze to exe - HELP WBPYTHON 5 3,800 Apr-09-2020, 01:34 PM
Last Post: WBPYTHON
  A software freeze ! HELP ! redorc15 1 1,760 Oct-10-2019, 10:54 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020