C# Class PInvokeSerialPort.SerialPort

PInvokeSerialPort main class. Borrowed from http://msdn.microsoft.com/en-us/magazine/cc301786.aspx ;)
Inheritance: IDisposable
Afficher le fichier Open project: ebraminio/PInvokeSerialPort Class Usage Examples

Méthodes publiques

Свойство Type Description
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

Méthodes publiques

Méthode Description
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.

Méthodes protégées

Méthode Description
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.

Private Methods

Méthode Description
CheckOnline ( ) : bool
CheckResult ( ) : void
InternalClose ( ) : void
ReceiveThread ( ) : void

Method Details

AfterOpen() protected méthode

Override this to provide processing after the port is openned (i.e. to configure remote device or just check presence).
protected AfterOpen ( ) : bool
Résultat bool

BeforeClose() protected méthode

Override this to provide processing prior to port closure.
protected BeforeClose ( bool error ) : void
error bool True if closing due to an error
Résultat void

Close() public méthode

Closes the com port.
public Close ( ) : void
Résultat void

Dispose() public méthode

For IDisposable
public Dispose ( ) : void
Résultat void

Flush() public méthode

Block until all bytes in the queue have been transmitted.
public Flush ( ) : void
Résultat void

GetModemStatus() protected méthode

Gets the status of the modem control input signals.
protected GetModemStatus ( ) : ModemStatus
Résultat ModemStatus

GetQueueStatus() protected méthode

Get the status of the queues
protected GetQueueStatus ( ) : QueueStatus
Résultat QueueStatus

OnBreak() protected méthode

Override this to take action when a break condition is detected on the input line.
protected OnBreak ( ) : void
Résultat void

OnRing() protected méthode

Override this to take action when a ring condition is signalled by an attached modem.
protected OnRing ( ) : void
Résultat void

OnRxChar() protected méthode

Override this to process received bytes.
protected OnRxChar ( byte ch ) : void
ch byte The byte that was received
Résultat void

OnRxException() protected méthode

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
Résultat void

OnStatusChange() protected méthode

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
Résultat void

OnTxDone() protected méthode

Override this to take action when transmission is complete (i.e. all bytes have actually been sent, not just queued).
protected OnTxDone ( ) : void
Résultat void

Open() public méthode

Opens the com port and configures it with the required settings
public Open ( ) : bool
Résultat bool

SendImmediate() public méthode

Sends a protocol byte immediately ahead of any queued bytes.
public SendImmediate ( byte tosend ) : void
tosend byte Byte to send
Résultat void

SerialPort() public méthode

Class contructor
public SerialPort ( string portName ) : System
portName string
Résultat System

SerialPort() public méthode

Class contructor
public SerialPort ( string portName, int baudRate ) : System
portName string
baudRate int
Résultat System

Sleep() protected méthode

Delay processing.
protected Sleep ( int milliseconds ) : void
milliseconds int Milliseconds to delay by
Résultat void

ThrowException() protected méthode

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
Résultat void

Write() public méthode

Queues bytes for transmission.
public Write ( byte toSend ) : void
toSend byte Array of bytes to be sent
Résultat void

Write() public méthode

Queues a single char for transmission.
public Write ( char toSend ) : void
toSend char Byte to be sent
Résultat void

Write() public méthode

Queues string for transmission.
public Write ( string toSend ) : void
toSend string Array of bytes to be sent
Résultat void

WriteLine() public méthode

Queues string with a new line ("\r\n") for transmission.
public WriteLine ( string toSend ) : void
toSend string Array of bytes to be sent
Résultat void

Property Details

AutoReopen public_oe property

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
Résultat bool

BaudRate public_oe property

Baud Rate (default: 2400) unsupported rates will throw "Bad settings"
public int BaudRate
Résultat int

CheckAllSends public_oe property

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
Résultat bool

DataBits public_oe property

Number of databits 1..8 (default: 8) unsupported values will throw "Bad settings"
public int DataBits
Résultat int

Parity public_oe property

The parity checking scheme (default: none)
public Parity Parity
Résultat Parity

RxFlowX public_oe property

If true, Xon and Xoff characters are sent to control the data flow from the remote station (default: false)
public bool RxFlowX
Résultat bool

RxGateDsr public_oe property

If true, received characters are ignored unless DSR is asserted by the remote station (default: false)
public bool RxGateDsr
Résultat bool

RxHighWater public_oe property

The number of free bytes in the reception queue at which flow is disabled (default: 2048)
public int RxHighWater
Résultat int

RxLowWater public_oe property

The number of bytes in the reception queue at which flow is re-enabled (default: 512)
public int RxLowWater
Résultat int

RxQueue public_oe property

Requested size for receive queue (default: 0 = use operating system default)
public int RxQueue
Résultat int

SendTimeoutConstant public_oe property

Constant. Max time for Send in ms = (Multiplier * Characters) + Constant (default: 0)
public int SendTimeoutConstant
Résultat int

SendTimeoutMultiplier public_oe property

Multiplier. Max time for Send in ms = (Multiplier * Characters) + Constant (default: 0 = No timeout)
public int SendTimeoutMultiplier
Résultat int

StopBits public_oe property

Number of stop bits (default: one)
public StopBits StopBits
Résultat StopBits

TxFlowCts public_oe property

If true, transmission is halted unless CTS is asserted by the remote station (default: false)
public bool TxFlowCts
Résultat bool

TxFlowDsr public_oe property

If true, transmission is halted unless DSR is asserted by the remote station (default: false)
public bool TxFlowDsr
Résultat bool

TxFlowX public_oe property

If true, transmission is halted when Xoff is received and restarted when Xon is received (default: false)
public bool TxFlowX
Résultat bool

TxQueue public_oe property

Requested size for transmit queue (default: 0 = use operating system default)
public int TxQueue
Résultat int

TxWhenRxXoff public_oe property

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
Résultat bool

UseDtr public_oe property

Specidies the use to which the DTR output is put (default: none)
public HsOutput UseDtr
Résultat HsOutput

UseRts public_oe property

Specifies the use to which the RTS output is put (default: none)
public HsOutput UseRts
Résultat HsOutput

XoffChar public_oe property

The character used to signal Xoff for X flow control (default: DC3)
public ASCII XoffChar
Résultat ASCII

XonChar public_oe property

The character used to signal Xon for X flow control (default: DC1)
public ASCII XonChar
Résultat ASCII