Author Topic: call to HidD_SetNumInputBuffers does not change buffer size  (Read 19002 times)

chrismott

  • Member
  • ***
  • Posts: 3
call to HidD_SetNumInputBuffers does not change buffer size
« on: October 30, 2012, 05:10:03 am »
Working on software for reading from my HiD device, and am occasionally not able to read the buffer fast enough. In Windows 7, I'm making a call to HidD_SetNumInputBuffers, with a value of 200, however it doesn't seem to have an effect. When I call HidD_GetNumInputBuffers it always returns 32 (the default value). 

Anyone know what could cause HidD_SetNumInputBuffers not to work?

Thanks,
Chris

PS. Jan's USB Complete book, has been very helpful in getting me this far.

moelski

  • Member
  • ***
  • Posts: 12
Re: call to HidD_SetNumInputBuffers does not change buffer size
« Reply #1 on: October 30, 2012, 09:04:03 am »
Hi Chris,

actually I´m writing my own USB / HID / Serial component for C#. And I was also at the point regarding the InputBuffer.
My actual results are the following ...
Mostly the slow component (especially for HID devices) is the device itself. So instead of increasing the buffer I spoke to the device vendor. And he made the device sending data every ms instead of every 10ms.

So are you sure that you run into trouble if you don´t increase the buffer?

Greetings Dominik

Maybe not the answer you need, but maybe a hint   ;)

chrismott

  • Member
  • ***
  • Posts: 3
Re: call to HidD_SetNumInputBuffers does not change buffer size
« Reply #2 on: October 30, 2012, 05:19:26 pm »
Dominik,

Yes, with interrupt data transfers coming every 1ms, the Windows software is able to keep up 99.9% of the time. I have a high priority thread reading from the USB buffer. Problem is that very occasionally, there is another process in Windows that delays the thread for more than 32ms, and I lose a few messages.

It's very close to working, but losing messages is still unacceptable.  If I could actually get the buffer up to 200, then I'm quite sure this wouldn't happen.

Chris
 

moelski

  • Member
  • ***
  • Posts: 12
Re: call to HidD_SetNumInputBuffers does not change buffer size
« Reply #3 on: October 30, 2012, 11:59:38 pm »
Hi !

Well for me it´s working.  8)

Code: [Select]
        [DllImport("hid.dll", SetLastError = true)]
        internal static extern Boolean HidD_GetNumInputBuffers(
            IntPtr HidDeviceObject,
            ref Int32 NumberBuffers);

        [DllImport("hid.dll", SetLastError = true)]
        internal static extern Boolean  HidD_SetNumInputBuffers(
            IntPtr HidDeviceObject,
            Int32 NumberBuffers);

Code: [Select]
            int numb = 0;
            var test = DsHidApi.HidD_GetNumInputBuffers(this.SafeHandle.DangerousGetHandle(), ref numb);
            DsLog.ResultOfApiCall("HidD_GetNumInputBuffers");
            Console.WriteLine(numb);

            numb = 32 *4;
            test = DsHidApi.HidD_SetNumInputBuffers(this.SafeHandle.DangerousGetHandle(), numb);
            DsLog.ResultOfApiCall("HidD_SetNumInputBuffers");
            Console.WriteLine(numb);

            test = DsHidApi.HidD_GetNumInputBuffers(this.SafeHandle.DangerousGetHandle(), ref numb);
            DsLog.ResultOfApiCall("HidD_GetNumInputBuffers");
            Console.WriteLine(numb);

This works for me. The second reading gets 128.

You need a handle from Createfile to get this working.

Hope this helps.

Dominik

chrismott

  • Member
  • ***
  • Posts: 3
Re: call to HidD_SetNumInputBuffers does not change buffer size
« Reply #4 on: October 31, 2012, 03:29:57 pm »
Dominik,

Thanks. This prompted me to go back and check my code again, and it's working fine for me now.

I honestly don't know what was happening for me before?! Perhaps it was a timing issue or I hadn't opened the device correctly.  I'm not sure. In any case things are good for me now.

Chris