update Modbus Library to achieve clear buffers regularly
This commit is contained in:
parent
4c94238188
commit
6c0271e70c
|
|
@ -36,4 +36,5 @@ public abstract class ModbusClient
|
|||
SlaveId = slaveId;
|
||||
Endian = endian;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -8,10 +8,12 @@ namespace InnovEnergy.Lib.Protocols.Modbus.Slaves;
|
|||
public class ModbusDevice<[DynamicallyAccessedMembers(All)] R> where R : notnull
|
||||
{
|
||||
private readonly IReadOnlyList<Batch<R>> _Batches;
|
||||
private readonly ModbusClient _modbusClient;
|
||||
|
||||
public ModbusDevice(ModbusClient modbusClient, Int32 addressOffset = 0)
|
||||
{
|
||||
_Batches = modbusClient.MakeBatchesFor<R>(addressOffset);
|
||||
_modbusClient = modbusClient;
|
||||
}
|
||||
|
||||
public R Read()
|
||||
|
|
@ -40,6 +42,7 @@ public class ModbusDevice<[DynamicallyAccessedMembers(All)] R> where R : notnull
|
|||
//Console.WriteLine($"Reading { _Batches.Count } Modbus batches.");
|
||||
foreach (var batch in _Batches)
|
||||
{
|
||||
_modbusClient.Channel.ClearBuffers();
|
||||
batch.Read(record);
|
||||
//Thread.Sleep(30); // this added mainly for Growatt reading
|
||||
}
|
||||
|
|
@ -50,6 +53,7 @@ public class ModbusDevice<[DynamicallyAccessedMembers(All)] R> where R : notnull
|
|||
{
|
||||
foreach (var batch in _Batches)
|
||||
{
|
||||
_modbusClient.Channel.ClearBuffers();
|
||||
batch.Write(record);
|
||||
//Thread.Sleep(50); // this added mainly for Growatt reading
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue