|
|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
// See https://aka.ms/new-console-template for more information
|
|
|
|
|
|
|
|
|
|
using System.IO.Compression;
|
|
|
|
|
using System.Reactive.Linq;
|
|
|
|
|
using System.Reactive.Threading.Tasks;
|
|
|
|
|
@ -11,16 +10,21 @@ using InnovEnergy.App.KacoCommunication.DataTypes;
|
|
|
|
|
using InnovEnergy.App.KacoCommunication.Devices;
|
|
|
|
|
using InnovEnergy.App.KacoCommunication.ESS;
|
|
|
|
|
using InnovEnergy.App.KacoCommunication.MiddlewareClasses;
|
|
|
|
|
using InnovEnergy.App.KacoCommunication.System;
|
|
|
|
|
using InnovEnergy.App.KacoCommunication.SystemConfig;
|
|
|
|
|
using InnovEnergy.Lib.Devices.BatteryDeligreen;
|
|
|
|
|
using InnovEnergy.Lib.Devices.Kaco92L3;
|
|
|
|
|
using InnovEnergy.Lib.Devices.Kaco92L3.DataType;
|
|
|
|
|
using InnovEnergy.Lib.Devices.PLVario2Meter;
|
|
|
|
|
using InnovEnergy.Lib.Devices.Trumpf.SystemControl;
|
|
|
|
|
using InnovEnergy.Lib.Devices.Trumpf.SystemControl.DataTypes;
|
|
|
|
|
using InnovEnergy.Lib.Devices.Trumpf.TruConvertDc;
|
|
|
|
|
using InnovEnergy.Lib.Devices.Trumpf.TruConvertDc.Control;
|
|
|
|
|
using InnovEnergy.Lib.Protocols.Modbus.Channels;
|
|
|
|
|
using InnovEnergy.Lib.Units;
|
|
|
|
|
using InnovEnergy.Lib.Utils;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using DeviceState = InnovEnergy.App.KacoCommunication.Devices.DeviceState;
|
|
|
|
|
using Formatting = Newtonsoft.Json.Formatting;
|
|
|
|
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
|
|
|
|
|
|
|
|
|
@ -30,12 +34,11 @@ internal static class Program
|
|
|
|
|
{
|
|
|
|
|
private static readonly TimeSpan UpdateInterval = TimeSpan.FromSeconds(5);
|
|
|
|
|
private const UInt16 NbrOfFileToConcatenate = 15; // add this to config file
|
|
|
|
|
private static UInt16 _fileCounter = 0;
|
|
|
|
|
private static UInt16 _fileCounter = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static SodistoreAlarmState _prevSodiohomeAlarmState = SodistoreAlarmState.Green;
|
|
|
|
|
private static SodistoreAlarmState _sodiAlarmState = SodistoreAlarmState.Green;
|
|
|
|
|
private static SodistoreAlarmState _prevSodiohomeAlarmState = SodistoreAlarmState.Green;
|
|
|
|
|
private static SodistoreAlarmState _sodiAlarmState = SodistoreAlarmState.Green;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static readonly IReadOnlyList<Byte> BatteryNodes;
|
|
|
|
|
@ -43,13 +46,13 @@ internal static class Program
|
|
|
|
|
private static readonly Channel GridMeterChannel;
|
|
|
|
|
private static readonly Channel DcDcChannel;
|
|
|
|
|
|
|
|
|
|
private const String Port1Cabinet = "/dev/ttyUSB0"; // move to a config file
|
|
|
|
|
private const String Port2Cabinet = "/dev/ttyUSB1"; // move to a config file
|
|
|
|
|
private const String Port3Cabinet = "/dev/ttyUSB2"; // move to a config file
|
|
|
|
|
private const String Port1Cabinet = "/dev/ttyUSB0"; // move to a config file
|
|
|
|
|
private const String Port2Cabinet = "/dev/ttyUSB1"; // move to a config file
|
|
|
|
|
private const String Port3Cabinet = "/dev/ttyUSB2"; // move to a config file
|
|
|
|
|
|
|
|
|
|
private static readonly String SwVersionNumber = " V1.00." + DateTime.Today;
|
|
|
|
|
private const String VpnServerIp = "10.2.0.11";
|
|
|
|
|
public static Boolean _subscribedToQueue = false;
|
|
|
|
|
private static readonly String SwVersionNumber = " V1.00." + DateTime.Today;
|
|
|
|
|
private const String VpnServerIp = "10.2.0.11";
|
|
|
|
|
public static Boolean _subscribedToQueue = false;
|
|
|
|
|
public static Boolean _subscribeToQueueForTheFirstTime = false;
|
|
|
|
|
|
|
|
|
|
private static Int32 _failsCounter = 0; // move to a config file
|
|
|
|
|
@ -65,7 +68,7 @@ internal static class Program
|
|
|
|
|
? new NullChannel()
|
|
|
|
|
: new TcpChannel(device);
|
|
|
|
|
|
|
|
|
|
BatteryNodes = config
|
|
|
|
|
BatteryNodes = config
|
|
|
|
|
.Devices
|
|
|
|
|
.BatteryNodes
|
|
|
|
|
.Select(n => n.ConvertTo<Byte>())
|
|
|
|
|
@ -74,13 +77,11 @@ internal static class Program
|
|
|
|
|
KacoChannel = CreateChannel(d.KacoIp);
|
|
|
|
|
GridMeterChannel = CreateChannel(d.GridMeterIp);
|
|
|
|
|
DcDcChannel = CreateChannel(d.DcDcIp);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static async Task Main(String[] args)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
@ -89,7 +90,7 @@ internal static class Program
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
// e.LogError();
|
|
|
|
|
e.LogError();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// ReSharper disable once FunctionNeverReturns
|
|
|
|
|
@ -105,39 +106,49 @@ internal static class Program
|
|
|
|
|
var gridMeterDevice = new PlVarioMeterDevice(GridMeterChannel);
|
|
|
|
|
var dcDcDevices = new TruConvertDcDcDevices(DcDcChannel);
|
|
|
|
|
|
|
|
|
|
var firstCabinetBatteriesDevice = BatteryNodes.Select(n => new BatteryDeligreenDevice(Port1Cabinet, n)).ToList();
|
|
|
|
|
var secondCabinetBatteriesDevice = BatteryNodes.Select(n => new BatteryDeligreenDevice(Port2Cabinet, n)).ToList();
|
|
|
|
|
var thirdCabinetBatteriesDevice = BatteryNodes.Select(n => new BatteryDeligreenDevice(Port3Cabinet, n)).ToList();
|
|
|
|
|
var firstCabinetBatteriesDevice =
|
|
|
|
|
BatteryNodes.Select(n => new BatteryDeligreenDevice(Port1Cabinet, n)).ToList();
|
|
|
|
|
var secondCabinetBatteriesDevice =
|
|
|
|
|
BatteryNodes.Select(n => new BatteryDeligreenDevice(Port2Cabinet, n)).ToList();
|
|
|
|
|
var thirdCabinetBatteriesDevice =
|
|
|
|
|
BatteryNodes.Select(n => new BatteryDeligreenDevice(Port3Cabinet, n)).ToList();
|
|
|
|
|
|
|
|
|
|
var batteryDevices1 = new BatteryDeligreenDevices(firstCabinetBatteriesDevice);
|
|
|
|
|
var batteryDevices2 = new BatteryDeligreenDevices(secondCabinetBatteriesDevice);
|
|
|
|
|
var batteryDevices3 = new BatteryDeligreenDevices(thirdCabinetBatteriesDevice);
|
|
|
|
|
var batteryDevices1 = new BatteryDeligreenDevices(firstCabinetBatteriesDevice);
|
|
|
|
|
var batteryDevices2 = new BatteryDeligreenDevices(secondCabinetBatteriesDevice);
|
|
|
|
|
var batteryDevices3 = new BatteryDeligreenDevices(thirdCabinetBatteriesDevice);
|
|
|
|
|
|
|
|
|
|
StatusRecord? ReadStatus()
|
|
|
|
|
{
|
|
|
|
|
PlVarioMeterRecord? gridRecord = null;
|
|
|
|
|
var config = Config.Load();
|
|
|
|
|
var kacoRecord = kacoDevice.Read();
|
|
|
|
|
var gridrawRecord = gridMeterDevice.Read();
|
|
|
|
|
var dcDcRecord = dcDcDevices.Read();
|
|
|
|
|
var config = Config.Load();
|
|
|
|
|
var kacoRecord = kacoDevice.Read();
|
|
|
|
|
var gridrawRecord = gridMeterDevice.Read();
|
|
|
|
|
var dcDcRecord = dcDcDevices.Read();
|
|
|
|
|
|
|
|
|
|
if (gridrawRecord != null)
|
|
|
|
|
{
|
|
|
|
|
gridRecord = new PlVarioMeterRecord(gridrawRecord);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var batteryKabinet1 = batteryDevices1.Read();
|
|
|
|
|
var batteryKabinet2 = batteryDevices2.Read();
|
|
|
|
|
var batteryKabinet3 = batteryDevices3.Read();
|
|
|
|
|
var batteryKabinet1 = batteryDevices1.Read();
|
|
|
|
|
var batteryKabinet2 = batteryDevices2.Read();
|
|
|
|
|
var batteryKabinet3 = batteryDevices3.Read();
|
|
|
|
|
|
|
|
|
|
var listOfBatteriesRecord = new List<BatteryDeligreenRecords>();
|
|
|
|
|
if (batteryKabinet1 != null) listOfBatteriesRecord.Add(batteryKabinet1);
|
|
|
|
|
if (batteryKabinet2 != null) listOfBatteriesRecord.Add(batteryKabinet2);
|
|
|
|
|
if (batteryKabinet3 != null) listOfBatteriesRecord.Add(batteryKabinet3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new StatusRecord
|
|
|
|
|
{
|
|
|
|
|
InverterRecord = kacoRecord,
|
|
|
|
|
InverterRecord = kacoRecord,
|
|
|
|
|
GridMeterRecord = gridRecord,
|
|
|
|
|
DcDc = dcDcRecord,
|
|
|
|
|
BatteryKabinet1 = batteryKabinet1,
|
|
|
|
|
BatteryKabinet2 = batteryKabinet2,
|
|
|
|
|
BatteryKabinet3 = batteryKabinet3,
|
|
|
|
|
Config = config // load from disk every iteration, so config can be changed while running
|
|
|
|
|
DcDc = dcDcRecord,
|
|
|
|
|
ListOfBatteriesRecord = listOfBatteriesRecord,
|
|
|
|
|
StateMachine = StateMachine.Default,
|
|
|
|
|
|
|
|
|
|
Config = config // load from disk every iteration, so config can be changed while running
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -169,35 +180,25 @@ internal static class Program
|
|
|
|
|
var statusrecord = ReadStatus();
|
|
|
|
|
statusrecord?.CreateSimpleTopologyTextBlock().WriteLine();
|
|
|
|
|
|
|
|
|
|
statusrecord?.StateMachine.State.WriteLine(" state");
|
|
|
|
|
statusrecord?.StateMachine.Message.WriteLine(" Message");
|
|
|
|
|
|
|
|
|
|
// statusrecord?.DcDc?.Dc.Battery.Power .WriteLine(" Power");
|
|
|
|
|
// statusrecord?.DcDc?.Dc.Battery.Voltage .WriteLine(" Voltage");
|
|
|
|
|
// statusrecord?.DcDc?.Dc.Battery.Current .WriteLine(" Current");
|
|
|
|
|
// statusrecord?.DcDc?.Dc.Link.Voltage .WriteLine(" Dc link Voltage");
|
|
|
|
|
statusrecord?.InverterRecord?.BatteryLimitsEnable.WriteLine(" BatteryLimitsEnable");
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(" **************** DcDc **********************");
|
|
|
|
|
statusrecord?.DcDc?.Dc.Battery.Power .WriteLine(" DC Battery Power");
|
|
|
|
|
statusrecord?.DcDc?.Dc.Battery.Voltage .WriteLine("DC Battery Voltage");
|
|
|
|
|
statusrecord?.DcDc?.Dc.Battery.Current .WriteLine("DC Battery Current");
|
|
|
|
|
statusrecord?.DcDc?.Dc.Link.Voltage .WriteLine(" Dc link Voltage");
|
|
|
|
|
|
|
|
|
|
statusrecord?.GridMeterRecord?.Frequency .WriteLine(" Frequency");
|
|
|
|
|
statusrecord?.GridMeterRecord?.VoltageU1 .WriteLine(" VoltageU1");
|
|
|
|
|
statusrecord?.GridMeterRecord?.VoltageU2 .WriteLine(" VoltageU2");
|
|
|
|
|
statusrecord?.GridMeterRecord?.VoltageU3 .WriteLine(" VoltageU3");
|
|
|
|
|
|
|
|
|
|
statusrecord?.GridMeterRecord?.CurrentI1 .WriteLine(" CurrentI1");
|
|
|
|
|
statusrecord?.GridMeterRecord?.CurrentI2 .WriteLine(" CurrentI2");
|
|
|
|
|
statusrecord?.GridMeterRecord?.CurrentI3 .WriteLine(" CurrentI3");
|
|
|
|
|
|
|
|
|
|
statusrecord?.GridMeterRecord?.ActivePowerL1 .WriteLine(" ActivePowerL1");
|
|
|
|
|
statusrecord?.GridMeterRecord?.ActivePowerL2 .WriteLine(" ActivePowerL2");
|
|
|
|
|
statusrecord?.GridMeterRecord?.ActivePowerL3 .WriteLine(" ActivePowerL3");
|
|
|
|
|
statusrecord?.GridMeterRecord?.ActivePowerTotal .WriteLine(" ActivePowerTotal");
|
|
|
|
|
Console.WriteLine(" ********************************* Kaco Inverter *********************************");
|
|
|
|
|
|
|
|
|
|
statusrecord?.InverterRecord?.ActivePowerW.WriteLine(" Inverter Power");
|
|
|
|
|
statusrecord?.InverterRecord?.CurrentState.WriteLine(" CurrentState");
|
|
|
|
|
statusrecord?.InverterRecord?.RequestedState.WriteLine(" RequestedState");
|
|
|
|
|
statusrecord?.InverterRecord?.PcuError.WriteLine(" PcuError");
|
|
|
|
|
statusrecord?.InverterRecord?.PcuState.WriteLine(" PcuState");
|
|
|
|
|
|
|
|
|
|
statusrecord?.InverterRecord?.BattCharId.WriteLine(" _battCharId");
|
|
|
|
|
statusrecord?.InverterRecord?.BattCharLength.WriteLine(" _battCharLength");
|
|
|
|
|
|
|
|
|
|
statusrecord?.InverterRecord?.MinDischargeVoltage.WriteLine(" MinDischargeVoltage");
|
|
|
|
|
statusrecord?.InverterRecord?.MaxDischargeCurrent.WriteLine(" MaxDischargeCurrent");
|
|
|
|
|
statusrecord?.InverterRecord?.DischargeCutoffCurrent.WriteLine(" DischargeCutoffCurrent");
|
|
|
|
|
@ -205,17 +206,31 @@ internal static class Program
|
|
|
|
|
statusrecord?.InverterRecord?.MaxChargeVoltage.WriteLine(" MaxChargeVoltage");
|
|
|
|
|
statusrecord?.InverterRecord?.MaxChargeCurrent.WriteLine(" MaxChargeCurrent");
|
|
|
|
|
statusrecord?.InverterRecord?.ChargeCutoffCurrent.WriteLine(" ChargeCutoffCurrent");
|
|
|
|
|
statusrecord?.InverterRecord?.ActivePowerSetPercent.WriteLine( "ActivePowerSetPercent");
|
|
|
|
|
|
|
|
|
|
statusrecord?.InverterRecord?.ActivePowerSetPercent.WriteLine(" ActivePowerSetPercent");
|
|
|
|
|
statusrecord?.InverterRecord?.ReactivePowerSetPercent.WriteLine(" ReactivePowerSetPercent");
|
|
|
|
|
statusrecord?.InverterRecord?.WatchdogSeconds.WriteLine(" WatchdogSeconds");
|
|
|
|
|
statusrecord?.ControlSystemState();
|
|
|
|
|
var i = 0;
|
|
|
|
|
foreach (var d in statusrecord.DcDc.Devices)
|
|
|
|
|
{
|
|
|
|
|
i++;
|
|
|
|
|
Console.WriteLine("before DcDc is " + i + d.Control.PowerStageEnable);
|
|
|
|
|
d.Control.ResetAlarmsAndWarnings = true;
|
|
|
|
|
d.Control.PowerStageEnable = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
statusrecord?.DcDc?.SystemControl.ApplyDcDcDefaultSettings();
|
|
|
|
|
InitializeKacoStartup(statusrecord);
|
|
|
|
|
foreach (var d in statusrecord.DcDc.Devices)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("After DcDc is " + d.Control.PowerStageEnable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine( " ************************************ We are writing ************************************");
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(" ************************************ We are writing ************************************");
|
|
|
|
|
|
|
|
|
|
statusrecord?.Config.Save(); // save the config file
|
|
|
|
|
if (statusrecord?.InverterRecord != null) kacoDevice.Write(statusrecord.InverterRecord);
|
|
|
|
|
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff"));
|
|
|
|
|
|
|
|
|
|
return statusrecord;
|
|
|
|
|
}
|
|
|
|
|
@ -230,8 +245,7 @@ internal static class Program
|
|
|
|
|
|
|
|
|
|
private static async Task SavingLocalCsvFile(Int64 timestamp, String csv)
|
|
|
|
|
{
|
|
|
|
|
const String directoryPath = "/home/inesco/salimax/csvFile";
|
|
|
|
|
|
|
|
|
|
var directoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "csvFiles");
|
|
|
|
|
// Ensure directory exists
|
|
|
|
|
if (!Directory.Exists(directoryPath))
|
|
|
|
|
{
|
|
|
|
|
@ -300,10 +314,10 @@ internal static class Program
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(line)) continue;
|
|
|
|
|
|
|
|
|
|
var parts = line.Split(';');
|
|
|
|
|
var keyPath = parts[0];
|
|
|
|
|
var value = parts[1];
|
|
|
|
|
var unit = parts.Length > 2 ? parts[2].Trim() : "";
|
|
|
|
|
var parts = line.Split(';');
|
|
|
|
|
var keyPath = parts[0];
|
|
|
|
|
var value = parts[1];
|
|
|
|
|
var unit = parts.Length > 2 ? parts[2].Trim() : "";
|
|
|
|
|
InsertIntoJson(jsonData, keyPath.Split('/'), value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -368,6 +382,7 @@ internal static class Program
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_fileCounter++;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
@ -381,9 +396,9 @@ internal static class Program
|
|
|
|
|
var returnedStatus = new StatusMessage
|
|
|
|
|
{
|
|
|
|
|
InstallationId = installationId,
|
|
|
|
|
Product = 3,
|
|
|
|
|
Status = _sodiAlarmState,
|
|
|
|
|
Type = MessageType.Heartbit,
|
|
|
|
|
Product = 3,
|
|
|
|
|
Status = _sodiAlarmState,
|
|
|
|
|
Type = MessageType.Heartbit,
|
|
|
|
|
};
|
|
|
|
|
if (s3Bucket != null)
|
|
|
|
|
RabbitMqManager.InformMiddleware(returnedStatus);
|
|
|
|
|
@ -416,7 +431,8 @@ internal static class Program
|
|
|
|
|
//Create a zip directory and put the compressed file inside
|
|
|
|
|
using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
|
|
|
|
|
{
|
|
|
|
|
var entry = archive.CreateEntry("data.json", CompressionLevel.SmallestSize); // Add JSON data to the ZIP archive
|
|
|
|
|
var entry = archive.CreateEntry("data.json",
|
|
|
|
|
CompressionLevel.SmallestSize); // Add JSON data to the ZIP archive
|
|
|
|
|
using (var entryStream = entry.Open())
|
|
|
|
|
using (var writer = new StreamWriter(entryStream))
|
|
|
|
|
{
|
|
|
|
|
@ -474,14 +490,16 @@ internal static class Program
|
|
|
|
|
var modbusData = new Dictionary<String, UInt16>();
|
|
|
|
|
|
|
|
|
|
// SYSTEM DATA
|
|
|
|
|
var result1 = ConvertToModbusRegisters((status.Config.MinSoc * 10), "UInt16", 30001); // this to be updated to modbusTCP version
|
|
|
|
|
var result1 =
|
|
|
|
|
ConvertToModbusRegisters((status.Config.MinSoc * 10), "UInt16",
|
|
|
|
|
30001); // this to be updated to modbusTCP version
|
|
|
|
|
var result2 = ConvertToModbusRegisters(status.InverterRecord!.PcuError, "UInt32", 30002);
|
|
|
|
|
|
|
|
|
|
// Merge all results into one dictionary
|
|
|
|
|
|
|
|
|
|
var allResults = new[]
|
|
|
|
|
{
|
|
|
|
|
result1,result2
|
|
|
|
|
result1, result2
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
foreach (var result in allResults)
|
|
|
|
|
@ -491,14 +509,15 @@ internal static class Program
|
|
|
|
|
modbusData[entry.Key] = entry.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Write to JSON
|
|
|
|
|
var json = JsonSerializer.Serialize(modbusData, new JsonSerializerOptions { WriteIndented = true });
|
|
|
|
|
await File.WriteAllTextAsync("/home/inesco/SodiStoreHome/ModbusTCP/modbus_tcp_data.json", json);
|
|
|
|
|
|
|
|
|
|
//Console.WriteLine("JSON file written successfully.");
|
|
|
|
|
//Console.WriteLine(json);
|
|
|
|
|
var stopTime = DateTime.Now;
|
|
|
|
|
Console.WriteLine(stopTime.ToString("HH:mm:ss.fff" )+ " Finish the loop");
|
|
|
|
|
var stopTime = DateTime.Now;
|
|
|
|
|
Console.WriteLine(stopTime.ToString("HH:mm:ss.fff") + " Finish the loop");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -515,13 +534,13 @@ internal static class Program
|
|
|
|
|
|
|
|
|
|
case "Int16":
|
|
|
|
|
var int16Val = Convert.ToInt16(value);
|
|
|
|
|
registers[startingAddress.ToString()] = (UInt16)int16Val; // reinterpret signed as ushort
|
|
|
|
|
registers[startingAddress.ToString()] = (UInt16)int16Val; // reinterpret signed as ushort
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "UInt32":
|
|
|
|
|
var uint32Val = Convert.ToUInt32(value);
|
|
|
|
|
registers[startingAddress.ToString()] = (UInt16)(uint32Val & 0xFFFF); // Low word
|
|
|
|
|
registers[(startingAddress + 1).ToString()] = (UInt16)(uint32Val >> 16); // High word
|
|
|
|
|
registers[startingAddress.ToString()] = (UInt16)(uint32Val & 0xFFFF); // Low word
|
|
|
|
|
registers[(startingAddress + 1).ToString()] = (UInt16)(uint32Val >> 16); // High word
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "Int32":
|
|
|
|
|
@ -534,9 +553,15 @@ internal static class Program
|
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentException("Unsupported output type: " + outputType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return registers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void ForAll<T>(this IEnumerable<T> ts, Action<T> action)
|
|
|
|
|
{
|
|
|
|
|
foreach (var t in ts)
|
|
|
|
|
action(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void InitializeKacoStartup(StatusRecord? statusRecord)
|
|
|
|
|
{
|
|
|
|
|
@ -544,12 +569,23 @@ internal static class Program
|
|
|
|
|
// 1. Apply DC – This part is physical and cannot be done in software.
|
|
|
|
|
// We assume DC power is already present.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("1. Apply DC");
|
|
|
|
|
//
|
|
|
|
|
// 2. Send valid battery limits (Model 64202)
|
|
|
|
|
statusRecord?.DcDc?.Devices
|
|
|
|
|
.Select(d => d.Control)
|
|
|
|
|
.ForAll(c => c.PowerStageEnable = true);
|
|
|
|
|
|
|
|
|
|
statusRecord?.DcDc?.Devices
|
|
|
|
|
.Select(d => d.Control )
|
|
|
|
|
.ForAll(c => c.ControlMode = DcControlMode.VoltageDroop);
|
|
|
|
|
//
|
|
|
|
|
// // 2. Send valid battery limits (Model 64202)
|
|
|
|
|
// All values temporarily set to "1" as requested.
|
|
|
|
|
// You will replace them later with real values.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("2. Send real value");
|
|
|
|
|
|
|
|
|
|
if (statusRecord?.InverterRecord != null)
|
|
|
|
|
{
|
|
|
|
|
statusRecord.InverterRecord.MinDischargeVoltage = 700f; // 64202.DisMinV
|
|
|
|
|
@ -564,7 +600,8 @@ internal static class Program
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 3. Enable limits (EnLimit)
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("3. Enable limits ");
|
|
|
|
|
statusRecord.InverterRecord.BatteryLimitsEnable = EnableDisableEnum.Enabled;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
@ -579,6 +616,9 @@ internal static class Program
|
|
|
|
|
// - Then after grid/DC conditions: CurrentState == 1 (OFF) or 11 (GRID_CONNECTED)
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("3. Read current state");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var state = statusRecord.InverterRecord.CurrentState;
|
|
|
|
|
|
|
|
|
|
Console.WriteLine($"KACO 64201.CurrentState = {state}");
|
|
|
|
|
@ -586,6 +626,7 @@ internal static class Program
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case CurrentState.Standby:
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Device is in STANDBY (8) — battery limits accepted.");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
@ -601,9 +642,26 @@ internal static class Program
|
|
|
|
|
Console.WriteLine("Device in unexpected state: " + state);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
//Thread.Sleep(2000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void ApplyDcDcDefaultSettings(this SystemControlRegisters? sc)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (sc is null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
sc.SystemConfig = Lib.Devices.Trumpf.SystemControl.DataTypes.SystemConfig.DcDcOnly;
|
|
|
|
|
sc.CommunicationTimeout = TimeSpan.FromSeconds(20);
|
|
|
|
|
|
|
|
|
|
sc.PowerSetPointActivation = PowerSetPointActivation.Immediate;
|
|
|
|
|
sc.UseSlaveIdForAddressing = true;
|
|
|
|
|
sc.SlaveErrorHandling = SlaveErrorHandling.Relaxed;
|
|
|
|
|
sc.SubSlaveErrorHandling = SubSlaveErrorHandling.Off;
|
|
|
|
|
sc.TargetSlave = 0;
|
|
|
|
|
sc.ResetAlarmsAndWarnings = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void InsertIntoJson(Dictionary<String, Object> jsonDict, String[] keys, String value)
|
|
|
|
|
{
|
|
|
|
|
var currentDict = jsonDict;
|
|
|
|
|
@ -617,11 +675,10 @@ internal static class Program
|
|
|
|
|
|
|
|
|
|
if (i == keys.Length - 1) // Last key, store the value
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (!value.Contains(",") && double.TryParse(value, out Double doubleValue)) // Try to parse value as a number
|
|
|
|
|
if (!value.Contains(",") &&
|
|
|
|
|
double.TryParse(value, out Double doubleValue)) // Try to parse value as a number
|
|
|
|
|
{
|
|
|
|
|
currentDict[key] = Math.Round(doubleValue, 2); // Round to 2 decimal places
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|