Browse Source

增加设备数据上传接口

master
anerx 2 months ago
parent
commit
fb851cf256
  1. 13
      Admin.Bodk.Customer/Entities/Customer.cs
  2. 30
      Admin.Bodk.Device/Services/DeviceService.cs
  3. 23
      Admin.NET.Application/Configuration/Swagger.json
  4. 13
      Admin.NET.Bodk.Core/Admin.NET.Bodk.Core.csproj
  5. 10
      Admin.NET.Bodk.Core/Devices/DeviceType.cs
  6. 19
      Admin.NET.Bodk.Core/Devices/IDevice.cs
  7. 10
      Admin.NET.Bodk.Core/IRuntime.cs
  8. 13
      Admin.NET.Bodk.Customer/Admin.NET.Bodk.Customer.csproj
  9. 15
      Admin.NET.Bodk.Customer/CustomerService.cs
  10. 19
      Admin.NET.Bodk.Customer/Entities/CustomerEntity.cs
  11. 13
      Admin.NET.Bodk.Device/Admin.NET.Bodk.Device.csproj
  12. 54
      Admin.NET.Bodk.Device/Controllers/DeviceController.cs
  13. 18
      Admin.NET.Bodk.Device/Controllers/Dto/DeviceDto.cs
  14. 10
      Admin.NET.Bodk.Device/Devices/DeviceType.cs
  15. 18
      Admin.NET.Bodk.Device/Devices/IDevice.cs
  16. 22
      Admin.NET.Bodk.Device/Devices/Summary/M9Summary.cs
  17. 13
      Admin.NET.Bodk.Genetic/Admin.NET.Bodk.Genetic.csproj
  18. 10
      Admin.NET.Bodk.Genetic/Entities/GeneticTestAgencyEntity.cs
  19. 10
      Admin.NET.Bodk.Genetic/Entities/GeneticTestResultEntity.cs
  20. 17
      Admin.NET.Bodk.Project/Admin.NET.Bodk.Project.csproj
  21. 87
      Admin.NET.Bodk.Project/Controllers/ProjectController.cs
  22. 21
      Admin.NET.Bodk.Project/Entities/ProjectEntity.cs
  23. 50
      Admin.NET.Bodk.Project/Models/Project.cs
  24. 2
      Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj
  25. 30
      Admin.NET.sln
  26. 6
      Bodk.Device.Storage/IStorage.cs
  27. 31
      Bodk.Device.Storage/M9Storage.cs
  28. 58
      Bodk.Device.Storage/Modules/Valves.cs

13
Admin.Bodk.Customer/Entities/Customer.cs

@ -1,4 +1,3 @@
using System.ComponentModel.DataAnnotations;
using Admin.NET.Core;
using Nest;
@ -6,10 +5,11 @@ using SqlSugar;
using Yitter.IdGenerator;
namespace Admin.Bodk.Customer.Entities;
/// <summary>
/// 客户表
/// </summary>
[SugarTable(null, "客户表")]
[SugarTable("bodk_customer", "客户表")]
[SysTable]
public class Customer : EntityTenant, IRepositorySettings
{
@ -29,6 +29,9 @@ public class Customer: EntityTenant, IRepositorySettings
[SugarColumn(ColumnDescription = "手机号码", Length = 32, IsNullable = true)]
public virtual string PhoneNo { get; set; }
[SugarColumn(ColumnDescription = "数据来源")]
public virtual DataSource Source { get; set; }
}
public enum Sex
@ -36,3 +39,9 @@ public enum Sex
Man = 1,
Woman = 0
}
public enum DataSource
{
App = 1,
Input = 2
}

30
Admin.Bodk.Device/Services/DeviceService.cs

