SerialPort class Null safety

Constructors

SerialPort(String portName, {int BaudRate = CBR_115200, int Parity = NOPARITY, int StopBits = ONESTOPBIT, int ByteSize = 8, int ReadIntervalTimeout = 10, int ReadTotalTimeoutConstant = 1, int ReadTotalTimeoutMultiplier = 0, bool openNow = true})
reusable instance using factory
factory

Properties

BaudRate int
using standard win32 Value like CBR_115200
write-only
ByteSize int
data byteSize
write-only
commTimeouts Pointer<COMMTIMEOUTS>
win32 COMMTIMEOUTS struct
final
dcb Pointer<DCB>
dcb is win32 DCB struct
final
handler int?
file handle handler will be INVALID_HANDLE_VALUE if failed
read / write
hashCode int
The hash code for this object. [...]
read-only, inherited
isOpened bool
read-only
openStatus bool
change isOpened value if necessary
write-only
Parity int
You can use NOPARITY, ODDPARITY and so on like win32
write-only
portName String
portName like COM3
final
readBytesSize int
using readBytesSize setting _readBytesSize
write-only
ReadIntervalTimeout int
ReadIntervalTimeout [...]
write-only
readOnBeforeFunction ↔ dynamic Function()
readOnBeforeFunction define what to do when data comming
read / write
readOnListenFunction ↔ dynamic Function(Uint8List value)
readOnListenFunction define what to do when data comming
read / write
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. [...]
write-only
ReadTotalTimeoutMultiplier int
ReadTotalTimeoutMultiplier [...]
write-only
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
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-dcb
write-only
WriteTotalTimeoutConstant int
WriteTotalTimeoutConstant [...]
write-only
WriteTotalTimeoutMultiplier int
WriteTotalTimeoutMultiplier [...]
write-only

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 non-existent 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
readBytesOnce(int bytesSize) Future<Uint8List>
readBytesOnce read data only once.
readBytesOnListen(int bytesSize, dynamic onData(Uint8List value), {void onBefore()?}) → void
readBytesOnListen can constantly listen data, you can use onData to get data.
toString() String
A string representation of this object. [...]
inherited
writeBytesFromString(String buffer) bool
writeBytesFromString will convert String to ANSI Code corresponding to char Serial devices can receive ANSI code if you write "hello" in String, device will get "hello\0" with "\0" automatically.
writeBytesFromUint8List(Uint8List uint8list) 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()

Constants

ERROR_IO_PENDING → const int
ERROR_IO_PENDING Overlapped I/O operation is in progress.
997
EV_RXCHAR → const int
EV_RXCHAR A character was received and placed in the input buffer.
0x0001