This commit is contained in:
@@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user