@ -8,6 +8,7 @@ using Furion.DynamicApiController;
using Furion.FriendlyException;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using NewLife.Caching;
using SqlSugar;
namespace Admin.Bodk.Device.Services;
@ -22,10 +23,15 @@ public class DeviceService : IDynamicApiController, ITransient
private readonly SqlSugarRepository<TaskChain> _taskChainRepository;
public DeviceService(SqlSugarRepository<Entities.Device.Device> repository, SqlSugarRepository<TaskChain> taskChainRepository)
private readonly ICache _cache;
public DeviceService(SqlSugarRepository<Entities.Device.Device> repository,
SqlSugarRepository<TaskChain> taskChainRepository,
ICache cache)
{
_repository = repository;
_taskChainRepository = taskChainRepository;
_cache = cache;
}
/// <summary>
@ -41,23 +47,35 @@ public class DeviceService : IDynamicApiController, ITransient
.WhereIF(!string.IsNullOrWhiteSpace(input.Name),
m => m.Name != null && m.Name.Contains(input.Name))
.WhereIF(!string.IsNullOrWhiteSpace(input.Type), m => m.Type == input.Type)
.Select((u) => new EquipmentDto
.Select<EquipmentDto>((u) => new EquipmentDto()
{
Id = u.Id,
Name = u.Name,
Type = u.Type,
BaseName = u.BaseName,
PicUrl = u.PicUrl,
LiquidNitrogenHeight = u.LiquidNitrogenHeight,
Temperature = u.Temperature,
Humidity = u.Humidity,
Address = u.Address,
Remark = u.Remark,
Code = u.Code,
Ip = u.Ip,
Status = u.Status,
CreateTime = u.CreateTime,
//TaskChainList =SqlFunc.Subqueryable<TaskChain>().Where(tc => tc.EquipmentId == u.Id).ToList()
})
.Mapper(d =>
{
var cache = _cache.Get<dynamic>($"bodk:device:{d.Code}:summary");
if (cache is not null)
{
d.Temperature = cache?.TankTopTemperature;
d.LiquidNitrogenHeight = cache?.LiquidHeight;
d.Humidity = cache?.CavityHumidity;
}
else
{
d.Temperature = -192.5f;
d.LiquidNitrogenHeight = 182;
d.Humidity = 0.5f;
}
})
.ToPagedListAsync(input.Page, input.PageSize);
}

23
Admin.NET.Application/Configuration/Swagger.json

@ -1,12 +1,17 @@
{
"$schema": "https://gitee.com/dotnetchina/Furion/raw/v4/schemas/v4/furion-schema.json",
"SpecificationDocumentSettings": {
"DocumentTitle": "Admin.NET 通用权限开发平台",
"DocumentTitle": "Bodk Swagger",
"GroupOpenApiInfos": [
{
"Group": "Bodk Groups",
"Title": "博工业务接口中心",
"Description": "Bodk Business API Center,提供博工业务相关的接口服务。",
"Version": "1.0.0"
},
{
"Group": "Default",
"Title": "Admin.NET 通用权限开发平台",
"Title": "Admin.NET",
"Description": "让 .NET 开发更简单、更通用、更流行。前后端分离架构(.NET6/Vue3),开箱即用紧随前沿技术。<br/><a href='https://gitee.com/zuohuaijun/Admin.NET/'>https://gitee.com/zuohuaijun/Admin.NET</a>",
"Version": "1.0.0"
//"TermsOfService": "https://dotnetchina.gitee.io/furion/",
@ -29,14 +34,18 @@
//}
}
],
"DefaultGroupName": "Default", //
"DocExpansionState": "List", // ListFullNone
"DefaultGroupName": "Default",
//
"DocExpansionState": "List",
// ListFullNone
"EnableAllGroups": true,
"LoginInfo": {
"Enabled": true, // Swagger
"Enabled": true,
// Swagger
"CheckUrl": "/api/swagger/checkUrl",
"SubmitUrl": "/api/swagger/submitUrl"
},
"EnumToNumber": true //
"EnumToNumber": true
//
}
}

13
Admin.NET.Bodk.Core/Admin.NET.Bodk.Core.csproj

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Admin.NET.Core\Admin.NET.Core.csproj" />
</ItemGroup>
</Project>

10
Admin.NET.Bodk.Core/Devices/DeviceType.cs

@ -0,0 +1,10 @@
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
namespace Admin.NET.Bodk.Core.Devices;
public enum DeviceType
{
M9 = 1,
}

19
Admin.NET.Bodk.Core/Devices/IDevice.cs

@ -0,0 +1,19 @@
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
namespace Admin.NET.Bodk.Core.Devices;
public interface IDevice
{
long? Id { get; }
DeviceType Type { get; }
string SerialNumber { get; }
object Summary { get; }
public long? ProjectId { get; }
string Name { get; }
}

10
Admin.NET.Bodk.Core/IRuntime.cs

@ -0,0 +1,10 @@
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
namespace Admin.NET.Bodk.Core;
public interface IRuntime
{
}

