Files
bj_power/bj_power_mes/internal/plc/mock.go
T

35 lines
747 B
Go
Raw Normal View History

2026-08-28 15:06:01 +08:00
package plc
import (
"context"
"errors"
)
// mockClient 模拟西门子 PLC:下发成功即认为写入寄存器,完成信号由外部置位。
type mockClient struct {
ack bool
sent string
}
func newMockClient() *mockClient {
return &mockClient{}
}
func (m *mockClient) SendProcessCode(_ context.Context, combination string) ([]int, error) {
codes := parseCombination(combination)
m.sent = combination
m.ack = false
return codes, nil
}
func (m *mockClient) QueryDone(_ context.Context) (bool, error) {
if m.sent == "" {
return false, errors.New("no process sent")
}
// 模拟:假设 PLC 已完成,30 秒后返回完成信号
return m.ack, nil
}
func (m *mockClient) AckDone(_ context.Context, ok bool) {
m.ack = ok
}