This commit is contained in:
xyy
2026-06-16 11:53:02 +08:00
parent 24763126ef
commit 2dadfe3861
11 changed files with 541 additions and 180 deletions

View File

@@ -188,6 +188,24 @@ namespace AciTester.Services
_tcpClient?.Close();
_tcpClient?.Dispose();
}
public async Task<int> ReadInt32Async(ushort startAddress)
{
await EnsureConnectedAsync();
var regs = await ReadHoldingRegistersAsync(startAddress, 2);
return (regs[0] << 16) | regs[1];
}
public async Task WriteInt32Async(ushort startAddress, int value)
{
await EnsureConnectedAsync();
var bytes = BitConverter.GetBytes(value);
if (BitConverter.IsLittleEndian) Array.Reverse(bytes);
ushort high = (ushort)((bytes[0] << 8) | bytes[1]);
ushort low = (ushort)((bytes[2] << 8) | bytes[3]);
await _master.WriteMultipleRegistersAsync(_config.SlaveId, startAddress, new ushort[] { high, low });
}
}