C# Class Com.Aote.Utils.SerialPort

Inheritance: IDisposable
ファイルを表示 Open project: DuBin1988/restv2

Public Properties

Property Type Description
Opened bool

Public Methods

Method Description
Close ( ) : void
ConvertHexChar ( char ch ) : int
Dispose ( ) : void

Disconnects and disposes of the SerialCom instance.

Flush ( ) : bool

Flushes the serial I/O buffers.

Open ( ) : bool

Opens and initializes the serial connection.

Read ( byte data ) : int

Reads any bytes that have been received and writes them to the specified array.

ReadString ( int maxBytesToRead ) : string

Reads any data that has been received as a string.

SerialPort ( string portName, int baudRate, StopBits stopBits, Parity parity ) : System

Creates a new instance of SerialCom.

SerialPort ( string portName, int baudRate, StopBits stopBits, Parity parity, byte byteSize ) : System

Creates a new instance of SerialCom.

String2Hex ( string str, byte senddata ) : int
Write ( byte data ) : int

Transmits the specified array of bytes.

Write ( int data ) : int

Transmits the specified string.

WriteLine ( int data ) : int

Transmits the specified string and appends the carriage return to the end if it does not exist.

Note that the string must end in '\r\n' before any serial device will interpret the data sent. For ease of programmability, this method should be used instead of Write() when you want to automatically execute the specified command string.

Private Methods

Method Description
CloseHandle ( IntPtr hObject ) : bool
ConfigureSerialPort ( ) : bool

Configures the serial device based on the connection parameters pased in by the user.

CreateFile ( string fileName, [ fileAccess, [ fileShare, IntPtr securityAttributes, [ creationDisposition, int flags, IntPtr template ) : IntPtr
FailIfNotConnected ( ) : void

Helper that throws a InvalidOperationException if we don't have a serial connection.

GetCommState ( IntPtr hFile, DCB &lpDCB ) : bool
PurgeComm ( IntPtr hFile, int dwFlags ) : bool
ReadFile ( IntPtr hFile, byte lpBuffer, int nNumberOfBytesToRead, int &lpNumberOfBytesRead, int lpOverlapped ) : bool
SetCommState ( IntPtr hFile, [ lpDCB ) : bool
SetCommTimeouts ( IntPtr hFile, COMMTIMEOUTS &lpCommTimeouts ) : bool
WriteFile ( IntPtr hFile, byte lpBuffer, int nNumberOfBytesToWrite, int &lpNumberOfBytesWritten, int lpOverlapped ) : bool

Method Details

Close() public method

public Close ( ) : void
return void

ConvertHexChar() public static method

public static ConvertHexChar ( char ch ) : int
ch char
return int

Dispose() public method

Disconnects and disposes of the SerialCom instance.
public Dispose ( ) : void
return void

Flush() public method

Flushes the serial I/O buffers.
public Flush ( ) : bool
return bool

Open() public method

Opens and initializes the serial connection.
public Open ( ) : bool
return bool

Read() public method

Reads any bytes that have been received and writes them to the specified array.
public Read ( byte data ) : int
data byte
return int

ReadString() public method

Reads any data that has been received as a string.
public ReadString ( int maxBytesToRead ) : string
maxBytesToRead int
return string

SerialPort() public method

Creates a new instance of SerialCom.
public SerialPort ( string portName, int baudRate, StopBits stopBits, Parity parity ) : System
portName string
baudRate int
stopBits StopBits
parity Parity
return System

SerialPort() public method

Creates a new instance of SerialCom.
public SerialPort ( string portName, int baudRate, StopBits stopBits, Parity parity, byte byteSize ) : System
portName string
baudRate int
stopBits StopBits
parity Parity
byteSize byte
return System

String2Hex() public static method

public static String2Hex ( string str, byte senddata ) : int
str string
senddata byte
return int

Write() public method

Transmits the specified array of bytes.
public Write ( byte data ) : int
data byte
return int

Write() public method

Transmits the specified string.
public Write ( int data ) : int
data int
return int

WriteLine() public method

Transmits the specified string and appends the carriage return to the end if it does not exist.
Note that the string must end in '\r\n' before any serial device will interpret the data sent. For ease of programmability, this method should be used instead of Write() when you want to automatically execute the specified command string.
public WriteLine ( int data ) : int
data int
return int

Property Details

Opened public_oe property

public bool Opened
return bool