![]() | PipeStream Class |
Namespace: WinUsbNet
The PipeStream type exposes the following members.
Name | Description | |
---|---|---|
![]() | CanRead |
Gets a value that indicates if the PipeStream can read from the USB device.
(Overrides StreamCanRead.) |
![]() | CanSeek |
Gets the value false, indicating the PipeStream does not support seeking.
(Overrides StreamCanSeek.) |
![]() | CanTimeout |
Gets a value that indicates if the PipeStream can time out.
(Overrides StreamCanTimeout.) |
![]() | CanWrite |
Gets a value that indicates if the PipeStream can write to the USB device.
(Overrides StreamCanWrite.) |
![]() | Length |
Throws NotSupportedException.
(Overrides StreamLength.) |
![]() | PipeId |
Gets the USB endpoint number for the PipeStream.
|
![]() | Position |
Throws NotSupportedException.
(Overrides StreamPosition.) |
![]() | ReadMaxPacketSize |
Gets the maximum size, in bytes, of the packets that are received on the pipe.
|
![]() | ReadTimeout |
Gets or sets the time, in milliseconds, to wait for a read operation to complete.
(Overrides StreamReadTimeout.) |
![]() | ReadUseShortPacket |
Gets or sets a value indicating if a short packet from the USB device
should be used to terminate a read transfer.
|
![]() | WriteMaxPacketSize |
Gets the maximum size, in bytes, of the packets that are transmitted on the pipe.
|
![]() | WriteTimeout |
Throws NotSupportedException.
(Overrides StreamWriteTimeout.) |
![]() | WriteUseShortPacket |
Gets or sets a value indicating if a short packet should be used to signal
to the USB device that the host has no more data to send.
|
Name | Description | |
---|---|---|
![]() | BeginRead | Begins an asynchronous read operation. (Inherited from Stream.) |
![]() | BeginWrite | Begins an asynchronous write operation. (Inherited from Stream.) |
![]() | ClearReadBuffer |
Clears the read buffer for the PipeStream.
|
![]() | Close | Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream. (Inherited from Stream.) |
![]() | CopyTo(Stream) | Reads the bytes from the current stream and writes them to the destination stream. (Inherited from Stream.) |
![]() | CopyTo(Stream, Int32) | Reads all the bytes from the current stream and writes them to a destination stream, using a specified buffer size. (Inherited from Stream.) |
![]() | CreateObjRef | Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.) |
![]() | Dispose | Releases all resources used by the Stream. (Inherited from Stream.) |
![]() | EndRead | Waits for the pending asynchronous read to complete. (Inherited from Stream.) |
![]() | EndWrite | Ends an asynchronous write operation. (Inherited from Stream.) |
![]() | Equals | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Flush |
This method does nothing.
(Overrides StreamFlush.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetLifetimeService | Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | InitializeLifetimeService | Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.) |
![]() | Read |
Attempts to read a specified number of bytes from the USB device.
(Overrides StreamRead(Byte, Int32, Int32).) |
![]() | ReadByte |
Attempts to read one byte from the USB device.
(Overrides StreamReadByte.) |
![]() | Seek |
Throws NotSupportedException.
(Overrides StreamSeek(Int64, SeekOrigin).) |
![]() | SetLength |
Throws NotSupportedException.
(Overrides StreamSetLength(Int64).) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
![]() | Write |
Writes a specified number of bytes to the USB device.
(Overrides StreamWrite(Byte, Int32, Int32).) |
![]() | WriteByte |
Writes one byte to the USB device.
(Overrides StreamWriteByte(Byte).) |
A USB device provides one or more endpoints for communicating with the host computer. The logical connection between the endpoint and the host is a USB pipe. The PipeStream provides methods for transferring data over this pipe.
You do not create a PipeStream directly. A PipeStream is automatically created for each endpoint of the USB device when the Open method on the UsbDevice is called. You access a PipeStream through the PipeStreams collection of the UsbDevice. Do not use the Close or Dispose methods on the PipeStream. The PipeStream is closed automatically when the USB device is closed or disconnected.
Each endpoint, and its corresponding pipe, provides one-way communication. It is possible (but rare) that two endpoints with opposite direction of data transfer will share the same endpoint number. In this case, a single PipeStream is used for the two pipes.
The CanRead and CanWrite properties identify the direction of data transfor for the pipe. The Read and Write methods are used to transfer an array of bytes, while the ReadByte and WriteByte methods are used to transfer a single byte at a time. Transfers of more structured data can be accomplished using the PipeStream with classes such as BinaryReader, and BinaryWriter with BufferedStream.
All transfers are synchronous and blocking. If you request to read more data than the USB device has ready, the ReadTimeout property will determine how long the read will block waiting for data. Write transfers are normally very fast so the WriteTimeout property is not used and will throw an exception.
USB transfers are carried in packets of a maximum size specified by the USB device. Transfers larger than the packet size will automatically use multiple packets. A packet of less than maximum size (short packet) can be used to indicate that a transfer is complete. The use of short packets is entirely up to the communication protocol that the device and host are using. If the length of data transfer is otherwise implicitly or explicity established, there is no need to use short packets.
If the USB device uses a short packet to indicate that it has no more data to send, set the ReadUseShortPacket property to true. Then the Read or ReadByte methods will terminate if they receive a short packet. If the ReadUseShortPacket property is false, the Read or ReadByte methods will ignore short packets and continue waiting for data until the number of bytes requested is received or the ReadTimeout limit is reached.
If the USB device accepts a short packet as an indicator that the host has no more data to send, set the WriteUseShortPacket property to true. This will ensure that the Write method will always end with a short packet, appending a zero-length packet if necessary (if the transfer is a multiple of the maximum packet size). Note that the Write and WriteByte methods perform no buffering. WriteByte will always send a 1-byte (short) packet.
The Length and Position properties and the Seek and SetLength methods are not meaningful and will throw an exception if used.