13
Admin.NET.Bodk.Customer/Admin.NET.Bodk.Customer.csproj

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Admin.NET.Core\Admin.NET.Core.csproj" />
</ItemGroup>
</Project>

15
Admin.NET.Bodk.Customer/CustomerService.cs

@ -0,0 +1,15 @@
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Microsoft.AspNetCore.Mvc;
namespace Admin.NET.Bodk.Customer;
[ApiDescriptionSettings(GroupName = "Bodk Groups",Description = "客户接口服务")]
public class CustomerService: IDynamicApiController, ITransient
{
}

19
Admin.NET.Bodk.Customer/Entities/CustomerEntity.cs

@ -0,0 +1,19 @@
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
using Admin.NET.Core;
using Nest;
namespace Admin.NET.Bodk.Customer.Entities;
public class CustomerEntity : EntityBase, IRepositorySettings
{
public string Name { get; set; }
public string IdCard { get; set; }
public string Phone { get; set; }
public bool IsMale { get; set; }
}

13
Admin.NET.Bodk.Device/Admin.NET.Bodk.Device.csproj

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Admin.NET.Web.Core\Admin.NET.Web.Core.csproj" />
</ItemGroup>
</Project>

54
Admin.NET.Bodk.Device/Controllers/DeviceController.cs

