Innovenergy_trunk/csharp/App/SchneiderMeterDriver/Signal.cs

80 lines
2.8 KiB
C#
Raw Normal View History

2024-06-07 08:36:15 +00:00
/*using InnovEnergy.Lib.Devices.IEM3kGridMeter;
2024-06-04 10:23:19 +00:00
using InnovEnergy.Lib.Protocols.DBus.Protocol.DataTypes;
using InnovEnergy.Lib.Victron.VeDBus;
2024-06-04 13:28:17 +00:00
namespace InnovEnergy.App.SchneiderDriver;
2024-06-04 10:23:19 +00:00
// TODO: Does not compile
2024-06-07 08:36:15 +00:00
public record Signal(Func<Iem3KGridMeterRegisters, object> Source, ObjectPath Path, string Format = "")
2024-06-04 10:23:19 +00:00
{
public VeProperty ToVeProperty(Iem3KGridMeterRegisters status)
2024-06-04 10:23:19 +00:00
{
var value = Source(status);
2024-06-07 08:36:15 +00:00
return new VeProperty(Path, value, string.Format($"{{0:{Format}}}", value));
2024-06-04 10:23:19 +00:00
}
2024-06-07 08:36:15 +00:00
}*/
using InnovEnergy.Lib.Devices.IEM3kGridMeter;
using InnovEnergy.Lib.Protocols.DBus.Protocol.DataTypes;
using InnovEnergy.Lib.Victron.VeDBus;
2024-06-12 12:05:29 +00:00
2024-06-07 08:36:15 +00:00
namespace InnovEnergy.App.SchneiderDriver
2024-06-12 12:05:29 +00:00
{
public record Signal(Func<Iem3KGridMeterRegisters, Object> Source, ObjectPath Path, String Format = "")
2024-06-12 12:05:29 +00:00
{
// Converts the status object to a VeProperty, handling null status gracefully
public VeProperty ToVeProperty(Iem3KGridMeterRegisters status)
{
// Check if status is null and log a message
// if (status == null)
// {
// Console.WriteLine($"Status is null for path: {Path}");
// // Return a default VeProperty if status is null
// return new VeProperty(Path, default(double), string.Format($"{{0:{Format}}}", default(double)));
// }
//
// // Retrieve the value using the provided source function
var value = Source(status);
//
// // Handle the case where the value itself might be null
// if (value == null)
// {
// Console.WriteLine($"Value is null for path: {Path}");
// // Return a default VeProperty if value is null
// return new VeProperty(Path, default(double), string.Format($"{{0:{Format}}}", default(double)));
// }
2024-06-12 12:05:29 +00:00
if (value is Single floatValue)
{
value = (Double)floatValue;
}
2024-06-12 12:05:29 +00:00
// Create and return the VeProperty with the actual value and format
return new VeProperty(Path, value, string.Format($"{{0:{Format}}}", value));
}
}
}
/*namespace InnovEnergy.App.SchneiderDriver
2024-06-07 08:36:15 +00:00
{
public record Signal(Func<Iem3KGridMeterRegisters, object> Source, ObjectPath Path, string Format = "")
{
public VeProperty ToVeProperty(Iem3KGridMeterRegisters status)
{
if (status == null)
{
Console.WriteLine($"Status is null for path: {Path}");
// Return a default VeProperty if status is null
return new VeProperty(Path, default, String.Format($"{{0:{Format}}}", default));
}
var value = Source(status);
return new VeProperty(Path, value, String.Format($"{{0:{Format}}}", value));
}
}
2024-06-12 12:05:29 +00:00
}*/
2024-06-07 08:36:15 +00:00