Fixed dispose on servers
This commit is contained in:
@@ -14,7 +14,7 @@ using AMWD.Protocols.Modbus.Common.Protocols;
|
|||||||
namespace AMWD.Protocols.Modbus.Serial
|
namespace AMWD.Protocols.Modbus.Serial
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A basic implementation of a Modbus serial line server.
|
/// A basic implementation of a Modbus serial line RTU server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||||
public class ModbusRtuServer : IDisposable
|
public class ModbusRtuServer : IDisposable
|
||||||
@@ -208,6 +208,9 @@ namespace AMWD.Protocols.Modbus.Serial
|
|||||||
|
|
||||||
_deviceListLock.Dispose();
|
_deviceListLock.Dispose();
|
||||||
_devices.Clear();
|
_devices.Clear();
|
||||||
|
|
||||||
|
_serialPort.Dispose();
|
||||||
|
_stopCts?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Assertions()
|
private void Assertions()
|
||||||
|
|||||||
@@ -22,6 +22,19 @@ float voltage = registers.GetSingle();
|
|||||||
Console.WriteLine($"The voltage of device #{unitId} between L1 and N is: {voltage:N2}V");
|
Console.WriteLine($"The voltage of device #{unitId} between L1 and N is: {voltage:N2}V");
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you want to use the `ASCII` protocol instead, you can do this on initialization:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// [...]
|
||||||
|
|
||||||
|
using var client = new ModbusSerialClient(serialPort)
|
||||||
|
{
|
||||||
|
Protocol = new AsciiProtocol();
|
||||||
|
};
|
||||||
|
|
||||||
|
// [...]
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Sources
|
## Sources
|
||||||
|
|
||||||
|
|||||||
@@ -193,6 +193,8 @@ namespace AMWD.Protocols.Modbus.Tcp
|
|||||||
|
|
||||||
_clients.Clear();
|
_clients.Clear();
|
||||||
_devices.Clear();
|
_devices.Clear();
|
||||||
|
|
||||||
|
_stopCts?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Assertions()
|
private void Assertions()
|
||||||
|
|||||||
@@ -23,6 +23,18 @@ float voltage = registers.GetSingle();
|
|||||||
Console.WriteLine($"The voltage of device #{unitId} between L1 and N is: {voltage:N2}V");
|
Console.WriteLine($"The voltage of device #{unitId} between L1 and N is: {voltage:N2}V");
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you want to use the `RTU over TCP` protocol instead, you can do this on initialization:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// [...]
|
||||||
|
|
||||||
|
using var client = new ModbusTcpClient(host, port)
|
||||||
|
{
|
||||||
|
Protocol = new RtuOverTcpProtocol();
|
||||||
|
};
|
||||||
|
|
||||||
|
// [...]
|
||||||
|
```
|
||||||
|
|
||||||
## Sources
|
## Sources
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user