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; namespace InnovEnergy.Lib.Devices.WITGrowatt4_15K; public class WITGrowatDevice : ModbusDevice { private const Parity Parity = 0; //none private const Int32 StopBits = 1; private const Int32 BaudRate = 9600; private const Int32 DataBits = 8; public Byte SlaveId { get; } public WITGrowatDevice(String tty, Byte slaveId, SshHost host) : this ( channel: new RemoteSerialChannel(host, tty, BaudRate, Parity, DataBits, StopBits), slaveId ) {} public WITGrowatDevice(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 WITGrowatDevice(Channel channel, Byte slaveId) : this ( client: new ModbusRtuClient(channel, slaveId) ) {} public WITGrowatDevice(ModbusClient client): base(client) { SlaveId = client.SlaveId; } }