Innovenergy_trunk/csharp/Lib/Devices/Battery250UP/Battery250UpDevice.cs

49 lines
1.3 KiB
C#
Raw Normal View History

2024-06-19 15:15:15 +00:00
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.Battery250Up;
public class Battery250UpDevice : ModbusDevice<Battery250UpRecord>
{
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 Battery250UpDevice(String tty, Byte slaveId, SshHost host) : this
(
channel: new RemoteSerialChannel(host, tty, BaudRate, Parity, DataBits, StopBits),
slaveId
)
{}
public Battery250UpDevice(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 Battery250UpDevice(Channel channel, Byte slaveId) : this
(
client: new ModbusRtuClient(channel, slaveId)
)
{}
public Battery250UpDevice(ModbusClient client): base(client)
{
SlaveId = client.SlaveId;
}
}