Update Battery Deligreen records
This commit is contained in:
parent
1077111b77
commit
355c96da55
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
<ItemGroup>
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,26 +1,23 @@
|
|||
namespace InnovEnergy.Lib.Devices.BatteryDeligreen;
|
||||
|
||||
public class BatteryDeligreenAlarmRecord
|
||||
{/*
|
||||
public String FwVersion { get; set; }
|
||||
{
|
||||
|
||||
public List<String> CellAlarmList { get; set; }
|
||||
public List<String> 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<Double> cellVoltage, TemperaturesList temperaturesList)
|
||||
public BatteryDeligreenAlarmRecord( List<String> cellAlarmList, List<String> 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,14 +4,10 @@ using static InnovEnergy.Lib.Devices.BatteryDeligreen.Temperatures;
|
|||
namespace InnovEnergy.Lib.Devices.BatteryDeligreen;
|
||||
using InnovEnergy.Lib.Units;
|
||||
|
||||
using Strings = IReadOnlyList<String>;
|
||||
|
||||
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<Double> 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<Double> 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;
|
||||
|
||||
// }
|
||||
}
|
||||
|
|
@ -144,7 +144,7 @@ public class BatteryDeligreenDevice
|
|||
// Read telemetry data from the connected device
|
||||
private async Task<BatteryDeligreenDataRecord?> 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<BatteryDeligreenAlarmRecord> ReadTelecomandData(UInt16 batteryId)
|
||||
private async Task<BatteryDeligreenAlarmRecord?> 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<BatteryDeligreenRecord?> 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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue