윈도우에서 네이티브 win32 API를 사용하여 시리얼 포트 통신을 가능하게 하는 플러터 플러그인입니다. 마이크로컨트롤러, 센서 또는 산업 장비와 같은 물리적 장치에 시리얼 포트를 통해 직접 연결할 수 있습니다. 윈도우 전용으로 설계되어 최소한의 추상화로 저수준 액세스를 제공하며, 데스크톱 애플리케이션에서 신뢰성 있고 효율적인 시리얼 통신이 필요한 개발자에게 적합합니다. 플러터 생태계와 원활하게 통합되며 하드웨어 중심 프로젝트에 이상적입니다.
사용 사례
아두이노 또는 유사한 마이크로컨트롤러에 연결
산업 센서에서 데이터 읽기
시리얼 프로토콜을 통한 하드웨어 장치 제어
임베디드 시스템을 위한 데스크톱 애플리케이션 개발
시리얼 주변 장치와 실시간 통신 설정
주요 기능
네이티브 win32 API 통합
윈도우 전용 플랫폼 지원
저지연 시리얼 통신
포트 열기/닫기용 간단한 API
보드레이트 및 패리티 구성 지원
실시간 데이터 스트리밍
적합한 대상
Windows 데스크톱 앱 개발자
하드웨어 인터페이스 프로젝트
사물인터넷 장치 제어 앱
임베디드 시스템 통합
실시간 데이터 수집 도구
고려 사항
Windows 운영 체제에 제한됨
일부 작업은 관리자 권한이 필요합니다
Linux 또는 macOS 지원 없음
수동 오류 처리가 필요합니다
Windows 전용 시스템 호출에 의존
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
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