C# Class System.IO.Ports.SerialPortBase

Inheritance: ISerialPort
显示文件 Open project: toxsedyshev/imBMW Class Usage Examples

Public Properties

Property Type Description
Encoding System.Text.Encoding
NewLine string

Protected Properties

Property Type Description
_bufferSync object
_continueReading bool
_incomingBuffer byte[]
_incomingBufferPosition int
_incomingBufferValidLength int
_readBufferSize int
_readThread Thread
_readToEvent System.Threading.AutoResetEvent
_writeBufferSize int
_writeThread Thread

Public Methods

Method Description
Flush ( ) : void
Read ( byte buffer, int offset, int count ) : int

Reads data from a serial port.

ReadAvailable ( ) : byte[]

Reads all available bytes and removes them from the reading buffer.

ReadAvailable ( int maxCount ) : byte[]

Reads desired number of bytes and removes them from the reading buffer.

ReadLine ( ) : string

Reads data from a serial port up to the NewLine value and decodes them as string using Encoding.

This method does not return until NewLine sequence is received.

SerialPortBase ( ) : System
SerialPortBase ( int writeBufferSize, int readBufferSize ) : System
Write ( ) : void

Writes data to a serial port.

The method does not return until all data are sent, including output buffer pauses and/or hardware flow control pauses, if applicable.

Write ( byte data, int offset, int length ) : void

Writes data to a serial port.

The method does not return until all data is sent, including output buffer pauses and/or hardware flow control pauses, if applicable.

Write ( string text ) : void

Encodes string data using Encoding and sends them to a serial port.

The method does not return until all data are sent, including output buffer pauses and/or hardware flow control pauses, if applicable.

WriteLine ( string text ) : void

Appends NewLine to the string, encodes it using Encoding and sends it to a serial port.

The method does not return until all data are sent, including output buffer pauses and/or hardware flow control pauses, if applicable.

Protected Methods

Method Description
AdvancePosition ( int count ) : void

Advances the internal circular read bufer position by specified amount and updates the valid length field accordingly.

BufferIndexOf ( byte what ) : int

Searches the internal circular read buffer for sequence of bytes.

GetBufferedData ( int arraySize ) : byte[]

Returns specified amount of data from internal circular read buffer. If there is not enough data available, remaining bytes are filled with zeros.

GetBufferedData ( byte buffer, int offset, int count ) : int

Copies specified amount of data from internal circular read buffer to the specified linear buffer.

OnBusyChanged ( bool busy ) : void
OnDataReceived ( byte data, int validLength ) : void

Adds the received data into internal circular read buffer and fires DataReceived event.

ReadDirect ( byte data, int offset, int length ) : int
ReadLoop ( ) : void
StartReading ( ) : void

Starts waiting for data in order to fire DataReceived event.

StopReading ( ) : void

Stops waiting for data.

WriteDirect ( byte data, int offset, int length ) : int

Private Methods

Method Description
ReadTo ( ) : byte[]

Method Details

AdvancePosition() protected method

Advances the internal circular read bufer position by specified amount and updates the valid length field accordingly.
protected AdvancePosition ( int count ) : void
count int The number of bytes to move forward.
return void

BufferIndexOf() protected method

Searches the internal circular read buffer for sequence of bytes.
protected BufferIndexOf ( byte what ) : int
what byte The sequence to look for.
return int

Flush() public abstract method

public abstract Flush ( ) : void
return void

GetBufferedData() protected method

Returns specified amount of data from internal circular read buffer. If there is not enough data available, remaining bytes are filled with zeros.
protected GetBufferedData ( int arraySize ) : byte[]
arraySize int The number of bytes to return.
return byte[]

GetBufferedData() protected method

Copies specified amount of data from internal circular read buffer to the specified linear buffer.
protected GetBufferedData ( byte buffer, int offset, int count ) : int
buffer byte The linear buffer that stores the data read from the internal read buffer.
offset int The offset value that indicates where writing to the linear buffer from the internal read buffer is to begin.
count int The number of bytes of data to be copied.
return int

