Serial |
The SerialPort type exposes the following members.
Name | Description | |
---|---|---|
AutoReceive | Set this property to true, if you want to receive the incoming data automatically in the Received event. Otherwise you have to use ReadBuffer method to get the received data. The default value is true. | |
AutoReconnect | Set this property to true, if you want to automatically reconnect to the serial port after a Faulted event, when the port is available again. Set AutoReconnect to true, before the port is faulted, otherwise it will have no effect. The default value is false. | |
AutoReconnectCheckInterval | The time interval in milliseconds the serial port is trying to periodically reconnect, after a Faulted event occur, if AutoReconnect is set to true. It must be a positive value. The default value is 4000. | |
BaudRate | Baud rate at which the communications device operates. | |
CanRaiseEvents | Gets a value indicating whether the component can raise an event. (Inherited from Component) | |
CloseWhenLineStatusIsZero | When this property is true and LineStatus becomes 0 (supposing that it was non 0 after the port has been opened), the port will be closed automatically. Set it to true, for improved fault detection. If you have problems with the port closing itself automatically immediately after open, set this property to false. The default value is true. | |
ConnectedTo | Returns the port where the component is connected to. | |
ConnectionTime | Indicates when the last connection was established. | |
Container | Gets the IContainer that contains the Component. (Inherited from Component) | |
CustomBaudRate | Custom baud rate value, used when BaudRate is set to Custom. | |
CustomPortName | Custom port name can be used when Port is set to Custom. You can use any name, different from COMMxx. | |
DataWidth | Number of bits in the bytes transmitted and received. | |
Delay | Obsolete. Time interval between two receivings in milliseconds (frequency). Same as Interval. | |
DesignMode | Gets a value that indicates whether the Component is currently in design mode. (Inherited from Component) | |
DiscardNulls | Specifies whether null bytes are discarded. If this member is true, null bytes are discarded when received. The default value is false. | |
DsrSensitivity | Specifies whether the communications driver is sensitive to the state of the DSR signal. If this member is true, the driver ignores any bytes received, unless the DSR modem input line is high. The default value is false. | |
EnableDtrOnOpen | Enable DTR when the port is opening. The default value is true. | |
EnableRtsOnOpen | Enable RTS when the port is opening. The default value is true. | |
EofChar | Value of the character used to signal the end of data (ANSI: 0 - 255). The default value is (char)26. | |
ErrorChar | Value of the character used to replace bytes received with a parity error (ANSI: 0 - 255). The default value is (char)0. | |
Events | Gets the list of event handlers that are attached to this Component. (Inherited from Component) | |
EvtChar | Value of the character used to signal an event (ANSI: 0 - 255). The default value is (char)26. | |
Handle | The Windows handle of the serial port. You can use it in some Windows API methods. | |
HardwareFlowControl | Hardware flow control of the serial port. | |
IdleInterval | Idle time interval in milliseconds. If the elapsed time from the last receive is higher than IdleInterval, Idle event occurs. If IdleInterval is 0, Idle event never occurs. It works only for AutoReceive = true. | |
IdleTimeoutInterval | You can set a time-out value to automatically close the connection and fire the IdleTimeout event, if there is no data received in several milliseconds. A value of zero indicates that time-out is not used. | |
InputBuffer | Recommended size of the device's internal input buffer, in bytes. The device driver receives the recommended buffer sizes, but is free to use any input and output (I/O) buffering scheme, as long as it provides reasonable performance and data is not lost due to overrun (except under extreme circumstances). | |
Interval | Time interval between two receivings in milliseconds (frequency). It must be a positive value. The default value is 100. | |
IsFaulted | Indicates that the last connection was faulted. | |
IsIdle | True if Idle occurred, until Resumed. It works only for AutoReceive = true. | |
IsReceiving | This property is false when the component is receiving data from the port, otherwise is false. Use this property to check if the component is inside a receiving process. | |
IsSending | This property is true when the component is sending data to the port, otherwise is false. Use this property to check if the component is inside a sending process. | |
LastDataReceived | Last data received from the serial port. | |
LastTimeReceived | Last date-time when data received from the serial port. | |
LineStatus | Line status of the serial port. The first 4 bits (LSB) of the result contains CTS, DSR, RING and DCD (RLSD or CD) signals status. | |
LogDateTime | When this property is true, a date-time stamp will be added before the logged data. | |
LogFile | Name and path of the log file. | |
LogInput | Enables or disables input logging. If you enable it, all the incoming data will be logged to the LogFile. | |
MaxLineLength | The maximum length of a line, when ReadStringLine or ReadStringUpToEndChars methods are used in synchronous mode (AutoReceive = false). If maximum length is reached, the methods return with empty string. If this value is 0, there is no maximum length. The default value is 0. | |
MinCheckDisconnectedInterval | The minimum time interval in milliseconds, for which the port availability is checked. For time critical usage it's recommended to set it to a higher value. The default value is 25. | |
NeedSynchronization | Set this property to true for thread safety. The default value is false. Note: if you set it to true, you may experiment thread interblocking and lower speed. | |
NewLine | Gets or sets the value used to interpret the end of line in the ReadLine or SendAsciiStringLine methods. Default value is Environment.NewLine, a string containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms. | |
OutputBuffer | Recommended size of the device's internal output buffer, in bytes. The device driver receives the recommended buffer sizes, but is free to use any input and output (I/O) buffering scheme, as long as it provides reasonable performance and data is not lost due to overrun (except under extreme circumstances). | |
PacketSize | The size of the packets in bytes you want to receive automatically in the Received event. Use this property, if you want to receive packets of equal size in the Received event. If the value is 0, this property will be ignored. It works only for AutoReceive = true. Default value is 0. | |
ParityBits | Parity scheme to be used. | |
ParityCheck | If this property is true, parity checking is performed and parity errors are reported. This should not be confused with the Parity member, which controls the type of parity used in communications. The default value is false. | |
Port | Physical name of the serial port. | |
Priority | Priority of the receiver thread. | |
ReadIntervalTimeout | Maximum time allowed to elapse between the arrival of two characters on the communications line, in milliseconds. During a ReadFile operation, the time period begins when the first character is received. If the interval between the arrival of any two characters exceeds this amount, the ReadFile operation is completed and any buffered data is returned. A value of zero indicates that interval time-outs are not used. A value of MAXDWORD, combined with zero values for both the ReadTotalTimeoutConstant and ReadTotalTimeoutMultiplier members, specifies that the read operation is to return immediately with the characters that have already been received, even if no characters have been received. | |
ReadTotalTimeoutConstant | Constant used to calculate the total time-out period for read operations, in milliseconds. For each read operation, this value is added to the product of the ReadTotalTimeoutMultiplier member and the requested number of bytes. A value of zero for both the ReadTotalTimeoutMultiplier and ReadTotalTimeoutConstant members indicates that total time-outs are not used for read operations. | |
ReadTotalTimeoutMultiplier | Multiplier used to calculate the total time-out period for read operations, in milliseconds. For each read operation, this value is multiplied by the requested number of bytes to be read. | |
ReplaceParityErrors | Specifies whether bytes received with parity errors are replaced with the character specified by the ErrorChar member. If this member is true and the ParityCheck member is true, replacement occurs. The default value is false. | |
Site | Gets or sets the ISite of the Component. (Inherited from Component) | |
SkipSetupFailed | When this property is true, if setting serial parameters like DCB in the Open method fails, will ignore this. Otherwise method Open will return false and the port will not be opened. The default value is false. | |
SoftwareFlowControl | Software flow control of the serial port. | |
StopBits | Number of stop bits to be used. | |
TxContinueOnXoff | Specifies whether transmission stops when the input buffer is full and the driver has transmitted the Xoff character. If this member is true, transmission continues after the Xoff character has been sent. If this member is false, transmission does not continue until the input buffer is within XonLim bytes of being empty and the driver has transmitted the Xon character. The default value is false. | |
UnlockKey | Unlock key. | |
WriteTotalTimeoutConstant | Constant used to calculate the total time-out period for write operations, in milliseconds. For each write operation, this value is added to the product of the WriteTotalTimeoutMultiplier member and the number of bytes to be written. A value of zero for both the WriteTotalTimeoutMultiplier and WriteTotalTimeoutConstant members indicates that total time-outs are not used for write operations. | |
WriteTotalTimeoutMultiplier | Multiplier used to calculate the total time-out period for write operations, in milliseconds. For each write operation, this value is multiplied by the number of bytes to be written. | |
XoffChar | Value of the XOFF character for both transmission and reception (ANSI: 0 - 255). The default value is (char)19. | |
XoffLim | Maximum number of bytes allowed in the input buffer before the XOFF character is sent. The maximum number of bytes allowed is calculated by subtracting this value from the size, in bytes, of the input buffer. The default value is 1. | |
XonChar | Value of the XON character for both transmission and reception (ANSI: 0 - 255). The default value is (char)17. | |
XonLim | Minimum number of bytes allowed in the input buffer before the XON character is sent. The default value is 0, which means InputBuffer div 4. |
Name | Description | |
---|---|---|
AsciiByteArrayToString | Converts ASCII / ANSI byte array to string. | |
ByteArrayToDecimalString | Converts byte array to decimal string representation. | |
ByteArrayToHexaString | Converts byte array to hexadecimal string representation. | |
ClearInputBuffer | Clears input buffer. | |
ClearOutputBuffer | Clears output buffer. | |
Close | Closes the serial port. | |
CreateObjRef | Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject) | |
DetectDevice(String, String, SerialCommPort, SerialBaudRate) | Detects the serial port where the device is connected to and returns as output parameters the communication port and baud rate. In the detection process senToken will be sent and receivedToken is expected to receive. | |
DetectDevice(String, String, SerialBaudRate, SerialBaudRate, SerialCommPort, SerialBaudRate) | Detects the serial port where the device is connected to and returns as output parameters the communication port and baud rate. In the detection process senToken will be sent and receivedToken is expected to receive. Only baud rate values between startBaudRate and endBaudRate are checked. | |
Dispose | Releases all resources used by the Component. (Inherited from Component) | |
Dispose(Boolean) |
Clean up any resources being used.
(Overrides ComponentDispose(Boolean)) | |
Echo | Sends the last received buffer back. | |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) | |
FastDetectDevice | Detects the serial port where the device is connected to and returns as output parameters the communication port and baud rate. In the detection process senToken will be sent and receivedToken is expected to receive. Only baud rates between 4800 and 921600 will be checked. | |
Finalize |
Finalizer.
(Overrides ComponentFinalize) | |
GetAvailableInputBufferSize | Returns the number of bytes of data in the receive buffer (bytes to read). It is used when AutoReceive = false. | |
GetAvailableOutputBufferSize | Returns the number of bytes of data in the send buffer (bytes to write). | |
GetCommPortDescription(SerialCommPort) | Returns the OS level description of the port. | |
GetCommPortDescription(String) | Returns the OS level description of the port. | |
GetCommPortPath(SerialCommPort) | Returns the OS level name of the port. E.g.: \Device\PCISerial1 If the port does not exists, returns empty string. | |
GetCommPortPath(String) | Returns the OS level name of the port. E.g.: \Device\PCISerial1 If the port does not exists, returns empty string. | |
GetCommPortType(SerialCommPort) | Returns the type of the serial port. | |
GetCommPortType(String) | Returns the type of the serial port. | |
GetCts | Returns the state of CTS (clear-to-send) line. | |
GetCts(UInt64) | Returns the state of CTS (clear-to-send) line from lineStatus parameter. | |
GetDcd | Returns the state of DCD (Data Carrier Detect, or alternately Carrier Detect abbreviated as CD, or RLSD (receive-line-signal-detect) line. | |
GetDcd(UInt64) | Returns the state of DCD (Data Carrier Detect, or alternately Carrier Detect abbreviated as CD, or RLSD (receive-line-signal-detect) line from lineStatus parameter. | |
GetDsr | Returns the state of DSR (data-set-ready) line. | |
GetDsr(UInt64) | Returns the state of DSR (data-set-ready) line from lineStatus parameter. | |
GetExistingCommPortNames | Returns the existing serial port names of the system. | |
GetExistingCommPorts | Returns the existing serial ports of the system. | |
GetHashCode | Serves as the default hash function. (Inherited from Object) | |
GetLifetimeService | Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject) | |
GetRing | Returns the state of RING line. | |
GetRing(UInt64) | Returns the state of RING line from lineStatus parameter. | |
GetService | Returns an object that represents a service provided by the Component or by its Container. (Inherited from Component) | |
GetType | Gets the Type of the current instance. (Inherited from Object) | |
InitializeLifetimeService | Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject) | |
InsertControlCharacters | Replaces readable text with control characters. | |
IntToSerialCommPort | Converts string to SerialCommPort. | |
IsCommPortAvailable(SerialCommPort) | Checks if the serial port is available (It exists and is not busy, opened by another or the same process). | |
IsCommPortAvailable(String) | Checks if the serial port is available (It exists and is not busy, opened by another or the same process). | |
IsCommPortBusy(SerialCommPort) | Checks if a serial port is already opened by another or the same process (busy). If the port does not exists, SerialPortException is thrown. | |
IsCommPortBusy(String) | Checks if a serial port is already opened by another or the same process (busy). If the port does not exists, SerialPortException is thrown. | |
IsConnected | Returns true if the serial port is connected (open). | |
IsExistingCommPort(SerialCommPort) | Checks if a serial port exists. | |
IsExistingCommPort(String) | Checks if a serial port exists. | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) | |
MemberwiseClone(Boolean) | Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject) | |
OnConnected | Raises the Connected event. | |
OnDetecting | Raises the Detecting event. | |
OnDisconnected | Raises the Disconnected event. | |
OnError | Raises the Error event. | |
OnFaulted | Raises the Faulted event. | |
OnIdle | Raises the Idle event. | |
OnIdleTimeout | Raises the IdleTimeout event. | |
OnLineStatusChanged | Raises the LineStatusChanged event. | |
OnReceived | Raises the Received event. | |
OnReconnecting | Raises the Reconnecting event. | |
OnResumed | Raises the Resumed event. | |
OnSent | Raises the Sent event. | |
Open | Opens the serial port. | |
RandomDataGenerator | Generates random data in string format (chars between 0 - 255). | |
ReadBuffer | Synchronously reads the received data from the serial port to a byte array. It works only if AutoReceive property is false, otherwise returns null. | |
ReadBufferToEnumerable | Synchronously reads the received data from the serial port to a byte list. It works only if AutoReceive property is false, otherwise returns null. | |
ReadBufferToString | Synchronously reads the received data from the serial port to ANSI string. It works only if AutoReceive property is false, otherwise returns null. | |
ReadByte | Synchronously reads one byte from the serial port, if data available. It works only if AutoReceive property is false, otherwise returns null. | |
ReadBytes | Reads numberOfBytes bytes from the serial port and discards them. It works only if AutoReceive property is false. | |
ReadChar | Synchronously reads one character from the serial port. It works only if AutoReceive property is false, otherwise returns empty string. | |
ReadChars | Reads numberOfChars chars from the serial port into string and discards them. It works only if AutoReceive property is false. | |
ReadLine | Reads the serial port up to the first occurrence of NewLine sequence. NewLine can be set by the NewLine property. It works only if AutoReceive property is false. | |
ReadStringUpToEndChars(CollectionString, Int32) | Reads the serial port up to the first occurrence of one of the endChars sequences of the endCharsList collection. It works only if AutoReceive property is false. | |
ReadStringUpToEndChars(String, Int32) | Reads the serial port up to the first occurrence of endChars sequence. It works only if AutoReceive property is false. | |
ReadStringUpToEndChars(CollectionString, String, Int32) | Reads the serial port up to the first occurrence of one of the endChars sequences of the endCharsList collection. It works only if AutoReceive property is false. | |
ReadStringUpToEndChars(CollectionString, String, Int32, Boolean, String) | Reads the serial port up to the first occurrence of one of the endChars sequences of the endCharsList collection. It works only if AutoReceive property is false. | |
ReplaceControlCharacters | Replaces control characters with readable text. | |
ResetIdleState | Resets the idle state of the port. | |
SendAsciiString | Sends an ANSI string to the serial port. | |
SendAsciiStringLine | Sends an ANSI string to the serial port and add the NewLine value at the end of the string. NewLine can be set by the NewLine property. | |
SendAsciiStringOnNewThread | Sends an ANSI string to the serial port on a separate thread. | |
SendByte | Sends a byte to the serial port. | |
SendByteArray(Byte) | Sends a byte array to the serial port. | |
SendByteArray(Byte, Int32) | Sends a specified number of bytes from a byte array to the serial port. | |
SendByteArray(Byte, Int32, Int32) | Sends a specified number of bytes from a byte array to the serial port. | |
SendByteArrayOnNewThread | Sends a byte array to the serial port on a separate thread. | |
SendCharArray(Char) | Sends a char array to the serial port. | |
SendCharArray(Char, Int32) | Sends a specified number of chars from a char array to the serial port. | |
SendCharArray(Char, Int32, Int32) | Sends a specified number of chars from a char array to the serial port. | |
SendString | Sends a string with the selected encoding to the serial port. | |
SendStringOnNewThread | Sends a string with the selected encoding to the serial port on a separate thread. | |
SendUnicodeString | Sends a UTF16 string to the serial port. | |
SendUtf32String | Sends a UTF32 string to the serial port. | |
SendUtf8String | Sends a UTF8 string to the serial port. | |
SerialCommPortToString | Converts SerialCommPort to string. | |
SetBreak | Sets break line. When value is true, suspends character transmission and places the transmission line in a break state. When value is false, restores character transmission and places the transmission line in a nonbreak state. | |
SetDtr | Sets DTR (data-terminal-ready) line. | |
SetFaulted | Emulates faulted state, raises the Faulted event and close the port. If AutoReconnect is true, it will try to reconnect. | |
SetRts | Sets RTS (request-to-send) line. | |
SetXonXoff | Sets XOnXoff state. When value is true, causes transmission to act as if an XON character has been received. When value is false, Causes transmission to act as if an XOFF character has been received. | |
StringToAsciiByteArray | Converts string to ASCII / ANSI byte array. | |
StringToDecimalString | Converts a string to decimal representation. | |
StringToHexaString | Converts a string to hexadecimal representation. | |
StringToSerialCommPort | Converts string to SerialCommPort. | |
StringToUnicodeByteArray | Converts string to UTF16 byte array. | |
StringToUtf32ByteArray | Converts string to UTF32 byte array. | |
StringToUtf8ByteArray | Converts string to UTF8 byte array. | |
TestDevice | Tests if the connection is alive sending sentToken and expecting to receive receivedToken. | |
ToString | Returns a String containing the name of the Component, if any. This method should not be overridden. (Inherited from Component) | |
UnicodeByteArrayToString | Converts UTF16 byte array to string. | |
UnicodeCharArrayToUnicodeByteArray | Converts a char array to byte array. | |
Utf32ByteArrayToString | Converts UTF32 byte array to string. | |
Utf8ByteArrayToString | Converts UTF8 byte array to string. |
Name | Description | |
---|---|---|
Connected | Occurs after the serial port is connected. | |
Detecting | Occurs when the serial port detection process is in progress. and there are new values of port or baud rate to be checked. | |
Disconnected | Occurs when the serial port is disconnected. | |
Disposed | Occurs when the component is disposed by a call to the Dispose method. (Inherited from Component) | |
Error | Fires when an error occurs. The error will be cleared automatically. | |
Faulted | Occurs when the serial port communication is faulted. After a Faulted event, the port will be closed automatically. | |
Idle | If the elapsed time from the last receive is higher than IdleInterval (milliseconds), Idle event occurs. If IdleTinerval is 0, this event will never occur. It works only for AutoReceive = true. | |
IdleTimeout | Occurs when there is no data received in several milliseconds, the interval is specified in the IdleTimeoutInterval property. | |
LineStatusChanged | Occurs when the line status of the serial port is changed. | |
Received | Occurs when data was received. You will get the received data in DataEventArg.Buffer, when AutoReceive is true. When AutoReceive is false, DataEventArg.Buffer property is null and you have to read the data with one of the Read methods. | |
Reconnecting | Occurs when the serial port connection was lost (faulted) and tries to reconnect. AutoReconnect must be true. | |
Resumed | Occurs when the receiver is idle and data is received. It works only for AutoReceive = true. | |
Sent | Occurs when data was sent. |