Innovenergy_trunk/csharp/Lib/Devices/Battery48TL/Battery48TLDevice.cs

48 lines
1.3 KiB
C#

using System.IO.Ports;
using InnovEnergy.Lib.Protocols.Modbus.Channels;
using InnovEnergy.Lib.Protocols.Modbus.Clients;
using InnovEnergy.Lib.Protocols.Modbus.Slaves;
using InnovEnergy.Lib.Utils;
using static System.IO.Ports.Parity;
namespace InnovEnergy.Lib.Devices.Battery48TL;
public class Battery48TlDevice : ModbusDevice<Battery48TlRecord>
{
public const Parity Parity = Odd;
public const Int32 StopBits = 1;
public const Int32 BaudRate = 115200;
public const Int32 DataBits = 8;
public Byte SlaveId { get; }
public Battery48TlDevice(String tty, Byte slaveId, SshHost host) : this
(
channel: new RemoteSerialChannel(host, tty, BaudRate, Parity, DataBits, StopBits),
slaveId
)
{}
public Battery48TlDevice(String tty, Byte slaveId, String? host = null) : this
(
channel: host switch
{
null => new SerialPortChannel ( tty, BaudRate, Parity, DataBits, StopBits),
_ => new RemoteSerialChannel(host, tty, BaudRate, Parity, DataBits, StopBits)
},
slaveId
)
{}
public Battery48TlDevice(Channel channel, Byte slaveId) : this
(
client: new ModbusRtuClient(channel, slaveId)
)
{}
public Battery48TlDevice(ModbusClient client): base(client)
{
SlaveId = client.SlaveId;
}
}