linas | 23 May 2013 09:12
Picon

Regarding LibUsbDotNet ObjectDisposedException

Hello,


I am using LibUsbDotNet library. Here I have faced one problem using UsbEndpointWriter.UsbWriter() method. The problem occurs
when I disconnect the USB cable. I got ObjectDisposedException in my application. How to avoid this?

In my source code I close USB resources in case of transmission failure.

            if (bUsbReady)
            {
                if (UsbWriter.Write(data, 20, out uiBytesTransmitted) == ErrorCode.None)
                {
                    return true;
                }
                else
                {
                    closeDevice();
                    return false;
                }
            }



In my closeDevice() method I dispose all necessary objects in case of UsbWrite failure.

        public static void closeDevice()
        {
            bUsbReady = false;

            if (mUsbDevice != null)
            {
                if (mUsbDevice.IsOpen)
                {
                    if (UsbReader != null)
                    {
                        //Isvalom priemimo buferi (nemeta dispose exception)
                        // Always disable and unhook event when done.
                        UsbReader.DataReceivedEnabled = false;
                        UsbReader.DataReceived -= (OnDataReceived);
                        //UsbReader.ReadFlush();
                        UsbReader.Abort();
                        UsbReader.Dispose();
                        UsbReader = null;
                    }

                    if (UsbWriter != null)
                    {
                        UsbWriter.Abort();
                        UsbWriter.Dispose();
                        UsbWriter = null;
                    }

                    mUsbDevice.ActiveEndpoints.Clear();
                    // If this is a "whole" usb device (libusb-win32, linux libusb)
                    // it will have an IUsbDevice interface. If not (WinUSB) the 
                    // variable will be null indicating this is an interface of a 
                    // device.
                    IUsbDevice wholeUsbDevice = mUsbDevice as IUsbDevice;
                    if (!ReferenceEquals (wholeUsbDevice, null))
                    {
                        // Release interface #0.
                        wholeUsbDevice.ReleaseInterface(0);
                    }

                    
                    mUsbDevice.Close();
                    UsbDevice.Exit();
                    mUsbDevice = null;
                    
                    

                }
            }
        } 
------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
_______________________________________________
Libusb-win32-devel mailing list
Libusb-win32-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
Warren Terrall | 10 May 2013 17:42
Picon

usb_find_devices() is zero

I realize that this has been posted about before, but I can't seem to find
the answer to my problem. I have some simple enumeration code that looks for
the usb busses and devices. However usb_find_devices() always returns zero.
Since there aren't any devices I can't connect to anything later.

I have run testlibusb-win.exe as some of the other posts have suggested and
get the following output:

/DLL version:	1.2.6.0
Driver version:	-1.-1.-1.-1

bus/device  idVendor/idProduct/

Honestly I'm not sure what it means.
Most of the code I'm using was provided by Microchip in one of their
examples.

Thanks in advance!
~Warren

///////////////////////////////////// Code
////////////////////////////////////////////
if ( Connection_Status != CONNECTED)  // if not connected already
{
	int count;
	usb_init(); /* initialize the library */
	usb_find_busses(); /* find all busses */
	count = usb_find_devices(); /* find all connected devices */

	//Now look through the list that we just populated.  We are trying to see
if any of them match our device.
	struct usb_bus *bus;
	struct usb_device *dev;
	for(bus = usb_get_busses(); bus; bus = bus->next)
	{
		for(dev = bus->devices; dev; dev = dev->next)
		{	
			if(dev->descriptor.idVendor == MY_VID
		 	      && dev->descriptor.idProduct == MY_PID)
	 		{
 				MyLibusbDeviceHandle = usb_open(dev); //Opens a USB device 
				break;
 			} 
		}
	}
	if(!MyLibusbDeviceHandle)
	{
                // Always ends up here because their are no devices to
connect to.
	        this->Connect_btn->Text = L"Failed";
		return;

	}
	if(usb_set_configuration(MyLibusbDeviceHandle, 1) < 0) // Sets the Active
configuration of the device
	{
		usb_close(MyLibusbDeviceHandle);
		this->Connect_btn->Text = L"Failed";
		return;
	}

	if(usb_claim_interface(MyLibusbDeviceHandle, 0) < 0)  //claims the
interface with the Operating System
	{
		//Closes a device opened since the claim interface is failed.
		usb_close(MyLibusbDeviceHandle);
		this->Connect_btn->Text = L"Failed";
		return ;

	}
	ToggleLED_btn->Enabled = true;				//Make button no longer greyed out
	GetPushbuttonState_btn->Enabled = true;	//Make button no longer greyed out
	StateLabel->Enabled = true;	            //Make label no longer greyed out
	Connection_Status = CONNECTED;	            //Now status is connected
}
///////////////////////////////////// End of Code
////////////////////////////////////////////

