SerialPort class abstract

Serial port.

Provides means to:

  • obtaining a list of serial ports on the system
  • opening, closing and getting information about ports
  • signals, modem control lines, breaks, etc.
  • low-level reading and writing data, and buffer management

Note: The port must be disposed using dispose() when done.

Error handling

Serial Port for Dart throws SerialPortError in case something goes wrong under the hood in libserialport and it returns an error code:

final port = SerialPort(...);
  port.write(...);
try {
} on SerialPortError catch (e) {
  print(SerialPort.lastError);
}

The error message is that provided by the OS, using the current language settings. The library does not define its own error codes or messages to accompany other return codes.

See also:

Constructors

SerialPort(String name)
Creates a serial port for name.
factory
SerialPort.fromAddress(int address)
@internal
factory

Properties

address int
@internal
no setter
busNumber int?
Gets the USB bus number of a USB serial adapter port.
no setter
bytesAvailable int
Gets the amount of bytes available for reading.
no setter
bytesToWrite int
Gets the amount of bytes waiting to be written.
no setter
config SerialPortConfig
Gets the current configuration of the serial port.
getter/setter pair
description String?
Gets the description of the port, for presenting to end users.
no setter
deviceNumber int?
Gets the USB device number of a USB serial adapter port.
no setter
hashCode int
The hash code for this object.
no setterinherited
isOpen bool
Gets whether the serial port is open.
no setter
macAddress String?
Gets the MAC address of a Bluetooth serial adapter port.
no setter
manufacturer String?
Get the USB manufacturer of a USB serial adapter port.
no setter
name String?
Gets the name of the port.
no setter
productId int?
Gets the USB Product ID of a USB serial adapter port.
no setter
productName String?
Gets the USB product name of a USB serial adapter port.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
serialNumber String?
Gets the USB serial number of a USB serial adapter port.
no setter
signals int
Gets the status of the control signals for the serial port.
no setter
transport int
Gets the transport type used by the port.
no setter
vendorId int?
Gets the USB vendor ID of a USB serial adapter port.
no setter

Methods

close() bool
Closes the serial port.
dispose() → void
Releases all resources associated with the serial port.
drain() → void
Waits for buffered data to be transmitted.
endBreak() bool
Takes the port transmit line out of the break state.
flush([int buffers = SerialPortBuffer.both]) → void
Flushes serial port buffers. Data in the selected buffer(s) is discarded.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
open({required int mode}) bool
Opens the serial port in the specified mode.
openRead() bool
Opens the serial port for reading only.
openReadWrite() bool
Opens the serial port for reading and writing.
openWrite() bool
Opens the serial port for writing only.
read(int bytes, {int timeout = -1}) Uint8List
Read data from the serial port.
startBreak() bool
Puts the port transmit line into the break state.
toString() String
A string representation of this object.
inherited
write(Uint8List bytes, {int timeout = -1}) int
Write data to the serial port.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

availablePorts List<String>
Lists the serial ports available on the system.
no setter
lastError SerialPortError?
Gets the error for a failed operation.
no setter