C# Класс PInvokeSerialPort.SerialPort

PInvokeSerialPort main class. Borrowed from http://msdn.microsoft.com/en-us/magazine/cc301786.aspx ;)
Наследование: IDisposable
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
AutoReopen bool
BaudRate int
CheckAllSends bool
DataBits int
Parity Parity
RxFlowX bool
RxGateDsr bool
RxHighWater int
RxLowWater int
RxQueue int
SendTimeoutConstant int
SendTimeoutMultiplier int
StopBits StopBits
TxFlowCts bool
TxFlowDsr bool
TxFlowX bool
TxQueue int
TxWhenRxXoff bool
UseDtr HsOutput
UseRts HsOutput
XoffChar ASCII
XonChar ASCII

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

Метод Описание
Close ( ) : void

Closes the com port.

Dispose ( ) : void

For IDisposable

Flush ( ) : void

Block until all bytes in the queue have been transmitted.

Open ( ) : bool

Opens the com port and configures it with the required settings

SendImmediate ( byte tosend ) : void

Sends a protocol byte immediately ahead of any queued bytes.

SerialPort ( string portName ) : System

Class contructor

SerialPort ( string portName, int baudRate ) : System

Class contructor

Write ( byte toSend ) : void

Queues bytes for transmission.

Write ( char toSend ) : void

Queues a single char for transmission.

Write ( string toSend ) : void

Queues string for transmission.

WriteLine ( string toSend ) : void

Queues string with a new line ("\r\n") for transmission.

Защищенные методы

Метод Описание
AfterOpen ( ) : bool

Override this to provide processing after the port is openned (i.e. to configure remote device or just check presence).

BeforeClose ( bool error ) : void

Override this to provide processing prior to port closure.

GetModemStatus ( ) : ModemStatus

Gets the status of the modem control input signals.

GetQueueStatus ( ) : QueueStatus

Get the status of the queues

OnBreak ( ) : void

Override this to take action when a break condition is detected on the input line.

OnRing ( ) : void

Override this to take action when a ring condition is signalled by an attached modem.

OnRxChar ( byte ch ) : void

Override this to process received bytes.

OnRxException ( Exception e ) : void

Override this to take action when the reception thread closes due to an exception being thrown.

OnStatusChange ( ModemStatus mask, ModemStatus state ) : void

Override this to take action when one or more modem status inputs change state

OnTxDone ( ) : void

Override this to take action when transmission is complete (i.e. all bytes have actually been sent, not just queued).

Sleep ( int milliseconds ) : void

Delay processing.

ThrowException ( string reason ) : void

Use this to throw exceptions in derived classes. Correctly handles threading issues and closes the port if necessary.

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

Метод Описание
CheckOnline ( ) : bool
CheckResult ( ) : void
InternalClose ( ) : void
ReceiveThread ( ) : void

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

AfterOpen() защищенный Метод

Override this to provide processing after the port is openned (i.e. to configure remote device or just check presence).
protected AfterOpen ( ) : bool
Результат bool

BeforeClose() защищенный Метод

Override this to provide processing prior to port closure.
protected BeforeClose ( bool error ) : void
error bool True if closing due to an error
Результат void

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

Closes the com port.
public Close ( ) : void
Результат void

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

For IDisposable
public Dispose ( ) : void
Результат void

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

Block until all bytes in the queue have been transmitted.
public Flush ( ) : void
Результат void

GetModemStatus() защищенный Метод

Gets the status of the modem control input signals.
protected GetModemStatus ( ) : ModemStatus
Результат ModemStatus

GetQueueStatus() защищенный Метод

Get the status of the queues
protected GetQueueStatus ( ) : QueueStatus
Результат QueueStatus

OnBreak() защищенный Метод

Override this to take action when a break condition is detected on the input line.
protected OnBreak ( ) : void
Результат void

OnRing() защищенный Метод

Override this to take action when a ring condition is signalled by an attached modem.
protected OnRing ( ) : void
Результат void

OnRxChar() защищенный Метод

Override this to process received bytes.
protected OnRxChar ( byte ch ) : void
ch byte The byte that was received
Результат void

OnRxException() защищенный Метод

Override this to take action when the reception thread closes due to an exception being thrown.
protected OnRxException ( Exception e ) : void
e System.Exception The exception which was thrown
Результат void

OnStatusChange() защищенный Метод

