Author Topic: USB pipe policy  (Read 1509 times)

J.Beck

  • Newbie
  • *
  • Posts: 11
    • View Profile
USB pipe policy
« on: March 24, 2014, 08:40:43 am »
Dears Sirs,

i Need to set the USB policy SHORTPACKETTERMINATE for both pipes of my connection. I found some mechanism in the source which have to do with pipe policies, but it seems to me that they are not fully implemented.
So, what can I do to chenge the pipe policies?

Thank you for your help.

Best regards
Joachim 

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: USB pipe policy
« Reply #1 on: March 24, 2014, 04:38:47 pm »
Hello

You can try call WinUsb_SetPipePolicy() but you need correct handle of WinUSB interface.
Current version contains WinUSB but it is hidden.
I think we need modify source code for make SetPolicy available as public method.

I've added this modification in TODO list for next release.

Roman Novgorodov
DeepSoftware llc
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

J.Beck

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: USB pipe policy
« Reply #2 on: March 24, 2014, 07:14:00 pm »
Hello Mr. Novgorodov,

i extended the code in nrusb_winusb_api.pas so that the WinUsb_SetPipePolicy can be accessed as a method of TnrWinUsbApi. But there must be something wrong. The result of WinUsb_SetPipePolicy is always false. This is also true for the call of WinUsb_SetPipePolicy in TnrWinUsbApi.PreparePipe (I extended the code of this method to check the result of WinUsb_SetPipePolicy, it is always false!
Do you have an idea what could be wrong here?

By the way, I think in WinUsb_GetPipePolicy is a small bug:

The declaration of the function

var p:function (InterfaceHandle:THandle; PipeId:byte;
        PolicyType:byte;var ValueLength:dword; Value:pointer):boolean; stdcall;

should read:

var p:function (InterfaceHandle:THandle; PipeId:byte;
        PolicyType:dword;var ValueLength:dword; Value:pointer):boolean; stdcall;

Thank you for your help.
Regards
Joachim
« Last Edit: March 24, 2014, 07:18:12 pm by J.Beck »

J.Beck

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: USB pipe policy
« Reply #3 on: March 25, 2014, 07:52:26 am »
Hello,

i found the error.

The following code in nrusb_winApi is wrong:

function WinUsb_SetPipePolicy(InterfaceHandle:THandle; PipeId:byte;
        PolicyType:dword;ValueLength:dword; Value:pointer):boolean;
var p:function (InterfaceHandle:THandle; PipeId:byte;
        PolicyType:dword; ValueLength:dword; Value:pointer):boolean; stdcall;
begin
  Result := False;
  if AllocWinUsbDLL then begin
    @p := GetProcAddress(hWinUsbDLL,'WinUsb_SetPipePolicy');
    if @p <> nil
      then Result := p(InterfaceHandle,PolicyType,PipeId,ValueLength,Value);
  end;
end;

It should read:

function WinUsb_SetPipePolicy(InterfaceHandle:THandle; PipeId:byte;
        PolicyType:dword;ValueLength:dword; Value:pointer):boolean;
var p:function (InterfaceHandle:THandle; PipeId:byte;
        PolicyType:dword; ValueLength:dword; Value:pointer):boolean; stdcall;
begin
  Result := False;
  if AllocWinUsbDLL then begin
    @p := GetProcAddress(hWinUsbDLL,'WinUsb_SetPipePolicy');
    if @p <> nil
      then Result := p(InterfaceHandle,PipeId,PolicyType,ValueLength,Value);
  end;
end;


Now the setPipePolicy works.

Best regards
Joachim

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: USB pipe policy
« Reply #4 on: March 25, 2014, 03:18:56 pm »
Hello

You can try to call GetLastError for error details.
Maybe something wrong with usb device driver or WinUsb API does not allow to change policy at all.

Roman Novgorodov
DeepSoftware llc
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

J.Beck

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: USB pipe policy
« Reply #5 on: April 01, 2014, 05:59:36 am »
Hello Mr. Novgorodov,

please read my last two answers again. The problem is solved! The reason is a bug in your code. Please integrate the bug fix into your next Version.

Thank you

Best regards
Joachim Beck

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: USB pipe policy
« Reply #6 on: April 01, 2014, 03:22:17 pm »
Hello

Thank you for information.

We will glad to include these changes into next release of product.
After small testing of course.
Thank you.

Roman Novgorodov
DeepSoftware llc
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.