--
View this message in context: http://libusb.6.n5.nabble.com/usb-find-devices-is-zero-tp5711961.html
Sent from the LibUSB Dev - Win32 mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and 
their applications. This 200-page book is written by three acclaimed 
leaders in the field. The early access version is available now. 
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
Martin Reekie | 6 May 2013 17:25
Picon
Picon

usb_set_configuration error, Win 7

Folks,

I'm so sorry to bother you with something that is probably well known, 
but all I can find on the web about this are problems, not solutions.

I have been running a 32-bit XP machine for ages, using
libusb-win32-bin-1.2.6.0 and everything has been fine.  I have now moved 
to a Windows 7 machine, still 32-bit, and all is not fine.

I am using libusb to get data from a PIC18 microcontroller.  I fired up 
the microcontroller for the first time and the PC shot off to find 
drivers.  I tried to stop it, and I may have succeeded, but it's hard. 
I have de-installed the driver it chose (which might have been right) 
and tried to install the one I have just downloaded from SoundForge, but 
I'm not certain.

I think I have the latest drivers installed, fighting Win 7 all the way. 
  I have told Win 7 not to find drivers itself, but it's ignoring me.

Anyway, it all looks OK until I run my "C" program to get data.  The 
start of the program is appended.  All is well till 
"usb_set_configuration", when I get an error of -5, and I have no idea 
why.  I've been using this sort of code for literally years.

Can anyone please tell me what's going on and how to fix it?!

Martin

***************

#include <usb.h>
#include <stdio.h>
#include <time.h>

Blah, blah, then

	usb_dev_handle *dev = NULL; /* the device handle */

	usb_init(); /* initialize the library */
	usb_find_busses(); /* find all busses */
	usb_find_devices(); /* find all connected devices */

	if(!(dev = open_dev()))
		{
		printf("error: device not found!\n");
		return 0;
		}

	i = usb_set_configuration(dev, 1);

	if(i < 0)
		{
		printf("error %d: setting config 1 failed\n", i);
		usb_close(dev);
		return 0;
		}

and so on ...

When I run this I get:  "error -5: setting config 1 failed" and it quits.

-- 
**********************************************
* Dr Martin Reekie                           *
* Senior Lecturer                            *
* School of Engineering                      *
* The University of Edinburgh                *
* King's Buildings, Mayfield Road            *
* Edinburgh  EH9 3JL                         *
* Tel +44 131 650 5563                       *
* FAX +44 131 650 6554                       *
**********************************************

The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
Ekkehard | 6 May 2013 09:28
Favicon

Re: LIBUSB does not detect USB device after a Shorting USB cables

Hi,
your message has not been sent to the list, probably you are not a member of
the mailing list, so only very few people will see your messsage.

In USB 2.0:

The actual length (if not too long) of the usb cable is usually not a
problem. However, we have seen that sometimes if the receiver circuit is not
prooper attached to the bus (wrong restors, missing connection to ground,
inpropper shilding  etc.) could lead into the situation that it works under
a specific cable length, but fail on others.

You may read the recommendations of cypress
http://www.cypress.com/?docID=32407

In our expieriences a proper two layer design is rock solid
Greets Ekkehard

--
View this message in context: http://libusb.6.n5.nabble.com/LIBUSB-does-not-detect-USB-device-after-a-Shorting-USB-cables-tp5711842p5711903.html
Sent from the LibUSB Dev - Win32 mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
Hans Müller | 4 May 2013 09:51
Picon
Picon

libusbk: ErrorCode=0000138Eh ->PoolHandle_Inc_UsbK