OnBusyChanged() protected method

protected OnBusyChanged ( bool busy ) : void
busy bool
return void

OnDataReceived() protected method

Adds the received data into internal circular read buffer and fires DataReceived event.
protected OnDataReceived ( byte data, int validLength ) : void
data byte An array with data received.
validLength int Number of valid bytes in the array.
return void

Read() public method

Reads data from a serial port.
public Read ( byte buffer, int offset, int count ) : int
buffer byte The output buffer that stores the data read from the serial port.
offset int The offset value that indicates where writing to the output buffer from the serial port is to begin.
count int The number of bytes of data to be read.
return int

ReadAvailable() public method

Reads all available bytes and removes them from the reading buffer.
public ReadAvailable ( ) : byte[]
return byte[]

ReadAvailable() public method

Reads desired number of bytes and removes them from the reading buffer.
public ReadAvailable ( int maxCount ) : byte[]
maxCount int The maximum count of bytes to return.
return byte[]

ReadDirect() protected abstract method

protected abstract ReadDirect ( byte data, int offset, int length ) : int
data byte
offset int
length int
return int

ReadLine() public method

Reads data from a serial port up to the NewLine value and decodes them as string using Encoding.
This method does not return until NewLine sequence is received.
public ReadLine ( ) : string
return string

ReadLoop() protected method

protected ReadLoop ( ) : void
return void

SerialPortBase() public method

public SerialPortBase ( ) : System
return System

SerialPortBase() public method

public SerialPortBase ( int writeBufferSize, int readBufferSize ) : System
writeBufferSize int
readBufferSize int
return System

StartReading() protected method

Starts waiting for data in order to fire DataReceived event.
protected StartReading ( ) : void
return void

StopReading() protected method

Stops waiting for data.
protected StopReading ( ) : void
return void

Write() public method

Writes data to a serial port.
The method does not return until all data are sent, including output buffer pauses and/or hardware flow control pauses, if applicable.
public Write ( ) : void
return void

Write() public method

Writes data to a serial port.
The method does not return until all data is sent, including output buffer pauses and/or hardware flow control pauses, if applicable.
public Write ( byte data, int offset, int length ) : void
data byte The input buffer that is to write to the serial port.
offset int The offset value that indicates where writing from the input buffer to the serial port is to begin.
length int The number of bytes of data to be written to the serial port.
return void

Write() public method

Encodes string data using Encoding and sends them to a serial port.
The method does not return until all data are sent, including output buffer pauses and/or hardware flow control pauses, if applicable.
public Write ( string text ) : void
text string String data to send.
return void

WriteDirect() protected abstract method

protected abstract WriteDirect ( byte data, int offset, int length ) : int
data byte
offset int
length int
return int

WriteLine() public method

Appends NewLine to the string, encodes it using Encoding and sends it to a serial port.
The method does not return until all data are sent, including output buffer pauses and/or hardware flow control pauses, if applicable.
public WriteLine ( string text ) : void
text string String data to send.
return void

Property Details

Encoding public_oe property

Encoding to use when reading or writing string data. Default is UTF-8. Only expanding encodings are supported.
public Encoding,System.Text Encoding
return System.Text.Encoding

NewLine public_oe property

A string representing the line delimiter in string data.
public string NewLine
return string

_bufferSync protected_oe property

protected object _bufferSync
return object

_continueReading protected_oe property

protected bool _continueReading
return bool

_incomingBuffer protected_oe property

protected byte[] _incomingBuffer
return byte[]

_incomingBufferPosition protected_oe property

protected int _incomingBufferPosition
return int

_incomingBufferValidLength protected_oe property

protected int _incomingBufferValidLength
return int

_readBufferSize protected_oe property

protected int _readBufferSize
return int

_readThread protected_oe property

protected Thread _readThread
return Thread

_readToEvent protected_oe property

protected AutoResetEvent,System.Threading _readToEvent
return System.Threading.AutoResetEvent

_writeBufferSize protected_oe property

protected int _writeBufferSize
return int

_writeThread protected_oe property

protected Thread _writeThread
return Thread