• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 
April 28, 2024, 11:42:56 am

News:

SMF - Just Installed!


Error reading from USB pipe

Started by J.Beck, October 28, 2011, 05:55:49 am

Previous topic - Next topic

J.Beck

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

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