|
You should limit the iteration variable to the data length as it's shorter.
And btw, there's an Array.Copy[^] method for this kind of stuff.
|
|
|
|
|
Hi all,
I've problems using this library to receive data from my HID device (an Oregon Scientific WMR100 weather station).
I think I made all steps correctly: I create an UsbHidPort object, I initialized the correct Product and Vendor Id, I specified a new DataRecieveHandler, I called the CheckDevicePresent method and I finally sent some data to the device to initialize it, all without any exception, but... my DataRecieveHandler is never called!
I'm sure the object is sending back data and I'm sure the data I send to initialize the device is correct.
Any idea?
Thanks in advance...
modified on Tuesday, December 30, 2008 7:03 AM
|
|
|
|
|
Did you get here from this page[^]? If not, check out the link to the C# project. I've found that the project has some problems but it should get you started.
|
|
|
|
|
Your article states: "A mouse is always in use by Windows, and cannot be captured by your own application"
Does this apply to a keyboard also?
I was hoping to control one of the leds on an extra USB keyboard so that I could switch on/off an external device. May have to toggle the Scroll-Lock led instead by other means.
Regards
|
|
|
|
|
I see you have used the sample for a special Barcode Scanner.
I'm trying to get data which I scan with the USB barcode scanner Symbol Technologies LS2208'.
Following error occurs during the Inialize Method of the HDIDevice Class:
UsbLibrary.HIDDeviceException: Msg:UsbLibrary.HIDDeviceException: Msg:Failed to create device file WinEr:00000005
at UsbLibrary.HIDDevice.Initialise(String strPath) in HIDDevice.cs:line 136
at UsbLibrary.HIDDevice.FindDevice(Int32 nVid, Int32 nPid, Type oType) in HIDDevice.cs:line 287
at UsbLibrary.HIDDevice.FindDevice(Int32 nVid, Int32 nPid, Type oType) in HIDDevice.cs:line 295
at UsbLibrary.SpecifiedDevice.FindSpecifiedDevice(Int32 vendor_id, Int32 product_id) in SpecifiedDevice.cs:line 42
at UsbLibrary.UsbHidPort.CheckDevicePresent() in UsbHidPort.cs:line 218
The Windows Error Code 5 is 'Access Denied' during Method CreateFile.
I tried your sample application on Windows XP (32-bit) and Windows Vista (64-bit)
with bug fixing of DeviceInterfaceDetailData size problem 5 or 8, doesn't help.
What I found strange was the DevicePath with the value
devicePath = "\\?\hid#vid_05e0&pid_1200#6&1aeb9946&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"
Can you give me a hint where could be the problem?
If all the tree become pen and all ocean become ink and many more other ocean become ink even then the ALLAH praise could not be written completely. (AL-Quran)
|
|
|
|
|
I'm having the same problem.
|
|
|
|
|
I get the same error and am trying to diagnose now. Google brought me here and I'm disappointed no-one has answered the question yet. on goes the search for what causes this.
|
|
|
|
|
Тот же самый EXCEPTION и у меня возникает!
|
|
|
|
|
I solved this problem replacing the next code line:
m_hHandle = CreateFile(strPath, GENERIC_READ | GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, IntPtr.Zero);
with this:
m_hHandle = CreateFile(strPath, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, IntPtr.Zero);
After that change, the CreateFile method return me a positive number
Now, I have a problem in the BeginAsyncRead method, in the code line:
m_oFile.BeginRead(arrInputReport, 0, m_nInputReportLength, new AsyncCallback(ReadCompleted), arrInputReport);
The exception I got is this:
Excepción del tipo 'System.UnauthorizedAccessException' en mscorlib.dll
Excepción del tipo 'UsbLibrary.HIDDeviceException' en UsbLibrary.dll
Excepción del tipo 'UsbLibrary.HIDDeviceException' en UsbLibrary.dll
UsbLibrary.HIDDeviceException: Msg:UsbLibrary.HIDDeviceException: Msg:Failed to get the detailed data from the hid. WinEr:00000005
en UsbLibrary.HIDDevice.Initialise(String strPath) en C:\_usb_hid\usb hid\UsbLibrary\HIDDevice.cs:línea 132
en UsbLibrary.HIDDevice.FindDevice(Int32 nVid, Int32 nPid, Type oType) en C:\_usb_hid\usb hid\UsbLibrary\HIDDevice.cs:línea 280
en UsbLibrary.HIDDevice.FindDevice(Int32 nVid, Int32 nPid, Type oType) en C:\_usb_hid\usb hid\UsbLibrary\HIDDevice.cs:línea 288
en UsbLibrary.SpecifiedDevice.FindSpecifiedDevice(Int32 vendor_id, Int32 product_id) en C:\_usb_hid\usb hid\UsbLibrary\SpecifiedDevice.cs:línea 42
en UsbLibrary.UsbHidPort.CheckDevicePresent() en C:\_usb_hid\usb hid\UsbLibrary\UsbHidPort.cs:línea 218
I hope someone help us to find a solution!
|
|
|
|
|
I have same issues when changed it,
m_hHandle = CreateFile(strPath, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, IntPtr.Zero);
mijun lai
|
|
|
|
|
I, too have had this problem. It happened after I had a full test program (form) working and then refactored to produce a new UserControl (with my device interface and Wimar's USB component included).
The 0x20 error is ERROR_SHARING_VIOLATION. Using ProcessExplorer I found that the VS(2005) dev environment was one of the processes using the hid.dll. Others have suggested modifying the access attributes to READ_SHARE, etc in the CreatFile call.
I was able to remove the lock/conflict by relocating the usb.CheckDevicePresent call from my UserControl constructor to my component's 'Initialize' method.
My guess is that when the dev environment instantiates my UserControl for use in the designer that it ends up holding onto that handle.
Hope this helps someone else not spend a day scratching their head...
Calvin A. Hobbes
|
|
|
|
|
Has anyone managed to talk to a Mustek UPS via the USB using sniffer ?
If so can you please let me know how.
Thanks
Iain
|
|
|
|
|
An unhandled exception of type 'System.Security.SecurityException' occurred in mscorlib.dll
Additional information: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
I have taken the code, changed the two IDs in the properties box and then tried to run (either from explorer or debug) and I get the error above.
Any ideas as to why?
Thanks
Iain
|
|
|
|
|
(ref Messagea m)
Messagea?
Did C# Release a New Type that I missed somewhere along the lines... ?
-= Reelix =-
|
|
|
|
|
Hi
When I downloaded and ran this code the following error occurs,
ArgumentException was unhandled.
\usb hid\UsbLibrary\obj\Debug\UsbLibrary.dll' doesn't contain any UserControl types.
Assembly 'D:\usb hid\UsbLibrary\obj\Debug\UsbLibrary.dll' doesn't contain any UserControl types.
What should I do ?
Any help appreciated.
Thanks
|
|
|
|
|
I think I can take a stab at this (correct me if I'm in error, still learning )...
We built the solution from the "UsbLibrary" project, by default this project is the startup project in the solution. All that have to be done is: to open the Solution Properties window and to change the startup project to "UsbApp" then the code should work as intended.
|
|
|
|
|
This solved the problem for me.
|
|
|
|
|
That did not work for me. Also tried copying the dll into the debug directory (another web-site suggested this). Not even 1 line of code will execute.
The included (already built) sniffer EXE will run, but when I give the device the exact same data that the USB-Spy shows it got nothing happens.
-Matt
|
|
|
|
|
Hello,
Has anyone had any experience using this library in a Windows Service?
In particular, a Windows Service does not have a window and thus the two overrides that we are told to do (OnHandleCreated and WndProc ) don't exist in that context. So far I have found that I will need to call RegisterDeviceNotification to handle what WndProc is doing and yes I have found the c# declaration for the call, but I don't know what to pass for the parameters (for example, "A handle to the window or service that will receive device events"... a handle to the service?)
Then, anyone have any clues as to how to deal with the OnHandleCreated override?
Thanks in advance,
Jim
|
|
|
|
|
The HIDDevice class says I'm supposed to derive from this class for a new controller class. I see that the SpecifiedDevice does indeed do this. But, why does SpecifiedDevice contain the DataReceieved and DataSend events and event handlers? Shouldn't these be in the base class (HIDDevice)? Also, the UsbHidPort class contains an instance of SpecifiedDevice instead of HIDDevice. I know that HIDDevice is defined as abstract so you can't create an instance of that, but doesn't this mean that if I wanted to create my own custom controller class, I should be deriving from SpecifiedDevice and NOT HIDDevice?
Can someone offer some advice please?
|
|
|
|
|
We've been looking for something well crafted like this. Thank you!
After downloading, we tried to read the HTML doc'n before plunging in.
The index for it apparently comes up OK, but the content pane always indicates "The address is not valid." Is it all linked back your website?
Please advise.
|
|
|
|
|
I bet that you when you open the project you get a message saying "The project location is not trusted". This is some daft XP thing where it knows that the files came from a zip file that came from the internet and it labels it as dodgy in some hard-to-delete way. http://www.jameskovacs.com/blog/PermaLink.aspx?guid=6985963b-3d85-41ae-bca8-5f9efe2a79c7[^] is one way to delete the labels, or an easy one is simply to copy the file to a FAT32 drive (eg memory stick) and then copy them back. Only NTFS can store the dodgy label so this results in the label being lost.
Hope this helps,
Mark
|
|
|
|
|
Amazing! I had the same problem and your solution worked perfectly.
|
|
|
|
|
Great Project!
I tried it with a USB credit card reader, and found something interesting. When I read a card that has data on track 1, the sniffer will report the data, however when I try a card that only has data on track 2, the "usb_OnDataRecieved" event does not get fired. Could you think of why this would be? I know that a report is being sent from the reader to the pc, because when I use a different program from the manufacturer to test it, I get an event with their product.
Thanks in advance.
|
|
|
|
|
in method Initialise there is a line of code I don't understand.
line 90 and 92
m_hHandle = CreateFile(strPath, GENERIC_READ | GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, IntPtr.Zero);
if (m_hHandle != InvalidHandleValue || m_hHandle == null)
If internal m_hHandle variable is null that means good? I think if creation of file pass there should be a handle, otherwise it did not pass.
if (m_hHandle != null && m_hHandle != InvalidHandleValue)
I'm not sure, It is first time I'm working with HID device.
|
|
|
|