diff --git a/csharp/App/DeligreenBatteryCommunication/DeligreenBatteryCommunication.csproj b/csharp/App/DeligreenBatteryCommunication/DeligreenBatteryCommunication.csproj index 0017ee879..176ad9f64 100644 --- a/csharp/App/DeligreenBatteryCommunication/DeligreenBatteryCommunication.csproj +++ b/csharp/App/DeligreenBatteryCommunication/DeligreenBatteryCommunication.csproj @@ -9,6 +9,8 @@ + + diff --git a/csharp/Lib/Devices/BatteryDeligreen/BatteryDeligreenAlarmRecord.cs b/csharp/Lib/Devices/BatteryDeligreen/BatteryDeligreenAlarmRecord.cs index 7b860cfa1..e69d691af 100644 --- a/csharp/Lib/Devices/BatteryDeligreen/BatteryDeligreenAlarmRecord.cs +++ b/csharp/Lib/Devices/BatteryDeligreen/BatteryDeligreenAlarmRecord.cs @@ -1,26 +1,23 @@ namespace InnovEnergy.Lib.Devices.BatteryDeligreen; public class BatteryDeligreenAlarmRecord -{/* - public String FwVersion { get; set; } +{ + + public List CellAlarmList { get; set; } + public List CellTemperatureAlarm { get; set; } + public String EnviTempAlarm { get; set; } + public String PowerTempAlarm { get; set; } + public String CurrentAlarm { get; set; } + public String TotalVoltageAlarm { get; set; } - public TemperaturesList TemperaturesList { get; set; } - // public Dc_ Dc { get; set; } - public BatteryDeligreenAlarmRecord(Voltage busVoltage, Current busCurrent ,String fwVersion, Percent soc, UInt16 numberOfCycles, Double batteryCapacity, Double ratedCapacity, Voltage totalBatteryVoltage, Percent soh, Double residualCapacity, List cellVoltage, TemperaturesList temperaturesList) + public BatteryDeligreenAlarmRecord( List cellAlarmList, List cellTemperatureAlarm, String enviTempAlarm1, String powerTempAlarm1, String currentAlarm1, String totalVoltageAlarm1) { - BusVoltage = busVoltage; - BusCurrent = busCurrent; - FwVersion = fwVersion; - TotalBatteryVoltage = totalBatteryVoltage; - ResidualCapacity = residualCapacity; - BatteryCapacity = batteryCapacity; - Soc = soc; - RatedCapacity = ratedCapacity; - NumberOfCycles = numberOfCycles; - Soh = soh; - CellVoltage = cellVoltage; - TemperaturesList = temperaturesList; - Power = busVoltage * busCurrent; - }*/ + CellAlarmList = cellAlarmList; + CellTemperatureAlarm = cellTemperatureAlarm; + EnviTempAlarm = enviTempAlarm1; + PowerTempAlarm = powerTempAlarm1; + CurrentAlarm = currentAlarm1; + TotalVoltageAlarm = totalVoltageAlarm1; + } } \ No newline at end of file diff --git a/csharp/Lib/Devices/BatteryDeligreen/BatteryDeligreenDataRecord.cs b/csharp/Lib/Devices/BatteryDeligreen/BatteryDeligreenDataRecord.cs index 590214524..0cc90a6a8 100644 --- a/csharp/Lib/Devices/BatteryDeligreen/BatteryDeligreenDataRecord.cs +++ b/csharp/Lib/Devices/BatteryDeligreen/BatteryDeligreenDataRecord.cs @@ -4,14 +4,10 @@ using static InnovEnergy.Lib.Devices.BatteryDeligreen.Temperatures; namespace InnovEnergy.Lib.Devices.BatteryDeligreen; using InnovEnergy.Lib.Units; -using Strings = IReadOnlyList; public class BatteryDeligreenDataRecord { - // public Strings Warnings => ParseWarnings().OrderBy(w => w).ToList(); - // public Strings Alarms => ParseAlarms() .OrderBy(w => w).ToList(); - public String FwVersion { get; set; } public Voltage BusVoltage { get; set; } public Current BusCurrent { get; set; } @@ -25,7 +21,6 @@ public class BatteryDeligreenDataRecord public Percent Soh { get; set; } public List CellVoltage { get; set; } public TemperaturesList TemperaturesList { get; set; } - // public Dc_ Dc { get; set; } public BatteryDeligreenDataRecord(Voltage busVoltage, Current busCurrent ,String fwVersion, Percent soc, UInt16 numberOfCycles, Double batteryCapacity, Double ratedCapacity, Voltage totalBatteryVoltage, Percent soh, Double residualCapacity, List cellVoltage, TemperaturesList temperaturesList) { @@ -43,12 +38,4 @@ public class BatteryDeligreenDataRecord TemperaturesList = temperaturesList; Power = busVoltage * busCurrent; } - - // public struct Dc_ - // { - // public Voltage Voltage => BusVoltage; - // public Current Current => BusCurrent; - // public ActivePower Power => BusVoltage * BusCurrent; - - // } } \ No newline at end of file diff --git a/csharp/Lib/Devices/BatteryDeligreen/BatteryDeligreenDevice.cs b/csharp/Lib/Devices/BatteryDeligreen/BatteryDeligreenDevice.cs index 5bd7118ff..287f34244 100644 --- a/csharp/Lib/Devices/BatteryDeligreen/BatteryDeligreenDevice.cs +++ b/csharp/Lib/Devices/BatteryDeligreen/BatteryDeligreenDevice.cs @@ -144,7 +144,7 @@ public class BatteryDeligreenDevice // Read telemetry data from the connected device private async Task ReadTelemetryData(UInt16 batteryId) { - String frameToSend = batteryId switch + var frameToSend = batteryId switch { 0 => "7E3230303034363432453030323030464433370D", 1 => "7E3230303134363432453030323031464433350D", @@ -199,7 +199,7 @@ public class BatteryDeligreenDevice return Task.FromResult(responseBuffer.ToArray()); } - private async Task ReadTelecomandData(UInt16 batteryId) + private async Task ReadTelecomandData(UInt16 batteryId) { var frameToSend = batteryId switch { @@ -219,15 +219,14 @@ public class BatteryDeligreenDevice { // Write the frame to the channel (send it to the device) Write(frameToSend); - // await Task.Delay(delayFrame2); + // Read the response from the channel (assuming max response size) var responseBytes = await ReadFullResponse(116, 64); // Assuming Read can be executed asynchronously + // Convert the byte array to a hexadecimal string var responseHex = BytesToHexString(responseBytes); - var response = new TelecommandFrameParser().ParsingTelecommandFrame(responseHex); - - return new BatteryDeligreenAlarmRecord(); + return new TelecommandFrameParser().ParsingTelecommandFrame(responseHex); } catch (Exception ex) { @@ -238,11 +237,11 @@ public class BatteryDeligreenDevice public async Task Reads() { - var dataRecord = ReadTelemetryData(SlaveId).Result; + var dataRecord = ReadTelemetryData(SlaveId).Result; var alarmRecord = ReadTelecomandData(SlaveId).Result; await Task.Delay(5); // looks like this is need. A time delay needed between each frame to send to each battery - - return dataRecord != null ? new BatteryDeligreenRecord(dataRecord, alarmRecord) : null; + + return (dataRecord != null && alarmRecord != null ) ? new BatteryDeligreenRecord(dataRecord, alarmRecord) : null; // to check how this work if one of the record is null } private static String ConstructFrameToSend(UInt16 batteryId, String functionCode) @@ -252,9 +251,8 @@ public class BatteryDeligreenDevice var batteryIdHex = string.Concat(batteryIdAscii.Select(c => ((Int32)c).ToString("X2"))); Console.WriteLine("Battery ID " + batteryIdHex); - var frameToSend = - FrameStart + Version + batteryIdHex + DeviceCode + functionCode + - "453030323030464433370D"; // Example custom frame with dynamic batteryId + var frameToSend = FrameStart + Version + batteryIdHex + DeviceCode + functionCode + + "453030323030464433370D"; // Example custom frame with dynamic batteryId Console.WriteLine(frameToSend); return frameToSend; }