初始化2

This commit is contained in:
SunYF
2026-08-28 15:06:01 +08:00
parent b34325a16f
commit a9c3fbeb41
537 changed files with 176215 additions and 17 deletions
+35
View File
@@ -0,0 +1,35 @@
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
}