✨ feat(*): 更新 PLC 相关功能与配置
- 在 appConfig.json 中添加 EndianFormat 配置项并更新相关输入输出地址 - 修改 ResultCode 类型为 short,确保与 PLC 通信一致 - 新增 DesignTimePlcService 以支持设计时的 PLC 测试写入功能 - 更新 SystemSettingViewModel 和 DashboardPage 以支持手动测试写入 - 调整多个视图模型和服务以适应新的 PLC 写入逻辑 - 更新相关单元测试以验证新功能的正确性
This commit is contained in:
@@ -34,7 +34,7 @@ public sealed class SystemSettingViewModelTests
|
||||
StatusMessage = "SFTP 连接成功,根目录可访问。"
|
||||
}
|
||||
};
|
||||
var viewModel = new SystemSettingViewModel(configService, fileCheckService, stateStore, dispatcherService);
|
||||
var viewModel = new SystemSettingViewModel(configService, fileCheckService, stateStore, dispatcherService, new FakePlcService());
|
||||
|
||||
await viewModel.TestFileCheckConnectionCommand.ExecuteAsync(null);
|
||||
|
||||
@@ -60,7 +60,7 @@ public sealed class SystemSettingViewModelTests
|
||||
StatusMessage = "SFTP 连接失败: timeout"
|
||||
}
|
||||
};
|
||||
var viewModel = new SystemSettingViewModel(configService, fileCheckService, stateStore, dispatcherService);
|
||||
var viewModel = new SystemSettingViewModel(configService, fileCheckService, stateStore, dispatcherService, new FakePlcService());
|
||||
|
||||
await viewModel.TestFileCheckConnectionCommand.ExecuteAsync(null);
|
||||
|
||||
@@ -87,7 +87,7 @@ public sealed class SystemSettingViewModelTests
|
||||
});
|
||||
});
|
||||
|
||||
var viewModel = new SystemSettingViewModel(configService, new FakeFileCheckService(), stateStore, dispatcherService);
|
||||
var viewModel = new SystemSettingViewModel(configService, new FakeFileCheckService(), stateStore, dispatcherService, new FakePlcService());
|
||||
|
||||
Assert.Single(viewModel.PlcMonitorItems);
|
||||
Assert.Equal("PcbArrived", viewModel.PlcMonitorItems[0].Name);
|
||||
@@ -104,7 +104,7 @@ public sealed class SystemSettingViewModelTests
|
||||
var configService = new FakeAppConfigService();
|
||||
var stateStore = new AppStateStore();
|
||||
var dispatcherService = new CapturedDispatcherService(Dispatcher.CurrentDispatcher);
|
||||
var viewModel = new SystemSettingViewModel(configService, new FakeFileCheckService(), stateStore, dispatcherService);
|
||||
var viewModel = new SystemSettingViewModel(configService, new FakeFileCheckService(), stateStore, dispatcherService, new FakePlcService());
|
||||
_ = CollectionViewSource.GetDefaultView(viewModel.PlcMonitorItems);
|
||||
|
||||
Exception? capturedException = null;
|
||||
@@ -160,7 +160,8 @@ public sealed class SystemSettingViewModelTests
|
||||
configService,
|
||||
new FakeFileCheckService(),
|
||||
stateStore,
|
||||
new CanceledDispatcherService());
|
||||
new CanceledDispatcherService(),
|
||||
new FakePlcService());
|
||||
var synchronizationContext = new ExceptionCapturingSynchronizationContext();
|
||||
SynchronizationContext? originalContext = SynchronizationContext.Current;
|
||||
|
||||
@@ -296,6 +297,37 @@ public sealed class SystemSettingViewModelTests
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 提供系统设置页测试用 PLC 服务替身。
|
||||
/// </summary>
|
||||
private sealed class FakePlcService : IPlcService
|
||||
{
|
||||
public Task<PlcSignalSnapshot> ReadSignalsAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.FromResult(new PlcSignalSnapshot());
|
||||
}
|
||||
|
||||
public Task<PlcMonitorSnapshot> ReadMonitorSnapshotAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.FromResult(new PlcMonitorSnapshot());
|
||||
}
|
||||
|
||||
public Task WriteStateAsync(PlcProcessState state, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task ForceReconnectAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<PlcWriteResult> WriteRawValueAsync(string address, PlcWriteType type, string value, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.FromResult(PlcWriteResult.Success(address, type, value));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 提供立即执行的测试用 Dispatcher,实现与设计时调度一致的同步行为。
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user