Hello, I'm stuck with a problem I do not understand. Basically I have a USB device, where I specify an alternate setting. After that I want to use the streaming API to get data from the device using a certain endpoint number. But the debug log is like this: (libusbK.lib)[k_Init_Version] libusbK.sys v3.0.5.16 [ERR](libusbK.lib)[UsbStack_QuerySelectedEndpoint] ErrorCode=0000138Eh ->PoolHandle_Inc_UsbK [ERR](libusbK.lib)[StmK_Init] ErrorCode=0000138Eh PipeID not found on selected interface =========> microdau.dll (Time[s]:14.150676): StmK_Init failed. ErrorCode: 0000138Eh I think the problem is not the PipeID (because the PipeID is valid for the chosen alternate setting), but the mesage before: PoolHandle_Inc_UsbK I appreciate any help. Thanks! Hans
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite
It's a free troubleshooting tool designed for production
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap2
_______________________________________________
Libusb-win32-devel mailing list
Libusb-win32-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
David Schober | 3 May 2013 06:07

libusbdotnet - Issue retrieving device SN on Mac (under Mono)

I apologies if this is being posted to the wrong mailing list. The support forum for LibUsbDotNet indicated that this was now the place to ask these questions:

 

My apologies for the newbie question. I’ve spent many frustrating hours trying to retrieve a USB device’s serial number (which I believe is stored as a string descriptor in the device – see SerialStringIndex property below). Initially I tried to retrieve this information via the MonoUsbDevice.MonoUsbDeviceList method. Although I can find my particular device in this list, the Info (UsbDeviceInfo class) property returns empty strings for all three of the ManufacturerString, ProductString and SerialString  properties:

 

(UsbDeviceInfo – Info property via MonuUsbDevice)

{Length:18

DescriptorType:Device

BcdUsb:0x0110

Class:PerInterface

SubClass:0x00

Protocol:0x00

MaxPacketSize0:64

VendorID:0x067B

ProductID:0xAAA5

BcdDevice:0x0300

ManufacturerStringIndex:1

ProductStringIndex:2

SerialStringIndex:3

ConfigurationCount:1

ManufacturerString:

ProductString:

SerialString:

}

 

I was eventually able to get what I wanted using the UsbDevice.AllDevices.FindAll method to retrieve a UsbRegDeviceList from which I found my particular WinUsbDevice with the following Info property. Note that the SerialString and other string properties are now populated.

 

(UsbDeviceInfo – Info property via WinUsbDevice)

{Length:18

DescriptorType:Device

BcdUsb:0x0110

Class:PerInterface

SubClass:0x00

Protocol:0x00

MaxPacketSize0:64

VendorID:0x067B

ProductID:0xAAA5

BcdDevice:0x0300

ManufacturerStringIndex:1

ProductStringIndex:2

SerialStringIndex:3

ConfigurationCount:1

ManufacturerString:Prolific Technology Inc.

ProductString:ALRT USB-SERIAL ADAPTOR

SerialString:09500006

}

 

I neglected to mention earlier that the goal of all of this was to run this code on Mac. With that in mind, I took the working Windows code and ran it on Mac. Unfortunately, it doesn’t work as expected. Instead of WinUSBDevice instances (ie: the Device property of the UsbRegistry class) I get MonoUsbDevice instances (when calling the UsbDevice.AllDevices.FindAll method). Just as I discovered earlier, the MonoUsbDevice instances returned on the Mac also do not have the SerailString property populated.

 

From the above I have two questions:

1)      Why does the MonoUsbDevice instance lack this information? Is this is bug or by design? Note that I poked around in memory near one of the handles associated with my MonoUsbDevice and am clearly able to see the SN in memory. What I can’t figure out is how the memory location is even associated to the MonoUsbDevice (if at all). The fact that it’s in memory , however, clearly suggests that the information is being loaded and should be accessible)

 

2)      Is there something entirely unrelated, to the above that, I’ve overlooked. Note that getting the SN on Mac is really what I need.

 

------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite
It's a free troubleshooting tool designed for production
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap2
_______________________________________________
Libusb-win32-devel mailing list
Libusb-win32-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
Fang Liu | 23 Apr 2013 20:24
Picon

failed to run the show.Info example.

hello

