项目逻辑添加

This commit is contained in:
2026-05-15 11:13:06 +08:00
parent 0b68413bf9
commit a050c307a8
5 changed files with 25 additions and 25 deletions

View File

@@ -46,13 +46,20 @@ namespace TabletTester2025.Services
}
throw new Exception($"无法连接到 PLC ({_config.IpAddress}:{_config.Port})");
}
//读取寄存器返回浮点型
public async Task<float> ReadFloatAsync(ushort startAddress)
{
await EnsureConnectedAsync();
var registers = await ReadHoldingRegistersAsync(startAddress, 2);
return UshortToFloat(registers[1], registers[0]);
}
//读取返回整型
public async Task<int> ReadIntAsync(ushort startAddress)
{
await EnsureConnectedAsync();
var registers = await ReadHoldingRegistersAsync(startAddress, 1);
return registers[0];
}
public async Task WriteCoilAsync(ushort coilAddress, bool value)
{