public Buffer Read() { if (first) { for (var i = 0; i < depth; i++) { buffers[i] = new byte[bufferSize]; } for (var i = 0; i < depth; i++) { queue[i] = pipe.BeginRead(buffers[i], 0, bufferSize, null, null); } first = false; } var r = queue[index]; var b = buffers[index]; var nb = new byte[bufferSize]; queue[index] = pipe.BeginRead(nb, 0, bufferSize, null, null); buffers[index] = nb; var length = pipe.EndRead(r); index = (index + 1) % depth; return(new Buffer(b, length)); }
internal void WaitForCompletion() { if (asyncResult == null) { throw new ScopeIOException("Can't wait for command's completion before executing command"); } try { if (endPoint.IsOut) { endPoint.EndWrite(asyncResult); } else if (endPoint.IsIn) { endPoint.EndRead(asyncResult); } else { throw new ScopeIOException("Unknown endpoint type"); } } catch (USBException e) { Error = e; bytesTransferred = 0; buffer = null; return; } MadWizard.WinUSBNet.USBAsyncResult usbresult = (MadWizard.WinUSBNet.USBAsyncResult)asyncResult; if (usbresult.Error != null) { Error = usbresult.Error; success = false; bytesTransferred = 0; buffer = null; } else { bytesTransferred = usbresult.BytesTransfered; } }
internal void WaitForCompletion() { if (asyncResult == null) { throw new ScopeIOException("Can't wait for command's completion before executing command"); } try { if (endPoint.IsOut) { endPoint.EndWrite(asyncResult); } else if (endPoint.IsIn) { endPoint.EndRead(asyncResult); } else { throw new ScopeIOException("Unknown endpoint type"); } } catch (Exception e) { throw new ScopeIOException("USB Error occurred: " + e.Message); } USBAsyncResult usbresult = (USBAsyncResult)asyncResult; if (usbresult.Error != null) { throw new ScopeIOException("USB Error occurred: " + usbresult.Error.Message); } if (usbresult.BytesTransfered != length) { throw new ScopeIOException(String.Format("Only transferred {0:d} out of {1:d} bytes", usbresult.BytesTransfered, length)); } }