Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to create ModbusIpMaster from IStreamResource #87

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions NModbus/Interfaces/IModbusFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public interface IModbusFactory
/// <returns></returns>
IModbusMaster CreateMaster(TcpClient client);

/// <summary>
/// Create an IP master from IStreamResource
/// </summary>
/// <param name="streamResource">IStreamResource transport</param>
/// <returns></returns>
IModbusMaster CreateIpMaster(IStreamResource streamResource);

#endregion

#region Slave
Expand Down
11 changes: 7 additions & 4 deletions NModbus/ModbusFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,19 @@ public IModbusMaster CreateMaster(UdpClient client)
{
var adapter = new UdpClientAdapter(client);

var transport = new ModbusIpTransport(adapter, this, Logger);

return new ModbusIpMaster(transport);
return CreateIpMaster(adapter);
}

public IModbusMaster CreateMaster(TcpClient client)
{
var adapter = new TcpClientAdapter(client);

var transport = new ModbusIpTransport(adapter, this, Logger);
return CreateIpMaster(adapter);
}

public IModbusMaster CreateIpMaster(IStreamResource streamResource)
{
var transport = new ModbusIpTransport(streamResource, this, Logger);

return new ModbusIpMaster(transport);
}
Expand Down