Innovenergy_trunk/csharp/Lib/Devices/AMPT/AmptCommunicationUnit.cs

90 lines
3.3 KiB
C#
Raw Normal View History

2023-05-06 13:41:20 +00:00
// using InnovEnergy.Lib.Protocols.Modbus.Channels;
// using InnovEnergy.Lib.Protocols.Modbus.Clients;
// using InnovEnergy.Lib.Protocols.Modbus.Conversions;
// using InnovEnergy.Lib.Protocols.Modbus.Slaves;
// using InnovEnergy.Lib.Units.Composite;
//
// namespace InnovEnergy.Lib.Devices.AMPT;
//
// public class AmptCommunicationUnit : ModbusDevice<CommunicationUnitRegisters>
// {
//
// private const UInt16 RegistersPerDevice = 16;
// private const UInt16 FirstDeviceOffset = 85;
//
//
// public AmptCommunicationUnit(String hostname, UInt16 port = 502, Byte slaveAddress = 1) : this
// (
// channel: new TcpChannel(hostname, port),
// slaveAddress
// )
// {}
//
//
// public AmptCommunicationUnit(Channel channel, Byte slaveAddress) : this
// (
// client: new ModbusTcpClient(channel, slaveAddress)
// )
// {}
//
// public AmptCommunicationUnit(ModbusClient client) : base(client)
// {
// }
//
//
// private AmptCommunicationUnitStatus TryReadStatus()
// {
// var r = new ModbusRegisters(116, Modbus.ReadHoldingRegisters(1, 116).ToArray()) ; // TODO
//
// var currentFactor = Pow(10.0m, r.GetInt16(73));
// var voltageFactor = Pow(10.0m, r.GetInt16(74));
// var energyFactor = Pow(10.0m, r.GetInt16(76) + 3); // +3 => converted from Wh to kWh
// var nbrOfDevices = r.GetUInt16(78);
//
// var devices = Enumerable
// .Range(0, nbrOfDevices)
// .Select(ReadDeviceStatus)
// .ToList();
//
// return new AmptCommunicationUnitStatus
// {
// Sid = r.GetUInt32(1),
// IdSunSpec = r.GetUInt16(3),
// Manufacturer = r.GetString(5, 16),
// Model = r.GetString(21, 16),
// Version = r.GetString(45, 8),
// SerialNumber = r.GetString(53, 16),
// DeviceAddress = r.GetInt16(69),
// IdVendor = r.GetUInt16(71),
// Devices = devices
// };
//
// AmptStatus ReadDeviceStatus(Int32 deviceNumber)
// {
// var baseAddress = (UInt16)(FirstDeviceOffset + deviceNumber * RegistersPerDevice); // base address
//
// return new AmptStatus
// {
// Dc = new DcBus
// {
// Voltage = r.GetUInt32((UInt16)(baseAddress + 6)) * voltageFactor,
// Current = r.GetUInt16((UInt16)(baseAddress + 5)) * currentFactor
// },
// Strings = new DcBus[]
// {
// new()
// {
// Voltage = r.GetUInt32((UInt16)(baseAddress + 8)) * voltageFactor,
// Current = r.GetUInt16((UInt16)(baseAddress + 14)) * currentFactor
// },
// new()
// {
// Voltage = r.GetUInt32((UInt16)(baseAddress + 9)) * voltageFactor,
// Current = r.GetUInt16((UInt16)(baseAddress + 15)) * currentFactor
// }
// },
// ProductionToday = r.GetUInt32((UInt16)(baseAddress + 12)) * energyFactor,
// };
// }
// }
// }