SerialPort class
Constructors
Properties
- BaudRate ← int
-
using standard win32 Value like
CBR_115200
no getter - ByteSize ← int
-
data byteSize
no getter
-
commTimeouts
→ Pointer<
COMMTIMEOUTS> -
win32
COMMTIMEOUTS
structfinal -
dcb
→ Pointer<
DCB> -
dcb is win32
DCB
structfinal - handler ↔ int?
-
file handle
handler will be
INVALID_HANDLE_VALUE
if failedgetter/setter pair - hashCode → int
-
The hash code for this object.
no setterinherited
- isOpened → bool
-
no setter
- openStatus ← bool
-
change isOpened value if necessary
no getter
- Parity ← int
-
You can use
NOPARITY
,ODDPARITY
and so on like win32no getter - portName → String
-
portName like COM3
final
- readBytesSize ← int
-
using readBytesSize setting
_readBytesSize
no getter - ReadIntervalTimeout ← int
-
ReadIntervalTimeout
no getter
- readOnBeforeFunction ↔ dynamic Function()
-
readOnBeforeFunction define what to do when data coming
getter/setter pair
- readOnListenFunction ↔ dynamic Function(Uint8List value)
-
readOnListenFunction define what to do when data coming
getter/setter pair
- ReadTotalTimeoutConstant ← int
-
A 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.
no getter
- ReadTotalTimeoutMultiplier ← int
-
ReadTotalTimeoutMultiplier
no getter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- StopBits ← int
-
1 stop bit is
ONESTOPBIT
, value is 0 more docs in https://docs.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-dcbno getter - WriteTotalTimeoutConstant ← int
-
WriteTotalTimeoutConstant
no getter
- WriteTotalTimeoutMultiplier ← int
-
WriteTotalTimeoutMultiplier
no getter
Methods
-
close(
) → void - close port which was opened
-
closeOnListen(
{required dynamic onListen()}) → StreamSubscription - [closeOnListen[ let you can close onListen function before closing port and using onError or onDone when port is closed.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
open(
) → void - open can be called when handler is null or handler is closed
-
openWithSettings(
{int BaudRate = CBR_115200, int Parity = NOPARITY, int StopBits = ONESTOPBIT, int ByteSize = 8, int ReadIntervalTimeout = 10, int ReadTotalTimeoutConstant = 1, int ReadTotalTimeoutMultiplier = 0}) → void - if you want open a port with some extra settings, use openWithSettings
-
readBytesOnListen(
int bytesSize, dynamic onData(Uint8List value), {void onBefore()?, Duration dataPollingInterval = const Duration(microseconds: 500)}) → void -
readBytesOnListen can listen data in polling mode, endless loop, you can use
onData
to get data. -
readBytesUntil(
Uint8List expected, {Duration dataPollingInterval = const Duration(microseconds: 500)}) → Future< Uint8List> -
readBytesUntil will read until an
expected
sequence is found -
setFlowControlSignal(
int flag) → void - setFlowControlSignal can set DTR and RTS signal Controlling DTR and RTS
-
toString(
) → String -
A string representation of this object.
inherited
-
writeBytesFromString(
String buffer, {int timeout = 500, bool includeZeroTerminator = true}) → bool - writeBytesFromString will convert String to ANSI Code corresponding to char
-
writeBytesFromUint8List(
Uint8List uint8list, {int timeout = 500}) → bool - writeBytesFromUint8List will write Uint8List directly, please ensure the last of list is 0 terminator if you want to convert it to char.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
getAvailablePorts(
) → List< String> - read Registry in Windows to get ports getAvailablePorts can be called using SerialPort.getAvailablePorts()
-
getPortsWithFullMessages(
{String classGUIDStr = GUID_DEVINTERFACE_COMPORT}) → List< PortInfo> -
Using getPortsWithFullMessages to get Serial Ports Info
Parameter: {String classGUIDStr = GUID_DEVINTERFACE_COMPORT}, refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/install/guid-devinterface-comport
You can set classGUIDStr = GUID_DEVINTERFACE_USB_DEVICE
return
PortInfo({ required this.portName, required this.friendlyName, required this.hardwareID, })
;
Constants
- CLRDTR → const int
- CLRDTR Clears the DTR (data-terminal-ready) signal.
- CLRRTS → const int
- CLRRTS Clears the RTS (request-to-send) signal.
- ERROR_IO_PENDING → const int
- ERROR_IO_PENDING Overlapped I/O operation is in progress.
- EV_RXCHAR → const int
- EV_RXCHAR A character was received and placed in the input buffer.
- SETDTR → const int
- SETDTR Sends the DTR (data-terminal-ready) signal.
- SETRTS → const int
- SETRTS Sends the RTS (request-to-send) signal.