更新2026
This commit is contained in:
@@ -80,6 +80,18 @@ namespace TabletTester2025.Services
|
||||
await _master.WriteSingleRegisterAsync(_config.SlaveId, registerAddress, value);
|
||||
}
|
||||
|
||||
public async Task WriteFloatAsync(ushort startAddress, float value)
|
||||
{
|
||||
await EnsureConnectedAsync();
|
||||
byte[] bytes = BitConverter.GetBytes(value);
|
||||
ushort[] registers =
|
||||
{
|
||||
(ushort)((bytes[2] << 8) | bytes[3]),
|
||||
(ushort)((bytes[0] << 8) | bytes[1])
|
||||
};
|
||||
await _master.WriteMultipleRegistersAsync(_config.SlaveId, startAddress, registers);
|
||||
}
|
||||
|
||||
public async Task<ushort[]> ReadHoldingRegistersAsync(ushort startAddress, ushort count)
|
||||
{
|
||||
await EnsureConnectedAsync();
|
||||
@@ -120,4 +132,4 @@ namespace TabletTester2025.Services
|
||||
await task;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user