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 }