I've downloaded the libusbdotnot 2.8.2 source code and tried to run the show.Info example from Visual studio 2012 on my Windows 7 machine.  But nothing prints out, I don't know why. Could someone help me?

--
Liu Fang
------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
_______________________________________________
Libusb-win32-devel mailing list
Libusb-win32-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
Ekkehard | 22 Apr 2013 10:01
Favicon

UsbK_SetCurrentAlternateSetting Isochronous transfer and used bandwidth in root hub

Hello,
I found a bad behaviour of the UsbK_SetCurrentAlternateSetting function,
while selecting a setting containing an EP with isochronous transfer.
As known, one can see the reserved USB bandwidth in the device manager,
selecting the corresponding USB root-hub and than selecting the tab
"Advanced".
After calling UsbK_SetCurrentAlternateSetting the reserved bandwidth is
shown correct. However, after terminating the process the display of the
reserved bandwidth persists, until the device is unplugged.
Only a call of UsbK_SetCurrentAlternateSetting and a selection of a "Null"
bandwidth setting can remove the device from the list of displayed
bandwidth.
To verify that the displayed bandwidth is actual the reserved bandwidth, I
attached several devices start the streaming and stop the streaming with and
without a closing UsbK_SetCurrentAlternateSetting call with the "Null"
setting. 
Result: The bandwidth reservation persists, and blocks the bus from using by
other devices.
Conclusion: It is highly recommended to call
UsbK_SetCurrentAlternateSetting(usbhandle, 0) prior closing the usbhandle. 
I recommend also to include this statement into the documentation. 
I expect this behaviour also with the libusb library function
libusb_set_interface_alt_setting.

Best regards
Ekkehard

--
View this message in context: http://libusb.6.n5.nabble.com/UsbK-SetCurrentAlternateSetting-Isochronous-transfer-and-used-bandwidth-in-root-hub-tp5711791.html
Sent from the LibUSB Dev - Win32 mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
Milan Drášil | 21 Apr 2013 12:28
Picon

Problem with LibUsbDotNet under LINUX

Hi all,
 
I've got a problem with LibUsbDotNet (2.2.8.104) and simple USB thermometer
TEMPerV1.2. Under WIN 7 the application runs OK, problem is in LINUX
(Linux raspberrypi 3.6.11-0-raspberrypi, image from OpenSuse LINUX).
 
1) USB info runs OK
 
2) Detach Linux Kernel Driver also runs OK, after that "lsusb -t" shows "no driver"
 
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/3p, 480M
        |__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=smsc95xx, 480M
        |__ Port 3: Dev 5, If 0, Class=Human Interface Device, Driver=, 1.5M
        |__ Port 3: Dev 5, If 1, Class=Human Interface Device, Driver=, 1.5M
 
3) OpenUsbDevice, SetConfiguration and ClaimInterface(s) is OK (without detaching kernel
   driver fires the exception "resource busy" is returned).
 
4) ControlTransfer(s) also OK, returns correct number of transferred bytes.
 
5) But, any attempt to read (OpenEndpointReader.., Read...) from device ends with
   "-7:ErrorTimeout:Operation timed out" (I've tried timeout value from 100
   to 10000 with no difference).
 
   This is under above metioned LINUX only, under WIN 7 everything runs OK.
 

Thanks in advance for any help..
 
Milan Drasil
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Libusb-win32-devel mailing list
Libusb-win32-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
Ekkehard | 19 Apr 2013 18:30
Favicon

BSOD on UsbK_SetCurrentAlternateSetting

Hello,
I am operating on 4 identical pieces of hardware. Four independent Instances
of my software are controlling this devices. The call is embedded in a
thread, the thread is in a DLL.
The BSOD occours calling the function UsbK_SetCurrentAlternateSetting of the
forth device (e.g. devices 1 to 3 have sucessfully started there work) 

The identical code called prior to the failing code is

      if not UsbK_SetConfiguration(usbHandle,1) then Exit;
      if not UsbK_ClaimInterface(usbHandle,interfaceIndex,True) then Exit;
      interfaceClaimed := True;
      if not UsbK_SetCurrentAlternateSetting(usbHandle,AltInterface) ... 
//<------ here BSOD in the 4th call

