Author Topic: Error reading from USB pipe  (Read 1205 times)

J.Beck

  • Newbie
  • *
  • Posts: 11
    • View Profile
Error reading from USB pipe
« on: October 28, 2011, 07:55:49 am »
Hello,

during debugging of my application, i found a strange bug which appears only under distinct circumstances. In TnrUSBPipePair.ThreadExecute there is a call to fUsbDevice.Api.Read. After this call the GetLastError is checked to be ERROR_IO_PENDING, which is normally the case.

TnrWinUsbApi.Read for WinUSB reads as foolows:

function TnrWinUsbApi.Read(idPipe: integer; data: pointer; len: integer;
  ovl: POVERLAPPED): integer;
var sz:dword;
begin
  Result := 0;
  if IsValid then begin
    if ovl <> nil then ZeroMemory(ovl, SizeOf(TOVERLAPPED) - SizeOf(THandle));
    if WinUsb_ReadPipe(hWinUsb, idPipe, data, len, sz, ovl) then begin
      Result := sz;
    end else OutputDebugString('Read Error');
  end;
end;

Now the following can happen:

In a system where no Debugger is present, OutputDebugString throws an Error (at least this is the case under XP SP3), This meens that GetlastError now gives an error (File not found) which is different to ERROR_IO_PENDING. In this case thef UsbDevice.Api.GetOverlappedResult in TnrUSBPipePair.ThreadExecute is not called and the read fails.
In my case this leads to the effect, that the application runs perfectly under the Delphi IDE, but fails if started standalone.
I deleted the OutputDebugString and the standalone versions runs ok too.

Maybe there are more places in the code which are effected by this phenomen.

Best regards
Joachim

J.Beck

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Error reading from USB pipe
« Reply #1 on: December 02, 2011, 02:45:13 pm »
Hello Mr. Novgorodov,

please recheck the problem discribed above. It is very annoying  to remove all these OutputDebugString statements from the source every time a new version appears.

Best regards
Joachim