采集实现完成。

master
MysticBoy 3 years ago
parent 996a1f59c4
commit c23e7f796e

@ -2,11 +2,15 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>annotations</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-IoTSharp.Gateway.Modbus-554A6128-AB47-40BC-8BC3-40D3123C6BFF</UserSecretsId> <UserSecretsId>aspnet-IoTSharp.Gateway.Modbus-554A6128-AB47-40BC-8BC3-40D3123C6BFF</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>.</DockerfileContext> <DockerfileContext>.</DockerfileContext>
<RestoreAdditionalProjectSources>
https://api.nuget.org/v3/index.json;
https://www.myget.org/F/iotsharp/api/v3/index.json;
</RestoreAdditionalProjectSources>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -14,19 +18,20 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="AMWD.Modbus.Common" Version="1.2.0" /> <PackageReference Include="AMWD.Modbus.Common" Version="1.2.1-1" />
<PackageReference Include="AMWD.Modbus.Proxy" Version="1.2.0" /> <PackageReference Include="AMWD.Modbus.Proxy" Version="1.2.0" />
<PackageReference Include="AMWD.Modbus.Serial" Version="1.2.0" /> <PackageReference Include="AMWD.Modbus.Serial" Version="1.2.0" />
<PackageReference Include="AMWD.Modbus.Tcp" Version="1.2.0" /> <PackageReference Include="AMWD.Modbus.Tcp" Version="1.2.0" />
<PackageReference Include="Modbus.SerialOverTCP" Version="1.2.1-1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.*" /> <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.*" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.*" /> <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.*" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.*" /> <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.*" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.*" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.*" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.16.1" /> <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.16.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.*" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.*" />
<PackageReference Include="MQTTnet" Version="4.0.2.221" /> <PackageReference Include="MQTTnet" Version="4.0.2.221" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="6.0.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -23,7 +23,7 @@ namespace IoTSharp.Gateway.Modbus.Pages.PointMapAdmin
public async Task OnGetAsync(Guid id) public async Task OnGetAsync(Guid id)
{ {
SlaveId = id; SlaveId = id;
if (_context.PointMappings != null && id!=null) if (_context.PointMappings != null && id!=Guid.Empty)
{ {
PointMapping = await _context.PointMappings.Include(pt => pt.Owner).Where(fm => fm.Owner!=null && fm.Owner.Id == id).ToListAsync(); PointMapping = await _context.PointMappings.Include(pt => pt.Owner).Where(fm => fm.Owner!=null && fm.Owner.Id == id).ToListAsync();
} }

@ -9,6 +9,7 @@ namespace IoTSharp.Gateway.Modbus
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found."); var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");

@ -74,7 +74,7 @@ namespace IoTSharp.Gateway.Modbus.Services
} while (!stoppingToken.IsCancellationRequested); } while (!stoppingToken.IsCancellationRequested);
} }
private async Task ReadDatas(ModbusSlave slave, IModbusClient? client, CancellationToken stoppingToken) private async Task ReadDatas(ModbusSlave slave, IModbusClient client, CancellationToken stoppingToken)
{ {
var points = _dbContext.PointMappings.Include(p => p.Owner).Where(p => p.Owner == slave).ToList(); var points = _dbContext.PointMappings.Include(p => p.Owner).Where(p => p.Owner == slave).ToList();
foreach (var point in points) foreach (var point in points)
@ -259,14 +259,12 @@ namespace IoTSharp.Gateway.Modbus.Services
ParseDtuParam(url, dtu); ParseDtuParam(url, dtu);
client = dtu; client = dtu;
break; break;
case "tcp": case "tcp":
client = new AMWD.Modbus.Tcp.Client.ModbusClient(url.Host, url.Port, mlog); client = new AMWD.Modbus.Tcp.Client.ModbusClient(url.Host, url.Port, mlog);
break; break;
case "d2t": case "d2t":
// client = new AMWD.Modbus.Tcp.Client.ModbusClient(url.Host, url.Port, mlog); client = new AMWD.Modbus.SerialOverTCP.Client.ModbusClient(url.Host, url.Port, mlog);
break;
default: default:
break; break;
} }

Loading…
Cancel
Save