46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using InnovEnergy.Lib.Devices.BatteryDeligreen;
|
|
|
|
internal static class Program
|
|
{
|
|
private static readonly TimeSpan UpdateInterval = TimeSpan.FromSeconds(2);
|
|
|
|
// private static readonly Channel? BatteriesChannel;
|
|
|
|
private const String Port = "/dev/ttyUSB0";
|
|
|
|
|
|
static Program()
|
|
{
|
|
Console.WriteLine("Hello, Deligreen World!");
|
|
|
|
// BatteriesChannel = new SerialPortChannel(Port, BaudRate, Parity, DataBits, StopBits);
|
|
|
|
}
|
|
|
|
public static async Task Main(string[] args)
|
|
{
|
|
Console.WriteLine("Starting Battery Communication");
|
|
|
|
var batteryDevices = new BatteryDeligreenDevice(Port);
|
|
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
Console.WriteLine("***************************** New Frame *********************************");
|
|
Console.WriteLine($"First Reading Timestamp: {DateTime.Now:HH:mm:ss.fff}");
|
|
// Read telemetry data asynchronously
|
|
await batteryDevices.ReadTelemetryData();
|
|
Console.WriteLine($"Last Timestamp: {DateTime.Now:HH:mm:ss.fff}");
|
|
// Wait for 2 seconds before the next reading
|
|
await Task.Delay(2000); // Delay in milliseconds (2000ms = 2 seconds)
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
// Handle exception and print the error
|
|
Console.WriteLine(e);
|
|
await Task.Delay(2000); // Delay in milliseconds (2000ms = 2 seconds)
|
|
}
|
|
}
|
|
}
|
|
} |