|
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.
|
|
|
|
|
I think you are correct. It does not make sense to accept null as a value since it is being passed as the device handle to HidD_GetPreparsedData....
so to conclude:
if (m_hHandle != null && m_hHandle != InvalidHandleValue)
|
|
|
|
|
I don't understand what i have to do to get this to work. Can you explain it a little better?
modified on Tuesday, September 16, 2008 11:37 AM
|
|
|
|
|
I give up. This is way beyond anything I can understand.
|
|
|
|
|
I, also, have the same problem. Not sure what causes this...
Regards,
sthompson
|
|
|
|
|
"Can't get it to work" sure doesn't give anybody much to go on.
May I suggest you articulate your observations some?
I have been able to connect and send data OK. I need to go work on my device, watch how it behaves, and try to make it send some data back. I might yet experience what you have and may be of some use to you and others here.
Let's make this a useful and collaborative forum.
HTH,
Bill
|
|
|
|
|
I copied as it is code to my system and changed my VENDOR_ID = 0x07b4 and PRODUCT_ID = 0x0221. But its throwing exception on OK button click that "Input string was not in a correct format" at
this.usb.ProductId = Int32.Parse(this.tb_product.Text, System.Globalization.NumberStyles.HexNumber);
this.usb.VendorId = Int32.Parse(this.tb_vendor.Text, System.Globalization.NumberStyles.HexNumber);
Plz any one help me regard this issue...
Thanks in advance
|
|
|
|
|
I had similiar problem, I tried to input hexadecimal format of integer number. I solved it pass regular number and the hexadecimal format is use inside Detect device void.
Magtek vendor Id 2049 get translete to 0x8001 or samething like that. Hope it helps you.
|
|
|
|
|
I've written some firmware around Microchip.com's USB stack.
Initially, I am using Microchip's ID's:
VID=0x04d8 and PID=0x003f.
On Nov 7, 2008, The Sniffer program provided at this website worked the first time and everytime for me.
All I had to was type 04d8 and 003f into the two ID text boxes.
HTH
|
|
|
|