@ -0,0 +1,54 @@
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
using System.ComponentModel;
using Admin.NET.Bodk.Device.Controllers.Dto;
using Admin.NET.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NewLife.Caching;
namespace Admin.NET.Bodk.Device.Controllers;
[ApiDescriptionSettings(Groups = new[] { "Bodk Groups" },Name = "DeviceController",Description = "设备接口服务")]
public class DeviceController : IDynamicApiController, ITransient
{
private readonly ICache _cache;
public DeviceController(ICache cache)
{
_cache = cache;
}
/// <summary>
/// 上传设备摘要
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[DisplayName("上传设备摘要")]
[Authorize(AuthenticationSchemes =
JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
public Task UploadDeviceSummary(DeviceInput input)
{
_cache.Set($"bodk:device:{input.SerialNumber}:summary", input.Summary);
return Task.CompletedTask;
}
/// <summary>
/// 获取设备摘要
/// </summary>
/// <param name="serialNumber"></param>
/// <returns></returns>
[DisplayName("获取设备摘要")]
[Authorize(AuthenticationSchemes =
JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
public Task<object> GetDeviceSummary(string serialNumber)
{
return Task.Run(() => _cache.Get<object>($"bodk:device:{serialNumber}:summary"));
}
}

18
Admin.NET.Bodk.Device/Controllers/Dto/DeviceDto.cs

@ -0,0 +1,18 @@
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
using Admin.NET.Bodk.Device.Devices;
using Admin.NET.Bodk.Device.Devices.Summary;
namespace Admin.NET.Bodk.Device.Controllers.Dto;
public class DeviceInput
{
public string SerialNumber { get; set; }
public string Name { get; set; }
public DeviceType DeviceType { get; set; }
public object? Summary { get; set; }
}

10
Admin.NET.Bodk.Device/Devices/DeviceType.cs

@ -0,0 +1,10 @@
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
namespace Admin.NET.Bodk.Device.Devices;
public enum DeviceType
{
M9 = 1
}

18
Admin.NET.Bodk.Device/Devices/IDevice.cs

@ -0,0 +1,18 @@
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
using Admin.NET.Bodk.Device.Devices.Summary;
namespace Admin.NET.Bodk.Device.Devices;
public interface IDevice
{
object Summary { get; }
string SerialNumber { get; }
long? Id { get; }
}

22
Admin.NET.Bodk.Device/Devices/Summary/M9Summary.cs

@ -0,0 +1,22 @@
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
namespace Admin.NET.Bodk.Device.Devices.Summary;
public class M9Summary
{
public bool Online { get; set; }
public float CavityHumidity { get; set; }
public float CavityTemperature { get; set; }
public float LiquidHeight { get; set; }
public float LiquidFillingPortTemperature { get; set; }
public float ExhaustPortTemperature { get; set; }
public float TankTopTemperature { get; set; }
}

13
Admin.NET.Bodk.Genetic/Admin.NET.Bodk.Genetic.csproj

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Admin.NET.Core\Admin.NET.Core.csproj" />
</ItemGroup>
</Project>

10
Admin.NET.Bodk.Genetic/Entities/GeneticTestAgencyEntity.cs

@ -0,0 +1,10 @@
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
namespace Admin.NET.Bodk.Genetic.Entities;
public class GeneticTestAgencyEntity
{
}

10
Admin.NET.Bodk.Genetic/Entities/GeneticTestResultEntity.cs

@ -0,0 +1,10 @@
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
namespace Admin.NET.Bodk.Genetic.Entities;
public class GeneticTestResultEntity
{
}

17
Admin.NET.Bodk.Project/Admin.NET.Bodk.Project.csproj

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Admin.NET.Core\Admin.NET.Core.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Services\" />
</ItemGroup>
</Project>

87
Admin.NET.Bodk.Project/Controllers/ProjectController.cs

@ -0,0 +1,87 @@
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
using System.ComponentModel;
using Admin.NET.Bodk.Project.Entities;
using Admin.NET.Bodk.Project.Models;
using Admin.NET.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Microsoft.AspNetCore.Mvc;
namespace Admin.NET.Bodk.Project.Controllers;
[ApiDescriptionSettings(GroupName = "Bodk Groups", Description = "项目接口服务")]
public class ProjectController : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<ProjectEntity> _repository;
public ProjectController(SqlSugarRepository<ProjectEntity> repository)
{
_repository = repository;
}
[ApiDescriptionSettings(Name = "GetList"), HttpPost]
[DisplayName("获取项目列表")]
public async Task<SqlSugarPagedList<Project.Models.Project>> GetList(ProjectQueryInput input)
{
return await _repository.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.Name),
m => input.Name != null && m.Name.Contains(input.Name))
.WhereIF(input.Id is not null, m => m.Id == input.Id)
.WhereIF(!string.IsNullOrWhiteSpace(input.Manager),
m => input.Manager != null && m.Manager.Contains(input.Manager))
.WhereIF(!string.IsNullOrWhiteSpace(input.Phone),
m => input.Phone != null && m.Phone.Contains(input.Phone))
.WhereIF(!string.IsNullOrWhiteSpace(input.Position),
m => input.Position != null && m.Position.Contains(input.Position))
.WhereIF(input.IsDeleted is not null,
m => m.IsDelete == input.IsDeleted)
.Select<Models.Project>((u) => new Models.Project()
{
Id = u.Id,
Name = u.Name,
Manager = u.Manager,
Position = u.Position,
Phone = u.Phone,
IsDeleted = u.IsDelete,
CreateTime = u.CreateTime,
})
.ToPagedListAsync(input.Page, input.PageSize);
}
[ApiDescriptionSettings(Name = "Add"), HttpPost]
[DisplayName("新增项目")]
public async Task AddProject(ProjectInput project)
{
await _repository.InsertAsync(new ProjectEntity()
{
Name = project.Name,
Position = project.Position,
Manager = project.Manager,
Phone = project.Phone
});
}
[ApiDescriptionSettings(Name = "Delete"), HttpPost]
[DisplayName("删除项目")]
public async Task DeleteProject(long id)
{
var project = await _repository.GetSingleAsync(d => d.Id == id);
project.IsDelete = true;
await _repository.UpdateAsync(project);
}
[ApiDescriptionSettings(Name = "Update"), HttpPost]
[DisplayName("修改项目")]
public async Task UpdateProject(ProjectInput projectInput)
{
var project = await _repository.GetSingleAsync(d => d.Id == projectInput.Id);
project.Manager = projectInput.Manager;
project.Name = projectInput.Name;
project.Phone = projectInput.Phone;
project.Position = projectInput.Position;
await _repository.UpdateAsync(project);
}
}

21
Admin.NET.Bodk.Project/Entities/ProjectEntity.cs

@ -0,0 +1,21 @@
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
using Admin.NET.Core;
using Nest;
using SqlSugar;
namespace Admin.NET.Bodk.Project.Entities;
[SugarTable("bodk_project", "项目表")]
public class ProjectEntity : EntityTenant, IRepositorySettings
{
public string Name { get; set; }
public string Position { get; set; }
public string Manager { get; set; }
public string Phone { get; set; }
}

50
Admin.NET.Bodk.Project/Models/Project.cs

@ -0,0 +1,50 @@
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
using Admin.NET.Core;
namespace Admin.NET.Bodk.Project.Models;
public class Project
{
public long? Id { get; set; }
public string Name { get; set; }
public string Position { get; set; }
public string Manager { get; set; }
public string Phone { get; set; }
public bool IsDeleted { get; set; }
public DateTime CreateTime { get; set; }
}
public class ProjectQueryInput : BasePageInput
{
public long? Id { get; set; }
public string? Name { get; set; }
public string? Position { get; set; }
public string? Manager { get; set; }
public string? Phone { get; set; }
public bool? IsDeleted { get; set; }
}
public class ProjectInput : BaseIdInput
{
public string Name { get; set; }
public string Position { get; set; }
public string Manager { get; set; }
public string Phone { get; set; }
}

2
Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj

@ -42,6 +42,8 @@
<ItemGroup>
<ProjectReference Include="..\Admin.Bodk.Customer\Admin.Bodk.Customer.csproj" />
<ProjectReference Include="..\Admin.Bodk.Device\Admin.Bodk.Device.csproj" />
<ProjectReference Include="..\Admin.NET.Bodk.Device\Admin.NET.Bodk.Device.csproj" />
<ProjectReference Include="..\Admin.NET.Bodk.Project\Admin.NET.Bodk.Project.csproj" />
<ProjectReference Include="..\Admin.NET.Web.Core\Admin.NET.Web.Core.csproj" />
</ItemGroup>

30
Admin.NET.sln

@ -30,6 +30,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bodk.Extensions.Modbus", "B
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Admin.Bodk.Customer", "Admin.Bodk.Customer\Admin.Bodk.Customer.csproj", "{6A073364-6552-4CDB-861A-4BD8B51E0FF6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Admin.NET.Bodk.Core", "Admin.NET.Bodk.Core\Admin.NET.Bodk.Core.csproj", "{C7CEFE53-6599-4249-B107-2912415660BD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Admin.NET.Bodk.Genetic", "Admin.NET.Bodk.Genetic\Admin.NET.Bodk.Genetic.csproj", "{BA340773-EEAA-430C-A0FC-AB6C3B35BA6D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Admin.NET.Bodk.Device", "Admin.NET.Bodk.Device\Admin.NET.Bodk.Device.csproj", "{35FB5A4D-4C35-4AF4-9719-1392707F9FF5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Admin.NET.Bodk.Customer", "Admin.NET.Bodk.Customer\Admin.NET.Bodk.Customer.csproj", "{75A96380-AA7E-46A6-892A-D66557B4565B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Admin.NET.Bodk.Project", "Admin.NET.Bodk.Project\Admin.NET.Bodk.Project.csproj", "{51EDA0FA-0D80-4631-9A2E-9315E99BA3CC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -76,6 +86,26 @@ Global
{6A073364-6552-4CDB-861A-4BD8B51E0FF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A073364-6552-4CDB-861A-4BD8B51E0FF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A073364-6552-4CDB-861A-4BD8B51E0FF6}.Release|Any CPU.Build.0 = Release|Any CPU
{C7CEFE53-6599-4249-B107-2912415660BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7CEFE53-6599-4249-B107-2912415660BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7CEFE53-6599-4249-B107-2912415660BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7CEFE53-6599-4249-B107-2912415660BD}.Release|Any CPU.Build.0 = Release|Any CPU
{BA340773-EEAA-430C-A0FC-AB6C3B35BA6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA340773-EEAA-430C-A0FC-AB6C3B35BA6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA340773-EEAA-430C-A0FC-AB6C3B35BA6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA340773-EEAA-430C-A0FC-AB6C3B35BA6D}.Release|Any CPU.Build.0 = Release|Any CPU
{35FB5A4D-4C35-4AF4-9719-1392707F9FF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{35FB5A4D-4C35-4AF4-9719-1392707F9FF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{35FB5A4D-4C35-4AF4-9719-1392707F9FF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{35FB5A4D-4C35-4AF4-9719-1392707F9FF5}.Release|Any CPU.Build.0 = Release|Any CPU
{75A96380-AA7E-46A6-892A-D66557B4565B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75A96380-AA7E-46A6-892A-D66557B4565B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75A96380-AA7E-46A6-892A-D66557B4565B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75A96380-AA7E-46A6-892A-D66557B4565B}.Release|Any CPU.Build.0 = Release|Any CPU
{51EDA0FA-0D80-4631-9A2E-9315E99BA3CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{51EDA0FA-0D80-4631-9A2E-9315E99BA3CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51EDA0FA-0D80-4631-9A2E-9315E99BA3CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51EDA0FA-0D80-4631-9A2E-9315E99BA3CC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

6
Bodk.Device.Storage/IStorage.cs

@ -88,4 +88,10 @@ public interface IStorage
/// </summary>
/// <returns></returns>
Task Ready();
/// <summary>
/// 一键回原
/// </summary>
/// <returns></returns>
Task GotoOrigin();
}

31
Bodk.Device.Storage/M9Storage.cs

@ -39,6 +39,10 @@ public class M9Storage : IStorage
_modbusWrapper.WriteCoilsAsync,
_modbusWrapper.ReadCoilsAsync, _modbusWrapper.ReadHoldingRegistersAsync,
_modbusWrapper.WriteHoldingRegistersAsync));
_modules.Add(new Valves(alarmEventHandler, motionTimeoutAlarmEventHandler,
_modbusWrapper.WriteCoilsAsync,
_modbusWrapper.ReadCoilsAsync, _modbusWrapper.ReadHoldingRegistersAsync,
_modbusWrapper.WriteHoldingRegistersAsync));
}
public async Task Start()
@ -152,7 +156,7 @@ public class M9Storage : IStorage
var module = _modules.FirstOrDefault(m => m.Id == moduleId);
if (module is null)
throw new Exception("module not found");
var method = module.GetType().GetMethod("methodName");
var method = module.GetType().GetMethod(methodName);
if (method is null)
throw new Exception("method not found");
await Task.Run(() => (Task)method.Invoke(module, parameters));
@ -199,7 +203,22 @@ public class M9Storage : IStorage
}
}
public Task Ready()
public async Task Ready()
{
await _modbusWrapper.WriteCoilsAsync(ReadyAddress, new[] { true });
while (!(await _modbusWrapper.ReadCoilsAsync(ReadyFlagAddress, 1))[0])
{
var modules = _modules.Where(d => d.Alarm || d.MotionTimeoutAlarm).ToList();
if (modules.Count > 0)
{
throw new Exception($"module has error");
}
await Task.Delay(100);
}
}
public Task GotoOrigin()
{
throw new NotImplementedException();
}
@ -215,6 +234,14 @@ public class M9Storage : IStorage
private const ushort EnabledAddress = 330;
private const ushort ReadyAddress = 13;
private const ushort ReadyFlagAddress = 14;
private const ushort GotoOriginAddress = 90;
private const ushort OriginFlagAddress = 11;
private void Process()
{
Task.Run(async () =>

58
Bodk.Device.Storage/Modules/Valves.cs

@ -0,0 +1,58 @@
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
using Bodk.Device.Storage.EventArgs;
namespace Bodk.Device.Storage.Modules;
public class Valves(
Action<object?, AlarmChangedEventArg> alarmEventHandler,
Action<object?, MotionTimeoutAlarmChangedEventArg> motionTimeoutAlarmEventHandler,
Func<ushort, bool[], Task> writeCoilRegisterFunc,
Func<ushort, ushort, Task<bool[]>> readCoilRegisterFunc,
Func<ushort, ushort, Task<ushort[]>> readHoldingRegistersFunc,
Func<ushort, ushort[], Task> writeHoldingRegistersFunc)
: ModuleBase(alarmEventHandler, motionTimeoutAlarmEventHandler, writeCoilRegisterFunc, readCoilRegisterFunc,
readHoldingRegistersFunc, writeHoldingRegistersFunc)
{
public override string Name => "Valves";
public override string Descirption => "阀门控制";
public override int Id => 1001;
private static ushort MainValve => 490;
private static ushort InletValve => 491;
private static ushort ExhaustValve => 492;
/// <summary>
/// 总阀控制
/// </summary>
/// <param name="open"></param>
/// <returns></returns>
public Task MainValveSwitch(bool open)
{
return writeCoilRegisterFunc(MainValve, new[] { open });
}
/// <summary>
/// 进液阀控制
/// </summary>
/// <param name="open"></param>
/// <returns></returns>
public Task InletValveSwitch(bool open)
{
return writeCoilRegisterFunc(InletValve, new[] { open });
}
/// <summary>
/// 排气阀控制
/// </summary>
/// <param name="open"></param>
/// <returns></returns>
public Task ExhaustValveSwitch(bool open)
{
return writeCoilRegisterFunc(ExhaustValve, new[] { open });
}
}
Loading…
Cancel
Save