55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using InnovEnergy.Lib.Protocols.Modbus.Channels;
|
|
using InnovEnergy.Lib.Protocols.Modbus.Clients;
|
|
|
|
namespace InnovEnergy.Lib.Protocols.Modbus.Slaves;
|
|
|
|
public static class ModbusSlave
|
|
{
|
|
|
|
public static Func<Byte, ModbusTcpClient> ModbusTcp(this Channel channel)
|
|
{
|
|
ModbusTcpClient SlaveId(Byte slaveId) => new ModbusTcpClient(channel, slaveId);
|
|
return SlaveId;
|
|
}
|
|
|
|
public static Func<Byte, ModbusRtuClient> ModbusRtu(this Channel channel)
|
|
{
|
|
ModbusRtuClient SlaveId(Byte slaveId) => new ModbusRtuClient(channel, slaveId);
|
|
return SlaveId;
|
|
}
|
|
|
|
|
|
public static Func<Byte, ModbusTcpClient> ModbusTcp<R>(this Channel channel) where R : notnull, new()
|
|
{
|
|
ModbusTcpClient SlaveId(Byte slaveId)
|
|
{
|
|
return new ModbusTcpClient(channel, slaveId);
|
|
}
|
|
|
|
return SlaveId;
|
|
}
|
|
|
|
public static Func<Byte, ModbusRtuClient> ModbusRtu<R>(this Channel channel) where R : notnull, new()
|
|
{
|
|
ModbusRtuClient SlaveId(Byte slaveId) => new ModbusRtuClient(channel, slaveId);
|
|
return SlaveId;
|
|
}
|
|
|
|
public static ModbusDevice<T> TcpSlave<T>(this Channel channel, Byte slaveId) where T : notnull, new()
|
|
{
|
|
var client = new ModbusTcpClient(channel, slaveId);
|
|
return new ModbusDevice<T>(client);
|
|
}
|
|
|
|
public static ModbusDevice<T> RtuSlave<T>(this Channel channel, Byte slaveId) where T : notnull, new()
|
|
{
|
|
var client = new ModbusRtuClient(channel, slaveId);
|
|
return new ModbusDevice<T>(client);
|
|
}
|
|
|
|
public static ModbusDevice<T> Slave<T>(this ModbusClient modbusClient) where T : notnull, new()
|
|
{
|
|
return new ModbusDevice<T>(modbusClient);
|
|
}
|
|
|
|
} |