项目逻辑添加
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user