Package selection guidance compiled from public package information, community data, and project usage.
A Flutter plugin that enables serial port communication on Windows using the native win32 API. It allows direct connection to physical devices via serial ports, such as microcontrollers, sensors, or industrial equipment. Designed specifically for Windows, it provides low-level access with minimal abstraction, making it suitable for developers needing reliable and efficient serial communication in desktop applications. The package integrates seamlessly with Flutter's ecosystem and is ideal for hardware-focused projects.
Use cases
Connecting to Arduino or similar microcontrollers
Reading data from industrial sensors
Controlling hardware devices via serial protocol
Developing desktop applications for embedded systems
Establishing real-time communication with serial peripherals
Key features
Native win32 API integration
Windows-only platform support
Low-latency serial communication
Simple API for opening/closing ports
Supports baud rate and parity configuration
Real-time data streaming
Suitable for
Windows desktop app developers
Hardware interface projects
IoT device control apps
Embedded system integrations
Real-time data acquisition tools
Considerations
Limited to Windows operating system
Requires admin privileges for some operations
No Linux or macOS support
Manual error handling required
Dependent on Windows-specific system calls
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
serial_port_win32
A SerialPort library using win32 API.
Breaking Changes from 2.x.x to 3.x.x
Due to many major changes in win32 package, this package need to break some APIs.
Some main APIs change below:
set Parity(int parity) -> set Parity(DCB_PARITY parity)
set StopBits(int stopBits) -> set StopBits(DCB_STOP_BITS stopBits)
final LPWSTR _portNameUtf16; -> final PCWSTR _portNameUtf16;
Some Exceptions change to WindowsExceptions
Deprecated
@Deprecated("Use win32 constant CLRDTR instead of this, because it is more clear to understand")
staticconstint CLRDTR = 6;
/// Clears the RTS (request-to-send) signal.@Deprecated("Use win32 constant CLRRTS instead of this, because it is more clear to understand")
staticconstint CLRRTS = 4;
/// Sends the DTR (data-terminal-ready) signal.@Deprecated("Use win32 constant SETDTR instead of this, because it is more clear to understand")
staticconstint SETDTR = 5;
/// Sends the RTS (request-to-send) signal.@Deprecated("Use win32 constant SETRTS instead of this, because it is more clear to understand")
staticconstint SETRTS = 3;
Getting Started
Get Ports
final ports = SerialPort.getAvailablePorts();
print(ports);
/// result like [COM3, COM4]
The port instance is Singleton Pattern. Don't re-create port for same Com name.
final port = SerialPort("COM5", openNow: true, ByteSize: 8, BaudRate: 9600);
// orfinal port = SerialPort("COM5", openNow: false, ByteSize: 8, BaudRate: 9600);
port.open();
// or
port.openWithSettings(BaudRate: CBR_115200);
// final port = SerialPort("COM5"); /// auto open with default settings
Read
There are several methods to read bytes from serial port.
readBytesUntil
[readBytesUntil] will read until an [expected] sequence is found
readBytes
General Read with the timeout parameter.
readFixedSizeBytes
[readFixedSizeBytes] will always read until readData.length == bytesSize.
print(await port.readBytesUntil(Uint8List.fromList("T".codeUnits))); /// '\0' is not included/// orvar read = port.readBytes(18, timeout: Duration(milliseconds: 10))..then((onValue) => print(onValue));
var result = await read;
print(result);
/// orvar fixedBytesRead = port.readFixedSizeBytes(2)..then((onValue) => print(onValue));
await fixedBytesRead;
/// see more in small example