The BSOD occours with Windows XP (32bit) and Windows 7 (64bit), and both
with libusbK version 3.0.5.13 and 3.0.5.16

The minidump says:
Problem signature:
  Problem Event Name:	BlueScreen
  OS Version:	6.1.7601.2.1.0.256.1
  Locale ID:	1033

Additional information about the problem:
  BCCode:	10d
  BCP1:	0000000000000005
  BCP2:	0000057FEE162A58
  BCP3:	0000000000001200
  BCP4:	FFFFFA8011E1A010
  OS Version:	6_1_7601
  Service Pack:	1_0
  Product:	256_1

Details of the calling stack are:
Filename: libusbK.sys
Address In Stack: libusbK.sys+304b
To Address: fffff880`06f59000
>From Address; fffff880`06f69000
Size: 0x00010000
Time Stamp: 0x4fad69b0
Time String: 5/11/2012 9:34:08 PM

The output of the TestLibUsb is:
DLL version:	1.2.6.0
Driver version:	3.0.5.16

bus/device  idVendor/idProduct
bus-0/\\.\libusb0-0255--0xXXXX-0xXXXX     XXXX/XXXX
- Manufacturer : XXXXXXXXXX
- Product      : XXXXX
- Serial Number: XXXXXXXXX
bLength:             18
bDescriptorType:     01h
bcdUSB:              0200h
bDeviceClass:        00h
bDeviceSubClass:     00h
bDeviceProtocol:     00h
bMaxPacketSize0:     40h
idVendor:            XXXXh
idProduct:           XXXXh
bcdDevice:           0100h
iManufacturer:       1
iProduct:            2
iSerialNumber:       3
bNumConfigurations:  1
  wTotalLength:         55
  bNumInterfaces:       1
  bConfigurationValue:  1
  iConfiguration:       0
  bmAttributes:         80h
  MaxPower:             250
    bInterfaceNumber:   0
    bAlternateSetting:  0
    bNumEndpoints:      2
    bInterfaceClass:    255
    bInterfaceSubClass: 0
    bInterfaceProtocol: 0
    iInterface:         0
      bEndpointAddress: 84h
      bmAttributes:     01h
      wMaxPacketSize:   0
      bInterval:        1
      bRefresh:         0
      bSynchAddress:    0
      bEndpointAddress: 85h
      bmAttributes:     01h
      wMaxPacketSize:   0
      bInterval:        1
      bRefresh:         0
      bSynchAddress:    0
    bInterfaceNumber:   0
    bAlternateSetting:  1
    bNumEndpoints:      2
    bInterfaceClass:    255
    bInterfaceSubClass: 0
    bInterfaceProtocol: 0
    iInterface:         0
      bEndpointAddress: 84h
      bmAttributes:     01h
      wMaxPacketSize:   940
      bInterval:        1
      bRefresh:         0
      bSynchAddress:    0
      bEndpointAddress: 85h
      bmAttributes:     01h
      wMaxPacketSize:   940
      bInterval:        1
      bRefresh:         0
      bSynchAddress:    0

Any ideas on this Item?
Best regards
Ekkehard

--
View this message in context: http://libusb.6.n5.nabble.com/BSOD-on-UsbK-SetCurrentAlternateSetting-tp5711772.html
Sent from the LibUSB Dev - Win32 mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
Ryan Buerger | 13 Apr 2013 19:15
Picon
Gravatar

Upper Level Filter Blocking Data from Vendor Driver?

I'm fairly new to driver and libusb development and am having a few issues with an upper level filter driver I am developing. Basically I installed the vendor driver and then the libusb filter driver on top. I can receive events just fine once I do the following:

     wholeUsbDevice.SetConfiguration(1);
     wholeUsbDevice.ClaimInterface(0);

Once I set the configuration, I start receiving data from the libusb driver, but the vendor driver functionality stops working until I do a wholeUsbDevice.ResetDevice(), but that stops the libusb driver data from flowing.

I'm trying to determine if I just don't understand filter drivers and this is by design or if I am doing something wrong. My goal is to augment the vendor's driver but still have their driver handle the bulk of the communications. Is that an achievable goal?

Thank you!
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Libusb-win32-devel mailing list
Libusb-win32-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel

Gmane