Update Battery Deligreen records

This commit is contained in:
atef 2025-03-14 13:19:41 +01:00
parent 1077111b77
commit 355c96da55
4 changed files with 28 additions and 44 deletions

View File

@ -9,6 +9,8 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="../../Lib/Devices/BatteryDeligreen/BatteryDeligreen.csproj" /> <ProjectReference Include="../../Lib/Devices/BatteryDeligreen/BatteryDeligreen.csproj" />
<ProjectReference Include="..\..\Lib\Devices\Amax5070\Amax5070.csproj" />
<ProjectReference Include="..\..\Lib\Protocols\Modbus\Modbus.csproj" />
<ProjectReference Include="..\..\Lib\Units\Units.csproj" /> <ProjectReference Include="..\..\Lib\Units\Units.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -1,26 +1,23 @@
namespace InnovEnergy.Lib.Devices.BatteryDeligreen; namespace InnovEnergy.Lib.Devices.BatteryDeligreen;
public class BatteryDeligreenAlarmRecord public class BatteryDeligreenAlarmRecord
{/*
public String FwVersion { 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<Double> cellVoltage, TemperaturesList temperaturesList)
{ {
BusVoltage = busVoltage;
BusCurrent = busCurrent; public List<String> CellAlarmList { get; set; }
FwVersion = fwVersion; public List<String> CellTemperatureAlarm { get; set; }
TotalBatteryVoltage = totalBatteryVoltage; public String EnviTempAlarm { get; set; }
ResidualCapacity = residualCapacity; public String PowerTempAlarm { get; set; }
BatteryCapacity = batteryCapacity; public String CurrentAlarm { get; set; }
Soc = soc; public String TotalVoltageAlarm { get; set; }
RatedCapacity = ratedCapacity;
NumberOfCycles = numberOfCycles;
Soh = soh; public BatteryDeligreenAlarmRecord( List<String> cellAlarmList, List<String> cellTemperatureAlarm, String enviTempAlarm1, String powerTempAlarm1, String currentAlarm1, String totalVoltageAlarm1)
CellVoltage = cellVoltage; {
TemperaturesList = temperaturesList; CellAlarmList = cellAlarmList;
Power = busVoltage * busCurrent; CellTemperatureAlarm = cellTemperatureAlarm;
}*/ EnviTempAlarm = enviTempAlarm1;
PowerTempAlarm = powerTempAlarm1;
CurrentAlarm = currentAlarm1;
TotalVoltageAlarm = totalVoltageAlarm1;
}
} }

View File

@ -4,14 +4,10 @@ using static InnovEnergy.Lib.Devices.BatteryDeligreen.Temperatures;
namespace InnovEnergy.Lib.Devices.BatteryDeligreen; namespace InnovEnergy.Lib.Devices.BatteryDeligreen;
using InnovEnergy.Lib.Units; using InnovEnergy.Lib.Units;
using Strings = IReadOnlyList<String>;
public class BatteryDeligreenDataRecord 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 String FwVersion { get; set; }
public Voltage BusVoltage { get; set; } public Voltage BusVoltage { get; set; }
public Current BusCurrent { get; set; } public Current BusCurrent { get; set; }
@ -25,7 +21,6 @@ public class BatteryDeligreenDataRecord
public Percent Soh { get; set; } public Percent Soh { get; set; }
public List<Double> CellVoltage { get; set; } public List<Double> CellVoltage { get; set; }
public TemperaturesList TemperaturesList { 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<Double> cellVoltage, TemperaturesList temperaturesList) public BatteryDeligreenDataRecord(Voltage busVoltage, Current busCurrent ,String fwVersion, Percent soc, UInt16 numberOfCycles, Double batteryCapacity, Double ratedCapacity, Voltage totalBatteryVoltage, Percent soh, Double residualCapacity, List<Double> cellVoltage, TemperaturesList temperaturesList)
{ {
@ -43,12 +38,4 @@ public class BatteryDeligreenDataRecord
TemperaturesList = temperaturesList; TemperaturesList = temperaturesList;
Power = busVoltage * busCurrent; Power = busVoltage * busCurrent;
} }
// public struct Dc_
// {
// public Voltage Voltage => BusVoltage;
// public Current Current => BusCurrent;
// public ActivePower Power => BusVoltage * BusCurrent;
// }
} }

View File

@ -144,7 +144,7 @@ public class BatteryDeligreenDevice
// Read telemetry data from the connected device // Read telemetry data from the connected device
private async Task<BatteryDeligreenDataRecord?> ReadTelemetryData(UInt16 batteryId) private async Task<BatteryDeligreenDataRecord?> ReadTelemetryData(UInt16 batteryId)
{ {
String frameToSend = batteryId switch var frameToSend = batteryId switch
{ {
0 => "7E3230303034363432453030323030464433370D", 0 => "7E3230303034363432453030323030464433370D",
1 => "7E3230303134363432453030323031464433350D", 1 => "7E3230303134363432453030323031464433350D",
@ -199,7 +199,7 @@ public class BatteryDeligreenDevice
return Task.FromResult(responseBuffer.ToArray()); return Task.FromResult(responseBuffer.ToArray());
} }
private async Task<BatteryDeligreenAlarmRecord> ReadTelecomandData(UInt16 batteryId) private async Task<BatteryDeligreenAlarmRecord?> ReadTelecomandData(UInt16 batteryId)
{ {
var frameToSend = batteryId switch var frameToSend = batteryId switch
{ {
@ -219,15 +219,14 @@ public class BatteryDeligreenDevice
{ {
// Write the frame to the channel (send it to the device) // Write the frame to the channel (send it to the device)
Write(frameToSend); Write(frameToSend);
// await Task.Delay(delayFrame2);
// Read the response from the channel (assuming max response size) // Read the response from the channel (assuming max response size)
var responseBytes = await ReadFullResponse(116, 64); // Assuming Read can be executed asynchronously var responseBytes = await ReadFullResponse(116, 64); // Assuming Read can be executed asynchronously
// Convert the byte array to a hexadecimal string // Convert the byte array to a hexadecimal string
var responseHex = BytesToHexString(responseBytes); var responseHex = BytesToHexString(responseBytes);
var response = new TelecommandFrameParser().ParsingTelecommandFrame(responseHex); return new TelecommandFrameParser().ParsingTelecommandFrame(responseHex);
return new BatteryDeligreenAlarmRecord();
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -242,7 +241,7 @@ public class BatteryDeligreenDevice
var alarmRecord = ReadTelecomandData(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 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) private static String ConstructFrameToSend(UInt16 batteryId, String functionCode)
@ -252,8 +251,7 @@ public class BatteryDeligreenDevice
var batteryIdHex = string.Concat(batteryIdAscii.Select(c => ((Int32)c).ToString("X2"))); var batteryIdHex = string.Concat(batteryIdAscii.Select(c => ((Int32)c).ToString("X2")));
Console.WriteLine("Battery ID " + batteryIdHex); Console.WriteLine("Battery ID " + batteryIdHex);
var frameToSend = var frameToSend = FrameStart + Version + batteryIdHex + DeviceCode + functionCode +
FrameStart + Version + batteryIdHex + DeviceCode + functionCode +
"453030323030464433370D"; // Example custom frame with dynamic batteryId "453030323030464433370D"; // Example custom frame with dynamic batteryId
Console.WriteLine(frameToSend); Console.WriteLine(frameToSend);
return frameToSend; return frameToSend;