Documentation
¶
Index ¶
- type CommandManager
- type CommandSession
- type ConnectConfig
- type Manager
- func (m *Manager) CloseAll()
- func (m *Manager) Connect(cfg ConnectConfig) (string, error)
- func (m *Manager) Disconnect(sessionID string)
- func (m *Manager) GetSession(sessionID string) (*Session, bool)
- func (m *Manager) GetSessionByAssetID(assetID int64) (CommandSession, bool)
- func (m *Manager) ListPorts() ([]SerialPortInfo, error)
- func (m *Manager) SetCallbacks(sessionID string, onData func(data []byte), onClosed func(sessionID string))
- func (m *Manager) TestConnection(ctx context.Context, cfg ConnectConfig) error
- type SerialPortInfo
- type Session
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandManager ¶
type CommandManager interface {
GetSessionByAssetID(assetID int64) (CommandSession, bool)
}
CommandManager 是供 AI 查找活跃串口会话使用的最小管理器接口。
type CommandSession ¶
type CommandSession interface {
ExecCommand(command string, silenceTimeout, maxTimeout time.Duration) (string, error)
}
CommandSession 是供 AI 串口命令执行使用的最小会话接口。
type ConnectConfig ¶
type ConnectConfig struct {
PortPath string
BaudRate int
DataBits int
StopBits string
Parity string
FlowControl string
AssetID int64
}
ConnectConfig 串口连接配置
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager 管理所有串口会话
func (*Manager) Connect ¶
func (m *Manager) Connect(cfg ConnectConfig) (string, error)
Connect 打开串口连接,返回 sessionId。调用方通过 SetCallbacks 设置回调。 若未在宽限时间内设置回调,会话会自动关闭并清理,避免悬挂。
func (*Manager) GetSession ¶
GetSession 获取活跃会话
func (*Manager) GetSessionByAssetID ¶
func (m *Manager) GetSessionByAssetID(assetID int64) (CommandSession, bool)
GetSessionByAssetID 根据资产 ID 查找活跃的串口会话
func (*Manager) ListPorts ¶
func (m *Manager) ListPorts() ([]SerialPortInfo, error)
ListPorts 列出系统可用串口
func (*Manager) SetCallbacks ¶
func (m *Manager) SetCallbacks(sessionID string, onData func(data []byte), onClosed func(sessionID string))
SetCallbacks 设置会话的数据和关闭回调(在 Connect 返回 sessionId 后调用)。 回调设置完成后才启动读取 goroutine,避免 SetCallbacks 调用前的数据丢失。
func (*Manager) TestConnection ¶
func (m *Manager) TestConnection(ctx context.Context, cfg ConnectConfig) error
TestConnection opens a serial port and immediately closes it. It returns as soon as ctx is canceled; if the underlying open call completes after cancellation, the temporary session is still closed in the background.
type SerialPortInfo ¶
type SerialPortInfo struct {
Name string `json:"name"`
DisplayName string `json:"displayName"`
ProductID string `json:"productId,omitempty"`
VendorID string `json:"vendorId,omitempty"`
SerialNumber string `json:"serialNumber,omitempty"`
}
SerialPortInfo 可用串口信息
type Session ¶
Session 表示一个活跃的串口终端会话
func (*Session) ExecCommand ¶
func (s *Session) ExecCommand(command string, silenceTimeout, maxTimeout time.Duration) (string, error)
ExecCommand 向串口发送命令并收集输出。 适用于 AI 工具调用场景:写入命令后等待输出静默(silenceTimeout)或达到最大等待时间。