- 在 appConfig.json 中添加 EndianFormat 配置项并更新相关输入输出地址 - 修改 ResultCode 类型为 short,确保与 PLC 通信一致 - 新增 DesignTimePlcService 以支持设计时的 PLC 测试写入功能 - 更新 SystemSettingViewModel 和 DashboardPage 以支持手动测试写入 - 调整多个视图模型和服务以适应新的 PLC 写入逻辑 - 更新相关单元测试以验证新功能的正确性
42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using AxiOmron.PcbCheck.Options;
|
||
using AxiOmron.PcbCheck.Services.Implementations;
|
||
using IoTClient.Enums;
|
||
using Xunit;
|
||
|
||
namespace AxiOmron.PcbCheck.Tests;
|
||
|
||
/// <summary>
|
||
/// 验证欧姆龙 FINS PLC 服务的通信参数解析行为。
|
||
/// </summary>
|
||
public sealed class OmronFinsPlcServiceTests
|
||
{
|
||
/// <summary>
|
||
/// 默认字节序应使用 BADC,以匹配现场 D 区 Int16 的高低字节顺序。
|
||
/// </summary>
|
||
[Fact]
|
||
public void ResolveEndianFormat_ShouldUseBadc_WhenConfigurationIsDefault()
|
||
{
|
||
var options = new PlcOptions();
|
||
|
||
EndianFormat result = OmronFinsPlcService.ResolveEndianFormat(options);
|
||
|
||
Assert.Equal(EndianFormat.BADC, result);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 非法字节序配置应抛出明确异常,避免使用错误端序静默读写 PLC 寄存器。
|
||
/// </summary>
|
||
[Fact]
|
||
public void ResolveEndianFormat_ShouldThrow_WhenConfigurationIsInvalid()
|
||
{
|
||
var options = new PlcOptions
|
||
{
|
||
EndianFormat = "XYZ"
|
||
};
|
||
|
||
var exception = Assert.Throws<InvalidOperationException>(() => OmronFinsPlcService.ResolveEndianFormat(options));
|
||
|
||
Assert.Contains("PLC 字节序配置无效", exception.Message);
|
||
}
|
||
}
|