fix: 修复串口 read timeout 未生效的问题
Some checks failed
test / native-os-build (macOS-latest) (push) Has been cancelled
test / native-os-build (ubuntu-latest) (push) Has been cancelled
test / native-os-build (windows-latest) (push) Has been cancelled
test / cross-os-build (freebsd amd64) (push) Has been cancelled
test / cross-os-build (linux ppc64le) (push) Has been cancelled
test / cross-os-build (openbsd 386) (push) Has been cancelled
test / cross-os-build (openbsd amd64) (push) Has been cancelled
test / cross-os-build (openbsd arm) (push) Has been cancelled

- 将串口文件描述符设置为非阻塞模式,确保 read() 不会阻塞
- 修改 VMIN 从 1 改为 0,让 select() 正确控制读取超时
- 添加 Timeout 错误代码,超时时正确返回错误而不是 (0, nil)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-05 10:47:17 +08:00
parent b3711b62ad
commit f10848f47f
2 changed files with 17 additions and 3 deletions

View File

@@ -163,6 +163,8 @@ const (
ErrorEnumeratingPorts
// PortClosed the port has been closed while the operation is in progress
PortClosed
// Timeout the read operation timed out
Timeout
// FunctionNotImplemented the requested function is not implemented
FunctionNotImplemented
)
@@ -192,6 +194,8 @@ func (e PortError) EncodedErrorString() string {
return "Could not enumerate serial ports"
case PortClosed:
return "Port has been closed"
case Timeout:
return "Read timeout"
case FunctionNotImplemented:
return "Function not implemented"
default: