• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 
April 20, 2024, 10:30:24 am

News:

SMF - Just Installed!


USB pipe policy

Started by J.Beck, March 24, 2014, 05:40:43 am

Previous topic - Next topic

J.Beck

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

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

March 24, 2014, 04:14:00 pm #2 Last Edit: March 24, 2014, 04:18:12 pm by J.Beck
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

J.Beck

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

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

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

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.