Comments (14)
The same happed to me. The problem is with the stream reader being
assyncronous,
thus working in a diferent thread that keeps on living waiting for the data
that
never arrives because we've killed our app.
I've changed the code to read sincronously and it now works fine.
Original comment by [email protected]
on 17 Mar 2008 at 4:20
from csharp-usb-hid-driver.
How did you change the code?
Original comment by [email protected]
on 25 Mar 2008 at 12:28
from csharp-usb-hid-driver.
I ended up adding Environment.exit(0) to my formClosed event handler. Seems to
kill
the app without consequences.
Original comment by [email protected]
on 25 Mar 2008 at 1:17
from csharp-usb-hid-driver.
ClassDiagram1.cd
Warning 1 The type 'USBHIDDRIVER.USBInterface' in 'C:\Documents and
Settings\Administrator\Desktop\usb\csharp-usb-hid-driver\USBHIDDRIVER\Interface.
cs'
conflicts with the imported type 'USBHIDDRIVER.USBInterface' in 'c:\Documents
and
Settings\Administrator\Desktop\usb\csharp-usb-hid-
driver\USBHIDDRIVER\bin\Release\USBHIDDRIVER.dll'. Using the one in
'C:\Documents
and Settings\Administrator\Desktop\usb\csharp-usb-hid-
driver\USBHIDDRIVER\Interface.cs'. C:\Documents and
Settings\Administrator\Desktop\usb\csharp-usb-hid-
driver\USBHIDDRIVER\TESTS\TestFixture.cs 13 22 USBHIDDRIVER
Original comment by [email protected]
on 27 Apr 2008 at 11:37
from csharp-usb-hid-driver.
I had this issue and I followed nikanj and used Environment.exit(0). This
kills all
the processes running and the application exits without issue. I'm assuming
this
won't cause and issues with leaving any open
threads/processes/handles/usb/windows
etc. So far all is well.
Original comment by [email protected]
on 1 Oct 2008 at 7:07
from csharp-usb-hid-driver.
This "Environment.exit(0)" also solved the same issue for me. I exposed
Dispose in
HIDUSBDevice to test where it was hanging and it seems to be when CT_CloseHandle
calls CloseHandle(hObject) it never returns.
On a side note its a great dll that I've found very useful.
Original comment by chris.towles
on 9 Jul 2009 at 7:21
from csharp-usb-hid-driver.
Hey, first of all thanks. I use the device list and i get a big string then i
tried to connect but its not possible the Connect() method keep returning
false( tried to connect a game controller):
USBHIDDRIVER.USBInterface myUsb = new USBHIDDRIVER.USBInterface("vid_0583",
"pid_206F");
String[] list = myUsb.getDeviceList();
foreach (String st in list)
{
lstDevices.Items.Add(st);
}
if (myUsb.Connect() != false)
{
lstDevices.Items.Add("Device Connected");
/*myUsb.enableUsbBufferEvent(new System.EventHandler(myEventCacher));
System.Threading.Thread.Sleep(2000);
myUsb.startRead();*/
}
else
{
lstDevices.Items.Add("I cant establised connection");
}
What i am doing wrong?
Thank you in advance
Original comment by [email protected]
on 23 Nov 2010 at 5:04
from csharp-usb-hid-driver.
change the vid and pid addresses to lowercase
Original comment by [email protected]
on 4 May 2011 at 1:33
from csharp-usb-hid-driver.
Since I really did not like the idea of using Environment.Exit(0) to solve this
problem I took a look at the windows API calls involved. The actual issue was
that the call to ReadFile() blocks execution and waits for data to become
available. Since the call to ReadFile() is in a separate thread, using a
blocking call is fine except that it will not stop blocking until it receives
input. Even after we try to close the application, that thread is still
waiting.
I first tried to use the windows API CancleIo() to close the handle and make
the ReadFile() function return immediately. This didn't work because that
function only works if it is called from the same thread as the call to
ReadFile(). This is impossible since the thread is blocked! I then found
CancelIoEx() which performs the same function as CancelIo(), but works from any
thread no matter who owns the handle. It worked!
I modified the function CT_CloseHandle(int hObject) to be as follows:
public unsafe int CT_CloseHandle(int hObject)
{
HidHandle = -1;
CancelIoEx(hObject, IntPtr.Zero);
return CloseHandle(hObject);
}
To use this you will also need to define the CancelIoEx function as follows:
[DllImport("kernel32.dll")]
static public extern int CancelIoEx(int hFile, IntPtr pOverlapped);
Kyle
Original comment by [email protected]
on 20 May 2012 at 7:04
from csharp-usb-hid-driver.
[deleted comment]
from csharp-usb-hid-driver.
Will someone provide us the same solution as Kyle for Windows xp or earlier
machines?
This is necessary as CancelIoEx is not included in XP machines.
Will be greatly appreciated..
Aelex
Original comment by [email protected]
on 3 Dec 2012 at 4:11
from csharp-usb-hid-driver.
I followed Kyle's steps, but the problem presisted.
My application threw a NullReferenceException when executing the
usbThread.Abort() in the disconnectDevice()-function.
usbThread is defined, but never used. After following Kyle's steps I changed
the usbThread.Abort() to dataReadingThread.Abort(), which made my application
stop correctly.
Jelle
Original comment by [email protected]
on 18 Apr 2013 at 3:07
from csharp-usb-hid-driver.
fgg
Original comment by [email protected]
on 6 Dec 2013 at 3:36
from csharp-usb-hid-driver.
Hello, Sorry for the preweious post.
I want to ask you Kyle, beacuse I'm have the same problem, with exiting,
stopping the reading from USB, that where, and how to call this
CT_CloseHandle(int hObject) method. I already made your changes, but my wpf app
still not close properly. When I use it, from a simple project app, than this
problem doesn't appears. So with the event handling mode(enableUsbBufferEvent),
how can I stop the reading thread. Or should I use the start/stop mode for
reading?
Thank You!
Original comment by [email protected]
on 6 Dec 2013 at 3:43
from csharp-usb-hid-driver.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from csharp-usb-hid-driver.