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

56 lines
1.7 KiB
C#
Raw Permalink Normal View History

2023-05-04 07:32:35 +00:00
using InnovEnergy.Lib.Protocols.Modbus.Channels;
using InnovEnergy.Lib.Protocols.Modbus.Clients;
2024-06-12 12:05:29 +00:00
namespace InnovEnergy.Lib.Protocols.Modbus.Slaves;
2023-05-04 07:32:35 +00:00
public static class ModbusSlave
{
public static Func<Byte, ModbusTcpClient> ModbusTcp(this Channel channel)
{
ModbusTcpClient SlaveId(Byte slaveId) => new ModbusTcpClient(channel, slaveId);
return SlaveId;
}
2024-06-07 08:36:15 +00:00
2023-05-04 07:32:35 +00:00
public static Func<Byte, ModbusRtuClient> ModbusRtu(this Channel channel)
{
ModbusRtuClient SlaveId(Byte slaveId) => new ModbusRtuClient(channel, slaveId);
return SlaveId;
}
2024-06-07 08:36:15 +00:00
2023-05-04 07:32:35 +00:00
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;
}
2024-06-07 08:36:15 +00:00
2023-05-04 07:32:35 +00:00
public static Func<Byte, ModbusRtuClient> ModbusRtu<R>(this Channel channel) where R : notnull, new()
{
ModbusRtuClient SlaveId(Byte slaveId) => new ModbusRtuClient(channel, slaveId);
return SlaveId;
}
2024-06-07 08:36:15 +00:00
2023-05-04 07:32:35 +00:00
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);
}
2024-06-07 08:36:15 +00:00
2023-05-04 07:32:35 +00:00
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);
}
2024-06-07 08:36:15 +00:00
2023-05-04 07:32:35 +00:00
public static ModbusDevice<T> Slave<T>(this ModbusClient modbusClient) where T : notnull, new()
{
return new ModbusDevice<T>(modbusClient);
}
2024-06-07 08:36:15 +00:00
}