-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
87 lines (71 loc) · 2.97 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using RaspTracer_AN_Modbus.Models;
using Newtonsoft.Json;
using RaspTracer_AN_Modbus.Logic;
using RaspTracer_AN_Modbus.Services;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace RaspTracer_AN_Modbus;
internal class Program
{
public const bool debug = false;
private static async Task Main(string[] args)
{
var host = new HostBuilder()
.ConfigureHostConfiguration(configHost =>
{
configHost.SetBasePath(Directory.GetCurrentDirectory());
configHost.AddEnvironmentVariables(prefix: "env_");
configHost.AddCommandLine(args);
})
.ConfigureAppConfiguration(configApp =>
{
configApp.SetBasePath(Directory.GetCurrentDirectory());
configApp.AddJsonFile("appsettings.json", optional: true);
configApp.AddEnvironmentVariables(prefix: "env_");
configApp.AddCommandLine(args);
})
.ConfigureServices((hostContext, services) =>
{
services.AddLogging();
services.AddSingleton<EPEverIOConnector>();
services.AddSingleton<MQTTService>();
services.AddHostedService<EPEverStatusUpdateService>();
})
.ConfigureLogging((hostContext, configLogging) =>
{
configLogging.AddConsole();
})
.UseConsoleLifetime()
.Build();
await host.RunAsync();
}
//private static void BruteForceWorkingReadRegisters()
//{
// EPEverIOConnector.OpenConnection();
// for (int a0 = 48; a0 < 52; a0++)
// {
// for (int a1 = 0; a1 < 256; a1++)
// {
// byte[] a0Bytes = BitConverter.GetBytes(a0);
// byte[] a1Bytes = BitConverter.GetBytes(a1);
// var address = new byte[] { 0x04, a0Bytes.First(), a1Bytes.First(), 0x00, 0x01 };
// try
// {
// var queryPackage = new EPEverQueryPackage(address);
// byte[] response = EPEverIOConnector.GetValueFromEPever(queryPackage);
// if (EPEverIOConnector.ByteArrayToString(response) != "018402C2C100" && EPEverIOConnector.ByteArrayToString(response).Substring(7, 4) != "2C10")
// {
// Console.WriteLine("Address: " + EPEverIOConnector.ByteArrayToString(new byte[] { a0Bytes.First(), a1Bytes.First() })
// + "; Response: " + EPEverIOConnector.ByteArrayToString(response).Substring(7, 4));
// }
// }
// catch (Exception ex)
// {
// }
// }
// }
// EPEverIOConnector.CloseConnection();
//}
}