Update reading and writing modbus protocol by a waiting time

This commit is contained in:
atef 2025-09-18 12:34:56 +02:00
parent 037b411d6b
commit a094c4f080
2 changed files with 6 additions and 3 deletions

View File

@ -29,7 +29,7 @@ public class SerialPortChannel : ConnectionChannel<SerialPort>
{ {
var serialPort = new SerialPort(portName, baudRate, parity, dataBits, sb) var serialPort = new SerialPort(portName, baudRate, parity, dataBits, sb)
{ {
ReadTimeout = 1000, // milliseconds ReadTimeout = 1000, // milliseconds
WriteTimeout = 1000 // milliseconds WriteTimeout = 1000 // milliseconds
}; };
serialPort.Open(); serialPort.Open();

View File

@ -37,11 +37,11 @@ public class ModbusDevice<[DynamicallyAccessedMembers(All)] R> where R : notnull
public R Read(R record) public R Read(R record)
{ {
// Console.WriteLine($"Reading { _Batches.Count } Modbus batches."); //Console.WriteLine($"Reading { _Batches.Count } Modbus batches.");
foreach (var batch in _Batches) foreach (var batch in _Batches)
{ {
batch.Read(record); batch.Read(record);
Thread.Sleep(50); // this added mainly for Growatt reading Thread.Sleep(30); // this added mainly for Growatt reading
} }
return record; return record;
} }
@ -49,6 +49,9 @@ public class ModbusDevice<[DynamicallyAccessedMembers(All)] R> where R : notnull
public void Write(R record) public void Write(R record)
{ {
foreach (var batch in _Batches) foreach (var batch in _Batches)
{
batch.Write(record); batch.Write(record);
Thread.Sleep(50); // this added mainly for Growatt reading
}
} }
} }