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()