update program.cs to debug
This commit is contained in:
parent
5db53006c3
commit
79b7563401
|
|
@ -24,6 +24,8 @@ using Formatting = Newtonsoft.Json.Formatting;
|
||||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||||
using static InnovEnergy.App.SinexcelCommunication.MiddlewareClasses.MiddlewareAgent;
|
using static InnovEnergy.App.SinexcelCommunication.MiddlewareClasses.MiddlewareAgent;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using InnovEnergy.Lib.Devices.Sinexcel_12K_TL.DataType;
|
||||||
|
|
||||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
|
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
|
||||||
|
|
||||||
namespace InnovEnergy.App.SinexcelCommunication;
|
namespace InnovEnergy.App.SinexcelCommunication;
|
||||||
|
|
@ -117,13 +119,48 @@ internal static class Program
|
||||||
var statusrecord = ReadStatus();
|
var statusrecord = ReadStatus();
|
||||||
if (statusrecord == null)
|
if (statusrecord == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
// Console.WriteLine( statusrecord.InverterRecord.TimedChargeAndDischargeOff + " TimedChargeAndDischargeOff ");
|
||||||
|
Console.WriteLine( statusrecord.InverterRecord.Battery1Power + " Battery1Power ");
|
||||||
|
Console.WriteLine( statusrecord.InverterRecord.Battery1Soc + " Battery1Soc ");
|
||||||
|
Console.WriteLine( statusrecord.InverterRecord.RepetitiveWeeks + " RepetitiveWeeks ");
|
||||||
|
Console.WriteLine( statusrecord.InverterRecord.EffectiveStartDate + " EffectiveStartDate ");
|
||||||
|
Console.WriteLine( statusrecord.InverterRecord.EffectiveEndDate + " EffectiveEndDate ");
|
||||||
|
Console.WriteLine( statusrecord.InverterRecord.ChargingPowerPeriod1 + " ChargingPowerPeriod1 ");
|
||||||
|
Console.WriteLine( statusrecord.InverterRecord.ChargeStartTimePeriod1 + " ChargeStartTimePeriod1 ");
|
||||||
|
Console.WriteLine( statusrecord.InverterRecord.ChargeEndTimePeriod1 + " ChargeEndTimePeriod1 ");
|
||||||
|
|
||||||
|
Console.WriteLine( statusrecord.InverterRecord.DischargeStartTimePeriod1 + " DischargeStartTimePeriod1 ");
|
||||||
|
Console.WriteLine( statusrecord.InverterRecord.DischargeEndTimePeriod1 + " DischargeEndTimePeriod1 ");
|
||||||
|
|
||||||
|
Console.WriteLine( statusrecord.InverterRecord.PowerOn + " PowerOn ");
|
||||||
|
Console.WriteLine( statusrecord.InverterRecord.PowerOff + " PowerOff ");
|
||||||
|
Console.WriteLine( statusrecord.InverterRecord.WorkingMode + " WorkingMode ");
|
||||||
|
// Console.WriteLine( statusrecord.InverterRecord.FaultClearing + " FaultClearing ");
|
||||||
SendSalimaxStateAlarm(GetSodiHomeStateAlarm(statusrecord),statusrecord);
|
SendSalimaxStateAlarm(GetSodiHomeStateAlarm(statusrecord),statusrecord);
|
||||||
|
|
||||||
Console.WriteLine( " ************************************ We are writing ************************************");
|
Console.WriteLine( " ************************************ We are writing ************************************");
|
||||||
var startWritingTime = DateTime.Now;
|
var startWritingTime = DateTime.Now;
|
||||||
Console.WriteLine(startWritingTime.ToString("HH:mm:ss.fff ") +"start Writing");
|
Console.WriteLine(startWritingTime.ToString("HH:mm:ss.fff ") +"start Writing");
|
||||||
statusrecord?.Config.Save(); // save the config file
|
statusrecord?.Config.Save(); // save the config file
|
||||||
//if (statusrecord?.InverterRecord != null) sinexcelDevice.Write(statusrecord.InverterRecord);
|
|
||||||
|
if (statusrecord != null)
|
||||||
|
{
|
||||||
|
statusrecord.InverterRecord.WorkingMode = WorkingMode.TimeChargeDischarge;
|
||||||
|
|
||||||
|
//statusrecord.InverterRecord.TimedChargeAndDischargeOff = 0;
|
||||||
|
statusrecord.InverterRecord.RepetitiveWeeks = SinexcelWeekDays.All;
|
||||||
|
statusrecord.InverterRecord.EffectiveStartDate = DateTime.Today.AddDays(-1);
|
||||||
|
statusrecord.InverterRecord.EffectiveEndDate = DateTime.Today.AddDays(2);
|
||||||
|
statusrecord.InverterRecord.ChargingPowerPeriod1 = 3;
|
||||||
|
statusrecord.InverterRecord.DishargingPowerPeriod1 = 3;
|
||||||
|
statusrecord.InverterRecord.DischargeStartTimePeriod1 = new TimeSpan(16, 00, 0);
|
||||||
|
statusrecord.InverterRecord.DischargeEndTimePeriod1 = new TimeSpan(17, 03, 0);
|
||||||
|
statusrecord.InverterRecord.PowerOn = 1;
|
||||||
|
statusrecord.InverterRecord.PowerOff = 0;
|
||||||
|
//statusrecord.InverterRecord.FaultClearing = 1;
|
||||||
|
}
|
||||||
|
if (statusrecord?.InverterRecord != null) sinexcelDevice.Write(statusrecord.InverterRecord);
|
||||||
|
|
||||||
var stopTime = DateTime.Now;
|
var stopTime = DateTime.Now;
|
||||||
Console.WriteLine(stopTime.ToString("HH:mm:ss.fff ")+ "run iteration time finish");
|
Console.WriteLine(stopTime.ToString("HH:mm:ss.fff ")+ "run iteration time finish");
|
||||||
|
|
@ -247,10 +284,11 @@ internal static class Program
|
||||||
var modbusData = new Dictionary<String, UInt16>();
|
var modbusData = new Dictionary<String, UInt16>();
|
||||||
|
|
||||||
// SYSTEM DATA
|
// SYSTEM DATA
|
||||||
var result1 = ConvertToModbusRegisters((status.Config.MinSoc * 10), "UInt16", 30001); // this to be updated to modbusTCP version
|
var result1 = ConvertToModbusRegisters((status.Config.ModbusProtcolNumber * 10), "UInt16", 30001); // this to be updated to modbusTCP version
|
||||||
var result2 = ConvertToModbusRegisters(status.InverterRecord.GridAPhaseVoltage, "UInt32", 30002);
|
var result2 = ConvertToModbusRegisters(status.InverterRecord.SystemDateTime.ToUnixTime(), "UInt32", 30002);
|
||||||
|
|
||||||
// Merge all results into one dictionary
|
// Merge all results into one dictionary
|
||||||
|
|
||||||
var allResults = new[]
|
var allResults = new[]
|
||||||
{
|
{
|
||||||
result1,result2
|
result1,result2
|
||||||
|
|
@ -274,40 +312,67 @@ internal static class Program
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Dictionary<String, UInt16> ConvertToModbusRegisters(Object value, String outputType, Int32 startingAddress)
|
private static Dictionary<string, ushort> ConvertToModbusRegisters(object value, string outputType, int startingAddress)
|
||||||
{
|
{
|
||||||
var registers = new Dictionary<String, UInt16>();
|
var regs = new Dictionary<string, ushort>(capacity: 2);
|
||||||
|
|
||||||
switch (outputType)
|
switch (outputType)
|
||||||
{
|
{
|
||||||
case "UInt16":
|
case "UInt16":
|
||||||
registers[startingAddress.ToString()] = Convert.ToUInt16(value);
|
{
|
||||||
|
regs[$"{startingAddress}"] = Convert.ToUInt16(value);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case "Int16":
|
case "Int16":
|
||||||
var int16Val = Convert.ToInt16(value);
|
{
|
||||||
registers[startingAddress.ToString()] = (UInt16)int16Val; // reinterpret signed as ushort
|
short v = Convert.ToInt16(value);
|
||||||
|
regs[$"{startingAddress}"] = unchecked((ushort)v); // reinterpret
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case "UInt32":
|
case "UInt32":
|
||||||
var uint32Val = Convert.ToUInt32(value);
|
{
|
||||||
registers[startingAddress.ToString()] = (UInt16)(uint32Val & 0xFFFF); // Low word
|
uint v = Convert.ToUInt32(value);
|
||||||
registers[(startingAddress + 1).ToString()] = (UInt16)(uint32Val >> 16); // High word
|
ushort hi = (ushort)(v >> 16);
|
||||||
|
ushort lo = (ushort)(v & 0xFFFF);
|
||||||
|
regs[$"{startingAddress}"] = hi; // HIGH word first (Modbus standard)
|
||||||
|
regs[$"{startingAddress + 1}"] = lo; // then LOW word
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case "Int32":
|
case "Int32":
|
||||||
var int32Val = Convert.ToInt32(value);
|
{
|
||||||
var raw = unchecked((UInt32)int32Val); // reinterprets signed int as unsigned
|
int v = Convert.ToInt32(value);
|
||||||
registers[startingAddress.ToString()] = (UInt16)(raw & 0xFFFF);
|
uint raw = unchecked((uint)v); // bit-reinterpret
|
||||||
registers[(startingAddress + 1).ToString()] = (UInt16)(raw >> 16);
|
ushort hi = (ushort)(raw >> 16);
|
||||||
|
ushort lo = (ushort)(raw & 0xFFFF);
|
||||||
|
regs[$"{startingAddress}"] = hi; // HIGH word
|
||||||
|
regs[$"{startingAddress + 1}"] = lo; // LOW word
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "Float": // IEEE-754 single
|
||||||
|
{
|
||||||
|
float f = Convert.ToSingle(value);
|
||||||
|
// Convert to bytes, then to two big-endian 16-bit words
|
||||||
|
var bytes = BitConverter.GetBytes(f); // little-endian on most platforms
|
||||||
|
Array.Reverse(bytes); // to big-endian byte order
|
||||||
|
ushort hi = (ushort)((bytes[0] << 8) | bytes[1]);
|
||||||
|
ushort lo = (ushort)((bytes[2] << 8) | bytes[3]);
|
||||||
|
regs[$"{startingAddress}"] = hi;
|
||||||
|
regs[$"{startingAddress + 1}"] = lo;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new ArgumentException("Unsupported output type: " + outputType);
|
throw new ArgumentException($"Unsupported output type: {outputType}");
|
||||||
}
|
}
|
||||||
return registers;
|
|
||||||
|
return regs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static async Task<Boolean> DataLogging(StatusRecord status, DateTime timeStamp)
|
private static async Task<Boolean> DataLogging(StatusRecord status, DateTime timeStamp)
|
||||||
{
|
{
|
||||||
var csv = status.ToCsv();
|
var csv = status.ToCsv();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue