Table of Contents

Class UsbStream

Namespace
System.Device.Usb
Assembly
System.Device.UsbStream.dll

Initializes a new instance of the UsbStream class.

public sealed class UsbStream : Stream, IDisposable
Inheritance
UsbStream
Implements
Inherited Members
Extension Methods

Properties

CanRead

When overridden in a derived class, gets a value indicating whether the current stream supports reading.

public override bool CanRead { get; }

Property Value

bool

true if the stream supports reading; otherwise, false.

CanSeek

When overridden in a derived class, gets a value indicating whether the current stream supports seeking.

public override bool CanSeek { get; }

Property Value

bool

true if the stream supports seeking; otherwise, false.

CanWrite

When overridden in a derived class, gets a value indicating whether the current stream supports writing.

public override bool CanWrite { get; }

Property Value

bool

true if the stream supports writing; otherwise, false.

IsConnected

Gets a value indicating whether the USB device is connected or not.

public bool IsConnected { get; }

Property Value

bool

Length

When overridden in a derived class, gets the length in bytes of the stream.

public override long Length { get; }

Property Value

long

A long value representing the length of the stream in bytes.

Exceptions

PlatformNotSupportedException

This is not support in .NET nanoFramework.

Position

When overridden in a derived class, gets or sets the position within the current stream.

public override long Position { get; set; }

Property Value

long

The current position within the stream.

Exceptions

PlatformNotSupportedException

This is not support in .NET nanoFramework.

ReadTimeout

Gets or sets the number of milliseconds before a time-out occurs when a read operation does not finish.

public override int ReadTimeout { get; set; }

Property Value

int

Exceptions

IOException

If the USB device is not connected.

ArgumentOutOfRangeException

The read time-out value is less than zero and not equal to Infinite.

WriteTimeout

Gets or sets the number of milliseconds before a time-out occurs when a write operation does not finish.

public override int WriteTimeout { get; set; }

Property Value

int

Exceptions

IOException

If the USB device is not connected.

ArgumentOutOfRangeException

The read time-out value is less than zero and not equal to Infinite.

Methods

Dispose(bool)

Releases the unmanaged resources used by the Stream and optionally releases the managed resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

Finalize()

protected override void Finalize()

Flush()

When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.

public override void Flush()

Exceptions

PlatformNotSupportedException

This is not support in .NET nanoFramework.

Read(byte[])

Reads a number of bytes from the USB device and writes those bytes into a byte array.

public int Read(byte[] buffer)

Parameters

buffer byte[]

The byte array to write the input to.

Returns

int

The number of bytes read.

Remarks

Device connectivity can be checked with IsConnected.

Exceptions

ObjectDisposedException

This UsbStream has been disposed.

InvalidOperationException

If the USB device is not connected.

TimeoutException

No bytes were available to read.

ArgumentNullException

The buffer passed is null.

Read(byte[], int, int)

Reads a number of bytes from the USB device and writes those bytes into a byte array at the specified offset.

public override int Read(byte[] buffer, int offset, int count)

Parameters

buffer byte[]

The byte array to write the input to.

offset int

The offset in buffer at which to write the bytes.

count int

The maximum number of bytes to read. Fewer bytes are read if count is greater than the number of bytes in the input buffer.

Returns

int

The number of bytes read.

Remarks

Device connectivity can be checked with IsConnected.

Exceptions

ObjectDisposedException

This UsbStream has been disposed.

InvalidOperationException

If the USB device is not connected.

TimeoutException

No bytes were available to read.

ArgumentNullException

The buffer passed is null.

ArgumentOutOfRangeException

The offset or count parameters are outside a valid region of the buffer being passed. Either offset or count is less than zero.

ArgumentException

offset plus count is greater than the length of the buffer.

Read(SpanByte)

When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

public override int Read(SpanByte buffer)

Parameters

buffer SpanByte

A region of memory. When this method returns, the contents of this region are replaced by the bytes read from the current source.

Returns

int

The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.

Exceptions

NotImplementedException

Seek(long, SeekOrigin)

When overridden in a derived class, sets the position within the current stream.

public override long Seek(long offset, SeekOrigin origin)

Parameters

offset long

A byte offset relative to the origin parameter.

origin SeekOrigin

A value of type SeekOrigin indicating the reference point used to obtain the new position.

Returns

long

The new position within the current stream.

Exceptions

PlatformNotSupportedException

This is not support in .NET nanoFramework.

SetLength(long)

When overridden in a derived class, sets the length of the current stream.

public override void SetLength(long value)

Parameters

value long

The desired length of the current stream in bytes.

Exceptions

PlatformNotSupportedException

This is not support in .NET nanoFramework.

Write(byte[])

Writes the number of bytes in buffer parameter to the USB device using data from a buffer.

public void Write(byte[] buffer)

Parameters

buffer byte[]

The byte array that contains the data to write to the USB device.

Exceptions

ObjectDisposedException

This UsbStream has been disposed.

InvalidOperationException

If the USB device is not connected.

TimeoutException

The operation did not complete before the time-out period ended.

Write(byte[], int, int)

Writes a specified number of bytes to the USB device using data from a buffer.

public override void Write(byte[] buffer, int offset, int count)

Parameters

buffer byte[]

The byte array that contains the data to write to the USB device.

offset int

The zero-based byte offset in the buffer parameter at which to begin copying bytes to the USB device.

count int

The number of bytes to write.

Exceptions

ObjectDisposedException

This UsbStream has been disposed.

InvalidOperationException

If the USB device is not connected.

TimeoutException

The operation did not complete before the time-out period ended.

ArgumentOutOfRangeException

The offset or count parameters are outside a valid region of the buffer being passed. Either offset or count is less than zero.

ArgumentException

offset plus count is greater than the length of the buffer.

Events

UsbDeviceConnectionChanged

Event occurs when the connection state of the USB device changes.

public event UsbDeviceConnectionChangedEventHandler UsbDeviceConnectionChanged

Event Type

UsbDeviceConnectionChangedEventHandler