Innovenergy_trunk/csharp/Sinexcel 12K TL/SinexcelDevice.cs

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