|
From: Xiaofan C. <xia...@gm...> - 2021-02-13 02:00:44
|
On Fri, Feb 12, 2021 at 11:38 PM Sumant Oemrawsingh <soe...@xs...> wrote: > > Hi guys, > > I'm trying to communicate synchronously using libusb to a PICKit 3 > (04d8:900a). > > The device has one configuration, with one interface and > alt-interface. This interface has two interrupt endpoints (one in, > one out) that I need to use. > > I notice the following behavior. > > After opening the device and detaching the dummy kernel driver, I > set the configuration, claim the interface, and set the > alt-interface. I can write to and then read from the endpoints, but when repeating a write > followed by a read, I very frequently get a read timeout. I need > to (essentially) close the device, unplug, and replug, to be able > to read again (after writing). Note that I do check the current > configuration first, to see if I need to set it. > > Clearing halt conditions doesn't help at all. > > However, when I on purpose don't set the configuration, don't > claim the interface and don't set the alt-interface, I can write > and read without any timeout issues, as often as I want. > > What's going on here? I've tried both libusb-compat and libusb-1.0 > with the synchronous interface only, on linux. I'm mostly used to > the old libusb (thus mostly using libusb-compat for now) since it > worked for all my previous projects, and am only now looking a bit > into libusb-1.0 to see if it would remedy the situation, without > luck. > Two things. 1) PICkit 3 is a USB HID device, please try HIDAPI which is the recommended library to use. 2) PICkit 3 may have a problem with the configuration setting command or alt interface setting command. You can try the following. You do need to claim the interface. But you do not need to set the alt interface as there is only one. http://libusb.sourceforge.net/api-1.0/libusb_caveats.html cfg = -1; libusb_get_configuration(dev, &cfg); if (cfg != desired) libusb_set_configuration(dev, desired); libusb_claim_interface(dev,0) ... -- Xiaofan |