Click or drag to resize

PipeStream Class

Provides a Stream for transferring data through a USB pipe.
Inheritance Hierarchy
SystemObject
  SystemMarshalByRefObject
    System.IOStream
      WinUsbNetPipeStream

Namespace:  WinUsbNet
Assembly:  WinUsbNet (in WinUsbNet.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public sealed class PipeStream : Stream

The PipeStream type exposes the following members.

Properties
  NameDescription
Public propertyCanRead
Gets a value that indicates if the PipeStream can read from the USB device.
(Overrides StreamCanRead.)
Public propertyCanSeek
Gets the value false, indicating the PipeStream does not support seeking.
(Overrides StreamCanSeek.)
Public propertyCanTimeout
Gets a value that indicates if the PipeStream can time out.
(Overrides StreamCanTimeout.)
Public propertyCanWrite
Gets a value that indicates if the PipeStream can write to the USB device.
(Overrides StreamCanWrite.)
Public propertyLength
Throws NotSupportedException.
(Overrides StreamLength.)
Public propertyPipeId
Gets the USB endpoint number for the PipeStream.
Public propertyPosition
Throws NotSupportedException.
(Overrides StreamPosition.)
Public propertyReadMaxPacketSize
Gets the maximum size, in bytes, of the packets that are received on the pipe.
Public propertyReadTimeout
Gets or sets the time, in milliseconds, to wait for a read operation to complete.
(Overrides StreamReadTimeout.)
Public propertyReadUseShortPacket
Gets or sets a value indicating if a short packet from the USB device should be used to terminate a read transfer.
Public propertyWriteMaxPacketSize
Gets the maximum size, in bytes, of the packets that are transmitted on the pipe.
Public propertyWriteTimeout
Throws NotSupportedException.
(Overrides StreamWriteTimeout.)
Public propertyWriteUseShortPacket
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.
Top
Methods
  NameDescription
Public methodBeginRead
Begins an asynchronous read operation.
(Inherited from Stream.)
Public methodBeginWrite
Begins an asynchronous write operation.
(Inherited from Stream.)
Public methodClearReadBuffer
Clears the read buffer for the PipeStream.
Public methodClose
Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream.
(Inherited from Stream.)
Public methodCopyTo(Stream)
Reads the bytes from the current stream and writes them to the destination stream.
(Inherited from Stream.)
Public methodCopyTo(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.)
Public methodCreateObjRef
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
(Inherited from MarshalByRefObject.)
Public methodDispose
Releases all resources used by the Stream.
(Inherited from Stream.)
Public methodEndRead
Waits for the pending asynchronous read to complete.
(Inherited from Stream.)
Public methodEndWrite
Ends an asynchronous write operation.
(Inherited from Stream.)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodFlush
This method does nothing.
(Overrides StreamFlush.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetLifetimeService
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
(Inherited from MarshalByRefObject.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodInitializeLifetimeService
Obtains a lifetime service object to control the lifetime policy for this instance.
(Inherited from MarshalByRefObject.)
Public methodRead
Attempts to read a specified number of bytes from the USB device.
(Overrides StreamRead(Byte, Int32, Int32).)
Public methodReadByte
Attempts to read one byte from the USB device.
(Overrides StreamReadByte.)
Public methodSeek
Throws NotSupportedException.
(Overrides StreamSeek(Int64, SeekOrigin).)
Public methodSetLength
Throws NotSupportedException.
(Overrides StreamSetLength(Int64).)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodWrite
Writes a specified number of bytes to the USB device.
(Overrides StreamWrite(Byte, Int32, Int32).)
Public methodWriteByte
Writes one byte to the USB device.
(Overrides StreamWriteByte(Byte).)
Top
Remarks

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.

See Also