|
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 'Datalogic Heron G'.
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_080c&pid_0300#7&6f2335e&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"
Can you give me a hint where could be the problem?
|
|
|
|
|
My problem is the same...
Please answer the question!
Steve
|
|
|
|
|
Hello,
I also try to use this sample to open a Datalogic QS6500Bt barcode sacnner.
And I also meet the same error listed as follows.
System.ComponentModel.Win32Exception: Access is denied.
Please help me if there are anyone know how to solve this problem.
Thanks a lot!
Best regards,
Kevin
|
|
|
|
|
I had Access is denied exception too, but I fixed it... The problem was that in my system I have 2 devices with same vendor id and product id, but first one doesnt work and the sw uses as default the first one!
So I modified it, add a combobox and at startup list all device paths and then pick second one...
|
|
|
|
|
I have a Weight Scale which continually sends data through USB. Is there any method to pause reading data from the port?
Noman Muhammad Aftab,
Software Mechanic
|
|
|
|
|
Maybe when you don't want the data from the port, disconnect the event handler. Then reattach when you want the data.
-- Mike
|
|
|
|
|
Hi all,
i'm new to .net world and i'm translating some my c++ applications (gcc and wxwidgets) to visual c++ and .net framework.
I'm testing this HID library but i've some problems to intialize it from my applications.
This is my code:
private: UsbLibrary::UsbHidPort^ usbHidPort;
void InitializeComponent(void)
{
this->usbHidPort = (gcnew UsbLibrary::UsbHidPort(this->components));
this->usbHidPort->ProductId = 2;
this->usbHidPort->VendorId = 1121;
this->usbHidPort->OnDeviceArrived += gcnew System::EventHandler(this, &ADSBForm::usbHidPort_OnDeviceArrived);
}
private: System::Void usbHidPort_OnDeviceArrived(System::Object^ sender, System::EventArgs^ e) {
MessageBox::Show("Connected");
}
internal:
void OnHandleCreated( Object^ sender, EventArgs^ e )
{
__super::OnHandleCreated(e);
this->usbHidPort->RegisterHandle(Handle);
}
protected:
virtual void WndProc( Message %m ) override
{
this->usbHidPort->ParseMessages(m);
__super::WndProc(m);
}
The application start correctly, but when i attach my usb device... nothing happen. Why? Someone have an idea?
|
|
|
|
|
Microchip.com provides both firmware and PC software that does a variety of HID apps.
Their PC software is written in C++, so you might want to go their and try their stuff.
It's poorly coded in one big blob, with their sloppy GUI intermingled with USB access code.
I wish everybody was as organized as the guy who wrote this code here.
|
|
|
|
|
The RTHID.dll library support .Net managed C++ for USB HID device.
http://sites.google.com/site/hidlibrary/sample-code
Reagrds,
Walem Cookage
|
|
|
|
|
|
I am trying to unregister the HID device on the close of a form so I can use it in another program.
The problem is even if I set everything to null it still does not release the hid device until I close the program.
|
|
|
|
|
Did anyone ever solve this issue? I'm have the same problem - in fact, it seems to be keeping the form alive as running another CC through my reader actually crashes inside the already closed form. It's apparent that nothing I do (NULL, unregister handles, etc) is actually releasing the USB reader.
|
|
|
|
|
I'm not sure, but I got a "code never reached"-warning here
public bool UnregisterHandle()
{
if (this.handle != null)
{
return Win32Usb.UnregisterForUsbEvents(this.handle);
}
return false; <-- this is never reached!!
}
It puzzled me a bit, but in my desperation I tried to change this line
if (this.handle != (IntPtr)null)
and the warning was gone.
I always thought that the original version should work, but maybe I'm wrong and that might also be the solution for your problem.
cheers
ScruffR
|
|
|
|
|
Hi
After written the buffer you have to flush or close the file buffer to unregister the device.
/// <summary>
/// Write an output report to the device.
/// </summary>
/// <param name="oOutRep">Output report to write</param>
protected void Write(OutputReport oOutRep)
{
try
{
m_oFile.Write(oOutRep.Buffer, 0, oOutRep.BufferLength);
m_oFile.Flush();
OR
m_oFile.Close();
}
catch (IOException ex)
{
// The device was removed!
throw new HIDDeviceException("Probbaly the device was removed");
}
catch(Exception exx)
{
Console.WriteLine(exx.ToString());
}
}
modified on Thursday, July 16, 2009 6:40 AM
|
|
|
|
|
|
file: SpecifiedOutputReport.cs
Line 16
For loop starts at 1 , should start at 0 : first byte sent was always 0 , this gave me problems.
kind regards
Bakaneko
modified on Tuesday, April 8, 2008 7:01 PM
|
|
|
|
|
Hello man,
First, thank's for that article and component. It's a great job who help me a lot.
But, I still have a problem: I develop a WPF application, and the sniffer library component seems to be incompatible with wpf, as it require a winform. I dont' know how to deal with that...
Moreover, sniffer is very coupled with the winform. Have you ever think of creating an stand-alone component ?
Why not to place the winform inside the library and supply personalized events ?
Loïc
Loïc Berthollet
|
|
|
|
|
Thanks for the code, it's helping me find out more about HID.
What I'm trying to do is to detect a specific device based on PID and VID (in my case a barcode scanner) then when found I want to capture all input from that device regardless of whether my app has focus or not (ideally my app will run as a windows service).
Currently running your test app i can't even detect my particular device, when I enter the vid and pid (as found from running msinfo32.exe) it detects a device being connected and disconnected but not the specified device.
If you could offer any guidance I would be very grateful. Could you also get in touch if you are available for contract work?
Dan
danmoov2@googlemail.com
|
|
|
|
|
I was able to use this code and receive data from the USB barcode scanner.
What model of scanner are you using?
I'm using a product from Hand Held Products (model 3800g)
3800 General Purpose Linear Image Scanner[^]
The model that I have, by default is setup as a keyboard/wedge. I had to scan a programming barcode to make it a USB HID device. By doing this it also changed the Product ID from 02E1 to 02E7. There is an option to use a USB-COM emulator that allows the device to communicate with a virtual RS232 port.
|
|
|
|
|
hi man
great job!
i have been trying to catch the IR codes from my remote control for more than a month and i was too lazy to dig into HID myself.
but your application did the trick.
thanks again
|
|
|
|
|
Hi!
I'm trying to send data report to my USB device, but with no luck (i'm using your Sniffer example) It should control the LED blinking.
The SendData method doesn't work. Are you sure about writing to the USB device using FileStream ?
I hacked the USB Library and used HidD_SetFeature method and it worked. Can you please explain me how your report writing works ? I think it's a bit confusing.
Thx.
|
|
|
|
|
Hi
You have to write another method to handle the reports.
Steps For Handling Reports:
1) In win32usb.cs, add
HidD_SetOutputReport() for handling output reports and HidD_GetInputReport() for handling input reports.
-------------------------------------------------------------------------------------------
/// Send an output report to a HID device.
/// </summary>
/// <param name="HidDeviceObject">A handle to a Hid Device Object.</param>
/// <param name="ReportBuffer">The buffer of the output report to send to the device.</param>
/// <param name="ReportBufferLength">The size (in bytes) of ReportBuffer.</param>
/// <returns>'true' if successful.'false' otherwise.</returns>
[DllImport("hid.dll", SetLastError = true)] protected static extern bool HidD_SetOutputReport(IntPtr HidDeviceObject, byte[] ReportBuffer, int ReportBufferLength);
/// <summary>
/// Retrieve an input report from a HID device.
/// <param name=" HidDeviceObject">A handle to a Hid Device Object.</param>
/// <param name="ReportBuffer">The buffer that the input report should be placed into.The first byte of the buffer should be set to the report ID of the desired report.</param>
/// <param name="ReportBufferLength">The size (in bytes) of ReportBuffer. This value should be greater than or equal to the InputReportByteLength field as specified in the HIDP_CAPS structure for the device.</Param>
///<returns>'true' if successful.'false' otherwise. </returns>
[DllImport("hid.dll", SetLastError = true)] protected static extern bool HidD_GetInputReport(IntPtr HidDeviceObject, byte[] ReportBuffer, int ReportBufferLength);
-------------------------------------------------------------------------------------------
2) Write methods sendReport() and getReport() in HIDDevice.cs
protected void sendReport(OutputReport oOutRep)
{
try
{
// Call SetOutputReport to send this report buffer over the control pipe
HidD_SetOutputReport(m_hHandle, oOutRep.Buffer, oOutRep.BufferLength);
}
catch (Exception exx)
{
Console.WriteLine(exx.ToString());
}
}
protected void getReport(byte[] data,byte buffersize)
{
try
{
//Call GetInputReport to get the requested report buffer over the control pipe
HidD_GetInputReport(m_hHandle, data, buffersize);
}
catch (Exception exx)
{
Console.WriteLine(exx.ToString());
}
}
-------------------------------------------------------------------------------------------
3) In SpecifiedDevice.cs,
In class, public class SpecifiedDevice : HIDDevice write set_report() and get_report()
//set the request to send the report buffer over the control pipe.
public void set_report(byte[] data, byte buffersize)
{
SpecifiedOutputReport oRep = new SpecifiedOutputReport(this);
oRep.set_report(data, buffersize);
try
{
sendReport(oRep);
}
catch (HIDDeviceException ex)
{
}
}
//Receive the requested report buffer over the control pipe.
public void get_report(byte[] data,byte buffersize)
{
try
{
getReport(data,buffersize);
}
catch (HIDDeviceException ex)
{
}
}
-------------------------------------------------------------------------------------------
4) In SpecifiedOutputReport.cs,
public bool set_report(byte[] data, byte buffersize)
{
byte[] arrbuff = Buffer;
for (int i = 0; i < buffersize; i++)
{
arrbuff[i] = data[i];
}
if (arrbuff.Length < buffersize)
{
return false;
}
else
{
return true;
}
}
-------------------------------------------------------------------------------------------
5) In SpecifiedInputReport.cs,
public void get_report(byte[] inputbuffer)
{
inputbuffer = Buffer;
}
-------------------------------------------------------------------------------------------
Thank you,
|
|
|
|
|
hi mdeepa. thank u for your modifiation. i added this modification but i havent used them. do i have to do something else or is this enough??
and thx wimar for this
|
|
|
|
|
Hello,
I also tried to run the program, but as i debugged it, it seems it can't find my HID device.
My HID device vendor id and product id is correct still it returns false form "SetupDiEnumDeviceInterfaces" function.
In the "while" statement :
while (SetupDiEnumDeviceInterfaces(hInfoSet, 0, ref gHid, (uint)nIndex, ref oInterface))
{....}
It always returns false...
Please let me know solution for this asap.
Thanks.
Samir Karve
|
|
|
|
|
Add FILE_SHARE_READ | FILE_SHARE_WRITE in the CreateFile function:
m_handle = CreateFile(
DeviceName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
0,
OPEN_EXISTING,
0,
0);
regards Jan
|
|
|
|