Add project files.
This commit is contained in:
25
EPTracer.sln
Normal file
25
EPTracer.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30907.101
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EPTracer", "EPTracer\EPTracer.csproj", "{51295B4D-8DE3-4BF7-B6AD-72629DAD922C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{51295B4D-8DE3-4BF7-B6AD-72629DAD922C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{51295B4D-8DE3-4BF7-B6AD-72629DAD922C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{51295B4D-8DE3-4BF7-B6AD-72629DAD922C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{51295B4D-8DE3-4BF7-B6AD-72629DAD922C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {C50D5042-CBEF-475D-81BC-ADF0B6909767}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
8
EPTracer/EPTracer - Backup.csproj
Normal file
8
EPTracer/EPTracer - Backup.csproj
Normal file
@@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
21
EPTracer/EPTracer.csproj
Normal file
21
EPTracer/EPTracer.csproj
Normal file
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="InfluxDB.Client" Version="4.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
|
||||
<PackageReference Include="NModbus" Version="3.0.72" />
|
||||
<PackageReference Include="NModbus.Serial" Version="3.0.72" />
|
||||
<PackageReference Include="System.IO.Ports" Version="6.0.0" />
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
114
EPTracer/Program.cs
Normal file
114
EPTracer/Program.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using InfluxDB.Client;
|
||||
using InfluxDB.Client.Api.Domain;
|
||||
using InfluxDB.Client.Writes;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using NModbus;
|
||||
using NModbus.Serial;
|
||||
using System;
|
||||
using System.IO.Ports;
|
||||
|
||||
namespace EPTracer
|
||||
{
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("***************************************************************");
|
||||
Console.WriteLine("Loading config...");
|
||||
|
||||
IConfiguration config = new ConfigurationBuilder()
|
||||
.AddJsonFile("appsettings.json", true, true)
|
||||
.Build();
|
||||
string portConf = config["port"];
|
||||
int interval = int.Parse(config["interval"]);
|
||||
string influxdb = config["influxdb"];
|
||||
string token = config["token"];
|
||||
string bucket = config["bucket"];
|
||||
string org = config["org"];
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"Serial Port: {portConf}");
|
||||
Console.WriteLine($"Interval: {interval}");
|
||||
Console.WriteLine($"InfluxDB: {influxdb}");
|
||||
Console.WriteLine($"Token: {token.Substring(0, 15)}...");
|
||||
Console.WriteLine($"Bucket: {bucket}");
|
||||
Console.WriteLine($"Org: {org}");
|
||||
Console.WriteLine("***************************************************************");
|
||||
Console.WriteLine();
|
||||
|
||||
|
||||
using (SerialPort port = new SerialPort(portConf))
|
||||
{
|
||||
Console.WriteLine($"Configuring serial port: {portConf}");
|
||||
// configure serial port
|
||||
port.BaudRate = 115200;
|
||||
port.DataBits = 8;
|
||||
port.Parity = Parity.None;
|
||||
port.StopBits = StopBits.One;
|
||||
|
||||
Console.WriteLine("Opening port");
|
||||
port.Open();
|
||||
|
||||
var factory = new ModbusFactory();
|
||||
IModbusSerialMaster master = factory.CreateRtuMaster(port);
|
||||
|
||||
byte slaveId = 1;
|
||||
ushort startAddress = 0x3100;
|
||||
ushort numRegisters = 18;
|
||||
|
||||
Console.WriteLine("Reading registers");
|
||||
Console.WriteLine(".....");
|
||||
while (true)
|
||||
{
|
||||
//read registers
|
||||
ushort[] registers = master.ReadInputRegisters(slaveId, startAddress, numRegisters);
|
||||
|
||||
var pvv = registers[0] / 100.00;
|
||||
var pva = registers[1] / 100.00;
|
||||
var pvw = registers[2] / 100.00;
|
||||
var btv = registers[4] / 100.00;
|
||||
var bta = registers[5] / 100.00;
|
||||
var btw = registers[6] / 100.00;
|
||||
var ldv = registers[8] / 100.00;
|
||||
var lda = registers[9] / 100.00;
|
||||
var ldw = registers[10] / 100.00;
|
||||
var btt = registers[12] / 100.00;
|
||||
var btc = registers[15] / 100.00;
|
||||
var rbt = registers[16] / 100.00;
|
||||
|
||||
using (var client = InfluxDBClientFactory.Create(influxdb, token))
|
||||
{
|
||||
client.SetLogLevel(InfluxDB.Client.Core.LogLevel.Body);
|
||||
|
||||
var timestamp = DateTime.UtcNow;
|
||||
var point = PointData.Measurement("solar")
|
||||
.Tag("unit", "1")
|
||||
.Field("pvv", pvv)
|
||||
.Field("pva", pva)
|
||||
.Field("pvw", pvw)
|
||||
.Field("btv", btv)
|
||||
.Field("bta", bta)
|
||||
.Field("btw", btw)
|
||||
.Field("ldv", ldv)
|
||||
.Field("lda", lda)
|
||||
.Field("ldw", ldw)
|
||||
.Field("btt", btt)
|
||||
.Field("btc", btc)
|
||||
.Field("rbt", rbt)
|
||||
.Timestamp(DateTime.UtcNow, WritePrecision.Ns);
|
||||
|
||||
using (var writeApi = client.GetWriteApi())
|
||||
{
|
||||
writeApi.WritePoint(point, bucket, org);
|
||||
Console.WriteLine(point.ToLineProtocol());
|
||||
}
|
||||
}
|
||||
|
||||
System.Threading.Thread.Sleep(interval * 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
EPTracer/appsettings.json
Normal file
8
EPTracer/appsettings.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"port": "/dev/ttyXRUSB0",
|
||||
"interval": 5,
|
||||
"influxdb": "http://127.0.0.1:8086",
|
||||
"token": "l8GGGVe6YaNTfvsE5h4WLMLOEVkOL49NyOvCD3eV1LqI4va2Uh9Acza0-_UIhbuT5FdJe5FniRlMoWtHM3kV-A==",
|
||||
"bucket": "solar",
|
||||
"org": "flexa"
|
||||
}
|
||||
Reference in New Issue
Block a user