Serial Port Communication in Flutter: RS-232/RS-485 in Practice
Configure baud rate, parity, and stop bits from Flutter, pick between flutter_libserialport, serial_port_win32, and flserial, and keep continuous reads off the UI thread.
Published on • November 10, 2026
AI Assistant

Industrial gear - PLCs, GPS receivers, weighing scales - still talks over serial wires, and Flutter apps increasingly have to read that traffic. The tricky part is that the two packages most people find first, flutter_serial_port and serial_port, are effectively dead, while the working options differ per platform. This post covers the serial settings you must get right, which packages are actually usable today, and how to run continuous reads without freezing your UI.
RS-232 and RS-485: what you actually configure
RS-232 is single-ended, typically limited to about 15 m, and point-to-point. RS-485 uses a differential pair, reaches around 1200 m, and supports multiple devices on one bus, which is why it dominates factory floors. Both need the same framing agreed on both ends:
| Setting | Typical values | Notes |
|---|---|---|
| Baud rate | 9600, 19200, 115200 | Must match the device exactly |
| Data bits | 8 | 7 for some legacy ASCII devices |
| Parity | none, even, odd | Error checking bit after the data bits |
| Stop bits | 1, 2 | Marks the end of each byte |
| Flow control | none, RTS/CTS, XON/XOFF | Hardware or software handshaking |
Getting any one of these wrong produces silence or garbage, so make them configurable instead of hard-coding 9600/8/N/1.
The package landscape (mind the traps)
Search pub.dev for “serial port” and two dead ends appear at the top:
- flutter_serial_port - version 0.0.1, published 2019, marked discontinued and Dart 3 incompatible. It is an untouched plugin template; do not add it.
- serial_port - version 0.3.1 from 2015, Dart 1 only. It shipped prebuilt binaries for Win/Linux/macOS and a handy
serial_port listCLI, but it cannot compile in a modern SDK.
What is alive today:
| Package | Platforms | Basis |
|---|---|---|
| flutter_libserialport 0.6.0 | Android, Linux, macOS, Windows | Builds/deploys the sigrok libserialport C library |
| serial_port_win32 3.0.0 | Windows | win32 package, raw Win32 API |
| flserial 0.7.3 | Android | FFI wrapper for an RS-232 C library |
| dart_periphery | Linux | GPIO/SPI/I2C/serial for SBCs |
| serial | web | window.navigator.serial (Web Serial API) |
| modbus_client_serial | protocol layer | Modbus RTU/ASCII over any serial stream |
Windows in practice: serial_port_win32
import 'package:serial_port_win32/serial_port_win32.dart';
final ports = SerialPort.getAvailablePorts(); // ["COM3", "COM4"]
if (ports.isEmpty) return;
final port = SerialPort(ports.first, openNow: true, ByteSize: 8, BaudRate: 9600);
port.openWithSettings(BaudRate: CBR_115200); // re-open at a different rate
port.StopBits = ONESTOPBIT;
final bytes = await port.readBytes(64, timeout: const Duration(milliseconds: 100));
await port.writeBytesFromString("AT\r\n",
includeZeroTerminator: false, stringConverter: StringConverter.nativeUtf8);
if (!port.isOpened) port.close();
Things the 3.x README is explicit about: the port object is a singleton per COM name (do not re-create it), Parity and StopBits setters now take DCB_PARITY / DCB_STOP_BITS enums rather than raw ints, failures throw WindowsException instead of generic Exceptions, and you must not use hot restart while a port is open - the handle leaks and the next run fails to open it. readBytesUntil (terminator-based), readBytes (timeout-based), and readFixedSizeBytes cover the three framing styles, and setFlowControlSignal(SETDTR) / CLRDTR toggles modem lines.
Cross-platform: flutter_libserialport
flutter_libserialport adds no API of its own - it just builds libserialport for you, so you code against the libserialport Dart package:
import 'package:flutter_libserialport/flutter_libserialport.dart';
final names = SerialPort.availablePorts; // COM*, /dev/ttyUSB*, /dev/tty.usbmodem*
final port = SerialPort(names.first);
if (!port.openReadWrite()) {
print(SerialPort.lastError); // SerialPortError with the OS message
}
port.config
..baudRate = 115200
..bits = 8
..parity = 0 // none
..stopBits = 1
..setFlowControl(0); // preset flow-control mode
final reader = SerialPortReader(port);
final sub = reader.stream.listen((data) => parse(data));
port.write(Uint8List.fromList([0x02, 0x31, 0x03]));
// ... later
await sub.cancel();
port.dispose(); // required: releases the native resources
Two rules from the docs: a port must be opened before you can change its settings, and you should always set baud rate, data bits, parity, and stop bits because the OS may leave whatever the last program used. Every failed operation surfaces as SerialPortError carrying the OS message in the system language.
Continuous reads: streams, framing, and isolates
Never poll in a loop on the UI isolate. Subscribe once and frame the bytes:
final buffer = <int>[];
sub = reader.stream.listen((chunk) {
buffer.addAll(chunk);
// split on CRLF, keep the partial line for the next chunk
var idx = buffer.indexOf(13);
while (idx != -1 && idx + 1 < buffer.length && buffer[idx + 1] == 10) {
final line = String.fromCharCodes(buffer.sublist(0, idx));
buffer.removeRange(0, idx + 2);
idx = buffer.indexOf(13);
onLine(line);
}
});
Framing is your job: ASCII devices terminate with CR/LF, NMEA sentences end with *HH checksums, and Modbus RTU frames are length-prefixed with a CRC-16. If parsing or CRC checking gets heavy (or you process thousands of frames per second), move it off the UI isolate with Isolate.run or a long-lived worker isolate that receives the chunks and sends back parsed records - byte transport stays on the port’s own thread, only your Dart logic migrates.
Industrial use cases and error handling
- PLCs: Modbus RTU over RS-485 - use
modbus_client_serialfor framing and pair it with aSerialPortReaderstream; remember RS-485 buses are half-duplex, so the adapter flips direction between request and response. - GPS: NMEA 0183 at 9600/8/N/1, sentences like
$GPGGA,...*cs; validate the checksum and drop malformed lines rather than trusting every frame. - Scales and printers: often 7 data bits with even parity, which is why the settings must be user-configurable.
Error handling needs the same discipline as any hardware I/O: wrap open()/openReadWrite() in a failure branch (permission denied or port busy is normal), pass timeouts to every read so a disconnected device cannot hang the UI, check isOpen before writes, catch SerialPortError / WindowsException where the platform throws, and always close() / dispose() in a finally so the port is released when the widget or service is disposed.
Takeaway: Skip the discontinued flutter_serial_port and Dart-1-era serial_port, configure all five framing settings explicitly (open first, then apply), drive continuous reads through a byte stream with your own framing and an isolate for heavy parsing, and cover Windows (serial_port_win32), Linux/macOS/Android (flutter_libserialport), and web (Web Serial) separately.