Override this to take action when one or more modem status inputs change state
protected OnStatusChange ( ModemStatus mask, ModemStatus state ) : void
mask ModemStatus The status inputs that have changed state
state ModemStatus The state of the status inputs
Результат void

OnTxDone() защищенный Метод

Override this to take action when transmission is complete (i.e. all bytes have actually been sent, not just queued).
protected OnTxDone ( ) : void
Результат void

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

Opens the com port and configures it with the required settings
public Open ( ) : bool
Результат bool

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

Sends a protocol byte immediately ahead of any queued bytes.
public SendImmediate ( byte tosend ) : void
tosend byte Byte to send
Результат void

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

Class contructor
public SerialPort ( string portName ) : System
portName string
Результат System

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

Class contructor
public SerialPort ( string portName, int baudRate ) : System
portName string
baudRate int
Результат System

Sleep() защищенный Метод

Delay processing.
protected Sleep ( int milliseconds ) : void
milliseconds int Milliseconds to delay by
Результат void

ThrowException() защищенный Метод

Use this to throw exceptions in derived classes. Correctly handles threading issues and closes the port if necessary.
protected ThrowException ( string reason ) : void
reason string Description of fault
Результат void

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

Queues bytes for transmission.
public Write ( byte toSend ) : void
toSend byte Array of bytes to be sent
Результат void

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

Queues a single char for transmission.
public Write ( char toSend ) : void
toSend char Byte to be sent
Результат void

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

Queues string for transmission.
public Write ( string toSend ) : void
toSend string Array of bytes to be sent
Результат void

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

Queues string with a new line ("\r\n") for transmission.
public WriteLine ( string toSend ) : void
toSend string Array of bytes to be sent
Результат void

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

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

If true, the port will automatically re-open on next send if it was previously closed due to an error (default: false)
public bool AutoReopen
Результат bool

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

Baud Rate (default: 2400) unsupported rates will throw "Bad settings"
public int BaudRate
Результат int

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

If true, subsequent Send commands wait for completion of earlier ones enabling the results to be checked. If false, errors, including timeouts, may not be detected, but performance may be better.
public bool CheckAllSends
Результат bool

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

Number of databits 1..8 (default: 8) unsupported values will throw "Bad settings"
public int DataBits
Результат int

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

The parity checking scheme (default: none)
public Parity Parity
Результат Parity

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

If true, Xon and Xoff characters are sent to control the data flow from the remote station (default: false)
public bool RxFlowX
Результат bool

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

If true, received characters are ignored unless DSR is asserted by the remote station (default: false)
public bool RxGateDsr
Результат bool

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

The number of free bytes in the reception queue at which flow is disabled (default: 2048)
public int RxHighWater
Результат int

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

The number of bytes in the reception queue at which flow is re-enabled (default: 512)
public int RxLowWater
Результат int

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

Requested size for receive queue (default: 0 = use operating system default)
public int RxQueue
Результат int

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

Constant. Max time for Send in ms = (Multiplier * Characters) + Constant (default: 0)
public int SendTimeoutConstant
Результат int

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

Multiplier. Max time for Send in ms = (Multiplier * Characters) + Constant (default: 0 = No timeout)
public int SendTimeoutMultiplier
Результат int

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

Number of stop bits (default: one)
public StopBits StopBits
Результат StopBits

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

If true, transmission is halted unless CTS is asserted by the remote station (default: false)
public bool TxFlowCts
Результат bool

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

If true, transmission is halted unless DSR is asserted by the remote station (default: false)
public bool TxFlowDsr
Результат bool

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

If true, transmission is halted when Xoff is received and restarted when Xon is received (default: false)
public bool TxFlowX
Результат bool

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

Requested size for transmit queue (default: 0 = use operating system default)
public int TxQueue
Результат int

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

If false, transmission is suspended when this station has sent Xoff to the remote station (default: true) Set false if the remote station treats any character as an Xon.
public bool TxWhenRxXoff
Результат bool

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

Specidies the use to which the DTR output is put (default: none)
public HsOutput UseDtr
Результат HsOutput

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

Specifies the use to which the RTS output is put (default: none)
public HsOutput UseRts
Результат HsOutput

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

The character used to signal Xoff for X flow control (default: DC3)
public ASCII XoffChar
Результат ASCII

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

The character used to signal Xon for X flow control (default: DC1)
public ASCII XonChar
Результат ASCII