ModbusClient添加帧前时间

This commit is contained in:
Diego2098
2023-05-15 22:45:55 +08:00
parent 158aa05fac
commit b4388a58d6
5 changed files with 21 additions and 2 deletions

View File

@@ -58,6 +58,7 @@ public class ModbusRtu : CollectBase, IDisposable
public override async Task<OperResult> WriteValueAsync(CollectVariableRunTime deviceVariable, string value)
{
await Task.Delay(driverPropertys.FrameTime);
return await _plc.WriteAsync(deviceVariable.DataType, deviceVariable.VariableAddress, value);
}
@@ -86,6 +87,7 @@ public class ModbusRtu : CollectBase, IDisposable
}
protected override async Task<OperResult<byte[]>> ReadAsync(string address, int length, CancellationToken cancellationToken)
{
await Task.Delay(driverPropertys.FrameTime, cancellationToken);
return await _plc.ReadAsync(address, length, cancellationToken);
}
@@ -104,6 +106,9 @@ public class ModbusRtuProperty : CollectDriverPropertyBase
[DeviceProperty("默认解析顺序", "")]
public DataFormat DataFormat { get; set; }
[DeviceProperty("帧前时间", "某些设备性能较弱,报文间需要间隔较长时间")]
public int FrameTime { get; set; } = 0;
[DeviceProperty("共享链路", "")]
public override bool IsShareChannel { get; set; } = false;

View File

@@ -53,6 +53,7 @@ public class ModbusRtuOverTcp : CollectBase, IDisposable
public override async Task<OperResult> WriteValueAsync(CollectVariableRunTime deviceVariable, string value)
{
await Task.Delay(driverPropertys.FrameTime);
return await _plc.WriteAsync(deviceVariable.DataType, deviceVariable.VariableAddress, value);
}
@@ -73,9 +74,10 @@ public class ModbusRtuOverTcp : CollectBase, IDisposable
_plc.Station = driverPropertys.Station;
_plc.TimeOut = driverPropertys.TimeOut;
}
protected override Task<OperResult<byte[]>> ReadAsync(string address, int length, CancellationToken cancellationToken)
protected override async Task<OperResult<byte[]>> ReadAsync(string address, int length, CancellationToken cancellationToken)
{
return _plc.ReadAsync(address, length, cancellationToken);
await Task.Delay(driverPropertys.FrameTime, cancellationToken);
return await _plc.ReadAsync(address, length, cancellationToken);
}
}
@@ -101,6 +103,9 @@ public class ModbusRtuOverTcpProperty : CollectDriverPropertyBase
[DeviceProperty("读写超时时间", "")]
public ushort TimeOut { get; set; } = 3000;
[DeviceProperty("帧前时间", "某些设备性能较弱,报文间需要间隔较长时间")]
public int FrameTime { get; set; } = 0;
[DeviceProperty("共享链路", "")]
public override bool IsShareChannel { get; set; } = false;
public override ShareChannelEnum ShareChannel => ShareChannelEnum.TcpClient;

View File

@@ -54,6 +54,7 @@ public class ModbusRtuOverUdp : CollectBase
public override async Task<OperResult> WriteValueAsync(CollectVariableRunTime deviceVariable, string value)
{
await Task.Delay(driverPropertys.FrameTime);
return await _plc.WriteAsync(deviceVariable.DataType, deviceVariable.VariableAddress, value);
}
@@ -75,6 +76,7 @@ public class ModbusRtuOverUdp : CollectBase
}
protected override async Task<OperResult<byte[]>> ReadAsync(string address, int length, CancellationToken cancellationToken)
{
await Task.Delay(driverPropertys.FrameTime, cancellationToken);
return await _plc.ReadAsync(address, length, cancellationToken);
}

View File

@@ -54,6 +54,7 @@ public class ModbusTcp : CollectBase
public override async Task<OperResult> WriteValueAsync(CollectVariableRunTime deviceVariable, string value)
{
await Task.Delay(driverPropertys.FrameTime);
return await _plc.WriteAsync(deviceVariable.DataType, deviceVariable.VariableAddress, value);
}
@@ -76,6 +77,7 @@ public class ModbusTcp : CollectBase
}
protected override async Task<OperResult<byte[]>> ReadAsync(string address, int length, CancellationToken cancellationToken)
{
await Task.Delay(driverPropertys.FrameTime, cancellationToken);
return await _plc.ReadAsync(address, length, cancellationToken);
}
}
@@ -94,6 +96,9 @@ public class ModbusTcpProperty : CollectDriverPropertyBase
[DeviceProperty("连接超时时间", "")]
public ushort ConnectTimeOut { get; set; } = 3000;
[DeviceProperty("帧前时间", "某些设备性能较弱,报文间需要间隔较长时间")]
public int FrameTime { get; set; } = 0;
[DeviceProperty("默认解析顺序", "")]
public DataFormat DataFormat { get; set; }

View File

@@ -55,6 +55,7 @@ public class ModbusUdp : CollectBase
public override async Task<OperResult> WriteValueAsync(CollectVariableRunTime deviceVariable, string value)
{
await Task.Delay(driverPropertys.FrameTime);
return await _plc.WriteAsync(deviceVariable.DataType, deviceVariable.VariableAddress, value);
}
@@ -76,6 +77,7 @@ public class ModbusUdp : CollectBase
}
protected override async Task<OperResult<byte[]>> ReadAsync(string address, int length, CancellationToken cancellationToken)
{
await Task.Delay(driverPropertys.FrameTime, cancellationToken);
return await _plc.ReadAsync(address, length, cancellationToken);
}
}