C# Класс Com.Aote.Utils.SerialPort

Наследование: IDisposable
Показать файл Открыть проект

Открытые свойства

Свойство Тип Описание
Opened bool

Открытые методы

Метод Описание
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.

Приватные методы

Метод Описание
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

Описание методов

Close() публичный Метод

public Close ( ) : void
Результат void

ConvertHexChar() публичный статический Метод

public static ConvertHexChar ( char ch ) : int
ch char
Результат int

Dispose() публичный Метод

Disconnects and disposes of the SerialCom instance.
public Dispose ( ) : void
Результат void

Flush() публичный Метод

Flushes the serial I/O buffers.
public Flush ( ) : bool
Результат bool

Open() публичный Метод

Opens and initializes the serial connection.
public Open ( ) : bool
Результат bool

Read() публичный Метод

Reads any bytes that have been received and writes them to the specified array.
public Read ( byte data ) : int
data byte
Результат int

ReadString() публичный Метод

Reads any data that has been received as a string.
public ReadString ( int maxBytesToRead ) : string
maxBytesToRead int
Результат string

SerialPort() публичный Метод

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
Результат System

SerialPort() публичный Метод

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
Результат System

String2Hex() публичный статический Метод

public static String2Hex ( string str, byte senddata ) : int
str string
senddata byte
Результат int

Write() публичный Метод

Transmits the specified array of bytes.
public Write ( byte data ) : int
data byte
Результат int

Write() публичный Метод

Transmits the specified string.
public Write ( int data ) : int
data int
Результат int

WriteLine() публичный Метод

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
Результат int

Описание свойств

Opened публичное свойство

public bool Opened
Результат bool