Beispiel #1
0
 public static unsafe extern bool WinUsb_WritePipe(
     SafeUsbHandle interfaceHandle,
     byte pipeID,
     [Friendly(FriendlyFlags.In | FriendlyFlags.Array)] byte *buffer,
     int bufferLength,
     out int lengthTransferred,
     [Friendly(FriendlyFlags.In | FriendlyFlags.Optional)] NativeOverlapped *overlapped);
 /// <summary>
 /// Initializes a new instance of the <see cref="WinUsbOverlapped"/> class.
 /// </summary>
 /// <param name="handle">
 /// A handle to the WinUSB device on which the I/O is being performed.
 /// </param>
 /// <param name="pipeID">
 /// The ID of the pipe on which the I/O is being performed.
 /// </param>
 /// <param name="buffer">
 /// The buffer which is used by the I/O operation. This buffer will be pinned for the duration of
 /// the operation.
 /// </param>
 /// <param name="cancellationToken">
 /// A <see cref="CancellationToken"/> which can be used to cancel the overlapped I/O.
 /// </param>
 public WinUsbOverlapped(SafeUsbHandle handle, byte pipeID, Memory <byte> buffer, CancellationToken cancellationToken)
 {
     this.handle            = handle ?? throw new ArgumentNullException(nameof(handle));
     this.pipeID            = pipeID;
     this.buffer            = buffer;
     this.cancellationToken = cancellationToken;
 }
Beispiel #3
0
        /// <summary>
        /// Asynchronously reads data from the specified pipe.
        /// </summary>
        /// <param name="interfaceHandle">
        /// An opaque handle to the interface that contains the endpoint with which the pipe is associated.
        /// </param>
        /// <param name="pipeID">
        /// <paramref name="pipeID"/> corresponds to the bEndpointAddress field in the endpoint descriptor.
        /// </param>
        /// <param name="buffer">
        /// A caller-allocated buffer that receives the data that is read.
        /// </param>
        /// <param name="cancellationToken">
        /// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.
        /// </param>
        /// <returns>
        /// A <see cref="ValueTask"/> which represents the asynchronous operation, and returns the number of bytes transferred.
        /// </returns>
        public static unsafe ValueTask <int> WinUsb_ReadPipeAsync(SafeUsbHandle interfaceHandle, byte pipeID, Memory <byte> buffer, CancellationToken cancellationToken)
        {
            var overlapped       = new WinUsbOverlapped(interfaceHandle, pipeID, buffer, cancellationToken);
            var nativeOverlapped = overlapped.Pack();

            if (WinUsb_ReadPipe(
                    interfaceHandle,
                    pipeID,
                    (byte *)overlapped.BufferHandle.Pointer,
                    buffer.Length,
                    out int lengthTransferred,
                    nativeOverlapped))
            {
                overlapped.Unpack();
                return(new ValueTask <int>(lengthTransferred));
            }
Beispiel #4
0
 public static unsafe extern bool WinUsb_QueryPipe(
     SafeUsbHandle interfaceHandle,
     byte alternateInterfaceNumber,
     byte pipeIndex,
     [Friendly(FriendlyFlags.Out)] WINUSB_PIPE_INFORMATION *pipeInformation);
Beispiel #5
0
 public static extern bool WinUsb_Initialize(Kernel32.SafeObjectHandle deviceHandle, out SafeUsbHandle interfaceHandle);
Beispiel #6
0
 public static extern bool WinUsb_AbortPipe(SafeUsbHandle handle, byte pipeID);