Innovenergy_trunk/csharp/Lib/Protocols/Modbus/Slaves/ModbusSlave.cs

110 lines
3.5 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);
}
}*/
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((TcpChannel)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((TcpChannel)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((TcpChannel)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);
}
}
}