diff --git a/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs b/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs index 2ee95d9..b3c3b17 100644 --- a/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs +++ b/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs @@ -28,8 +28,8 @@ namespace SlnMesnac.Business.@base private ILogger _logger; private IAirportTaskService _Taskservice; private IAGVStateService _AGVStateService; - private AirPorthttpClient _airPorthttpClient; - public BaseTaskInfoBusiness(ILogger logger, IAirportTaskService Taskservice, IAGVStateService agvService, TcpServer tcpServer, AirPorthttpClient airPorthttpClient) + private MeshttpClient _airPorthttpClient; + public BaseTaskInfoBusiness(ILogger logger, IAirportTaskService Taskservice, IAGVStateService agvService, TcpServer tcpServer, MeshttpClient airPorthttpClient) { _logger = logger; _tcpServer = tcpServer; @@ -107,7 +107,7 @@ namespace SlnMesnac.Business.@base } } - public static BaseTaskInfoBusiness GetInstance(ILogger logger, IAirportTaskService Taskservice, IAGVStateService agvService, TcpServer tcpServer, AirPorthttpClient airPorthttpClient) + public static BaseTaskInfoBusiness GetInstance(ILogger logger, IAirportTaskService Taskservice, IAGVStateService agvService, TcpServer tcpServer, MeshttpClient airPorthttpClient) { if (instance == null) { diff --git a/SlnMesnac.Extensions/RfidFactorySetup.cs b/SlnMesnac.Extensions/RfidFactorySetup.cs index ac5e29f..02591a8 100644 --- a/SlnMesnac.Extensions/RfidFactorySetup.cs +++ b/SlnMesnac.Extensions/RfidFactorySetup.cs @@ -1,9 +1,11 @@ using Microsoft.Extensions.DependencyInjection; +using Models; using Serilog; using SlnMesnac.Config; using SlnMesnac.Plc; using SlnMesnac.Rfid; using SlnMesnac.Rfid.Factory; +using SqlSugar; using System; using System.Collections.Generic; using System.Text; @@ -38,42 +40,51 @@ namespace SlnMesnac.Extensions { services.AddSingleton>(x => { + ISqlSugarClient sqlSugarClient = x.GetRequiredService(); AppConfig appConfig = x.GetService(); - List absractFactories = new List(); + List baseRfidInfos = sqlSugarClient.Queryable().Where(x=>x.Collectid == appConfig.StationCode).ToList(); + List sensor_Infos = sqlSugarClient.Queryable().Where(x => x.Deleteflag == 0).ToList(); + List absractFactories = new List(); try { - if (appConfig.rfidConfig != null) + foreach (var item in baseRfidInfos) { - foreach (var item in appConfig.rfidConfig) + if (item.Deleteflag == 0) { - if (item.isFlage) + int colonIndex = item.Connectstr.IndexOf(":"); + string IP = colonIndex != -1 ? item.Connectstr.Substring(0, colonIndex) : item.Connectstr; + string Port = colonIndex != -1 ? item.Connectstr.Substring(colonIndex + 1) : item.Connectstr; + RfidAbsractFactory _rfid = x.GetService(); + _rfid.ip = IP; + _rfid.port = int.Parse(Port); + _rfid.ConfigKey = sensor_Infos.Find(x => x.Deviceid == item.Deviceid).Combineid; + _rfid.FilterData = sensor_Infos.Find(x => x.Deviceid == item.Deviceid).Mapid; + //bool connectResult = _rfid.Connect(IP, int.Parse(Port)); + bool connectResult = false; + if (connectResult) { - RfidAbsractFactory _rfid = x.GetService(); - bool connectResult = _rfid.Connect(item.equipIp, item.equipPort); - if (connectResult) - { - Log.Information($"RFID:{item.equipIp}:{item.equipPort};连接成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); - _rfid.ConfigKey = item.equipKey; + //Log.Information($"RFID:{item.Connectstr};连接成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); + //_rfid.ConfigKey = item.equipKey; - if (absractFactories.Contains(_rfid)) - { - absractFactories.Remove(_rfid); - } - - absractFactories.Add(_rfid); - } - else + if (absractFactories.Contains(_rfid)) { - Log.Information($"RFID:{item.equipIp}:{item.equipPort};连接失败,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); + absractFactories.Remove(_rfid); } + absractFactories.Add(_rfid); + } + else + { + //Log.Information($"RFID:{item.Connectstr};连接失败,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); + if (absractFactories.Contains(_rfid)) + { + absractFactories.Remove(_rfid); + } + absractFactories.Add(_rfid); } } } - else - { - Log.Error("RFID配置信息为空"); - } + } catch (Exception e) { diff --git a/SlnMesnac.Model/domain/ApiResponse.cs b/SlnMesnac.Model/domain/ApiResponse.cs new file mode 100644 index 0000000..c8b2bf4 --- /dev/null +++ b/SlnMesnac.Model/domain/ApiResponse.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SlnMesnac.Model.domain +{ + public class ApiResponse + { + /// + /// 状态码(如 200 成功,400 失败,500 错误) + /// + public int Code { get; set; } + + /// + /// 消息(如 "操作成功"、"参数错误") + /// + public string Msg { get; set; } + + /// + /// 返回数据 + /// + public T Data { get; set; } + } +} diff --git a/SlnMesnac.Model/domain/Base_device_info.cs b/SlnMesnac.Model/domain/Base_device_info.cs new file mode 100644 index 0000000..0ba15fd --- /dev/null +++ b/SlnMesnac.Model/domain/Base_device_info.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using SqlSugar; +namespace Models +{ + /// + /// + /// + [SugarTable("base_device_info")] + public class Base_device_info + { + + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="deviceid" ,IsPrimaryKey = true) ] + public string Deviceid { get; set; } = null!; + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="name" ) ] + public string? Name { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="connectstr" ) ] + public string? Connectstr { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="connectmode" ) ] + public decimal? Connectmode { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="devicetype" ) ] + public string? Devicetype { get; set; } + + /// + /// 备 注:所属汇集软件ID + /// 默认值: + /// + [SugarColumn(ColumnName="collectid" ) ] + public string? Collectid { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="addr" ) ] + public string? Addr { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="mapid" ) ] + public string? Mapid { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="recordtime" ) ] + public DateTime? Recordtime { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="deleteflag" ) ] + public int? Deleteflag { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="recordperson" ) ] + public int? Recordperson { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="objid" ,IsIdentity = true) ] + public int Objid { get; set; } + + public string State = "未连接"; + + + } + +} \ No newline at end of file diff --git a/SlnMesnac.Model/domain/Base_sensor_info.cs b/SlnMesnac.Model/domain/Base_sensor_info.cs new file mode 100644 index 0000000..77a578f --- /dev/null +++ b/SlnMesnac.Model/domain/Base_sensor_info.cs @@ -0,0 +1,158 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using SqlSugar; +namespace Models +{ + /// + /// + /// + [SugarTable("base_sensor_info")] + public class Base_sensor_info + { + + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="sensorid" ,IsPrimaryKey = true) ] + public string Sensorid { get; set; } = null!; + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="combineid" ) ] + public string Combineid { get; set; } = null!; + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="name" ) ] + public string? Name { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="sensorser" ) ] + public decimal? Sensorser { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="sensortypeid" ) ] + public decimal? Sensortypeid { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="deviceid" ) ] + public string? Deviceid { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="readinterval" ) ] + public decimal? Readinterval { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="multdata" ) ] + public decimal? Multdata { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="timedout" ) ] + public decimal? Timedout { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="returnimm" ) ] + public decimal? Returnimm { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="mapid" ) ] + public string? Mapid { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="recordtime" ) ] + public DateTime? Recordtime { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="deleteflag" ) ] + public int? Deleteflag { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="recordperson" ) ] + public int? Recordperson { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="objid" ,IsIdentity = true) ] + public int Objid { get; set; } + + /// + /// 备 注:是否调用适配器 1是 2否 + /// 默认值: + /// + [SugarColumn(ColumnName="CallAdapter" ) ] + public decimal? CallAdapter { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="CallCombineID" ) ] + public string? CallCombineID { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="mesid" ) ] + public string? Mesid { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="DelayTime" ) ] + public string? DelayTime { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="ReadCounts" ) ] + public string? ReadCounts { get; set; } + + + } + +} \ No newline at end of file diff --git a/SlnMesnac.Model/domain/DeviceInfo.cs b/SlnMesnac.Model/domain/DeviceInfo.cs new file mode 100644 index 0000000..24da22e --- /dev/null +++ b/SlnMesnac.Model/domain/DeviceInfo.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Model.domain +{ + public class DeviceInfo + { + public string connectstr { get; set; } + + public string combineid { get; set; } + + public string addr { get; set; } + + public string port { get; set; } + } +} diff --git a/SlnMesnac.Model/domain/MesAlarmLightPara.cs b/SlnMesnac.Model/domain/MesAlarmLightPara.cs new file mode 100644 index 0000000..6ca9657 --- /dev/null +++ b/SlnMesnac.Model/domain/MesAlarmLightPara.cs @@ -0,0 +1,12 @@ +namespace SlnMesnac.Model.domain +{ + public class MesAlarmLightPara + { + public string EQUID { get; set; } + public string Sendtime { get; set; } + + public string Code { get; set; } + + public string msg { get; set; } + } +} \ No newline at end of file diff --git a/SlnMesnac.Model/domain/MesParaData.cs b/SlnMesnac.Model/domain/MesParaData.cs new file mode 100644 index 0000000..5b3b077 --- /dev/null +++ b/SlnMesnac.Model/domain/MesParaData.cs @@ -0,0 +1,15 @@ +namespace SlnMesnac.Model.domain +{ + public class MesParaData + { + public MesParaData() + { + } + + public string EQUID { get; set; } + public string EPCID { get; set; } + public string READSTATUS { get; set; } + public string ERRORMSG { get; set; } + public string READTIME { get; set; } + } +} \ No newline at end of file diff --git a/SlnMesnac.Model/domain/MesReadPara.cs b/SlnMesnac.Model/domain/MesReadPara.cs new file mode 100644 index 0000000..f64af4c --- /dev/null +++ b/SlnMesnac.Model/domain/MesReadPara.cs @@ -0,0 +1,10 @@ +namespace SlnMesnac.Model.domain +{ + public class MesReadPara + { + public string EQUID { get; set; } + public string requesttime { get; set; } + + + } +} \ No newline at end of file diff --git a/SlnMesnac.Model/domain/MesReadRespon.cs b/SlnMesnac.Model/domain/MesReadRespon.cs new file mode 100644 index 0000000..57968e4 --- /dev/null +++ b/SlnMesnac.Model/domain/MesReadRespon.cs @@ -0,0 +1,10 @@ +namespace SlnMesnac.Model.domain +{ + public class MesReadRespon + { + public string EPCID { get; set; } + public string Respontime { get; set; } + + + } +} \ No newline at end of file diff --git a/SlnMesnac.Model/domain/RFIDDeviceApiResponse.cs b/SlnMesnac.Model/domain/RFIDDeviceApiResponse.cs new file mode 100644 index 0000000..2353188 --- /dev/null +++ b/SlnMesnac.Model/domain/RFIDDeviceApiResponse.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SlnMesnac.Model.domain +{ + public class RFIDDeviceApiResponse + { + /// + /// 状态码(如 200 成功,400 失败,500 错误) + /// + public int Code { get; set; } + + /// + /// 消息(如 "操作成功"、"参数错误") + /// + public string Msg { get; set; } + + /// + /// 返回数据 + /// + public List Data { get; set; } + } +} diff --git a/SlnMesnac.Model/domain/RFIDDeviceInfo.cs b/SlnMesnac.Model/domain/RFIDDeviceInfo.cs new file mode 100644 index 0000000..12a1c97 --- /dev/null +++ b/SlnMesnac.Model/domain/RFIDDeviceInfo.cs @@ -0,0 +1,10 @@ +namespace SlnMesnac.Model.domain +{ + public class RFIDDeviceInfo + { + public string IPAddress { get; set; } + public string EQUID { get; set; } + public string position { get; set; } + public string ApiPort { get; set; } + } +} \ No newline at end of file diff --git a/SlnMesnac.Model/domain/Real_mesdata.cs b/SlnMesnac.Model/domain/Real_mesdata.cs new file mode 100644 index 0000000..8077fca --- /dev/null +++ b/SlnMesnac.Model/domain/Real_mesdata.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using SqlSugar; +namespace Models +{ + /// + /// + /// + [SugarTable("real_mesdata")] + public class Real_mesdata + { + + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="combineid" ) ] + public string? Combineid { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="tm" ) ] + public DateTime? Tm { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="data" ) ] + public string? Data { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="response" ) ] + public string? Response { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="reportmode" ) ] + public decimal? Reportmode { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="edittime" ) ] + public DateTime? Edittime { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="deleteflag" ) ] + public int? Deleteflag { get; set; } + + + } + +} \ No newline at end of file diff --git a/SlnMesnac.Model/domain/Real_workdata.cs b/SlnMesnac.Model/domain/Real_workdata.cs new file mode 100644 index 0000000..815a8d2 --- /dev/null +++ b/SlnMesnac.Model/domain/Real_workdata.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using SqlSugar; +namespace Models +{ + /// + /// + /// + [SugarTable("real_workdata")] + public class Real_workdata + { + + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="combineid" ) ] + public string? Combineid { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="tm" ) ] + public DateTime? Tm { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="data" ) ] + public string? Data { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="reportmode" ) ] + public decimal? Reportmode { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="edittime" ) ] + public DateTime? Edittime { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + [SugarColumn(ColumnName="deleteflag" ) ] + public int? Deleteflag { get; set; } + + + } + +} \ No newline at end of file diff --git a/SlnMesnac.Repository/service/IReal_mesdataService.cs b/SlnMesnac.Repository/service/IReal_mesdataService.cs new file mode 100644 index 0000000..6a25b79 --- /dev/null +++ b/SlnMesnac.Repository/service/IReal_mesdataService.cs @@ -0,0 +1,15 @@ +using Models; +using SlnMesnac.Model.domain; +using SlnMesnac.Repository.service.@base; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace SlnMesnac.Repository.service +{ + public interface IReal_mesdataService : IBaseService + { + Task AddAsync(Real_mesdata record); + } +} \ No newline at end of file diff --git a/SlnMesnac.Repository/service/IReal_workdataService.cs b/SlnMesnac.Repository/service/IReal_workdataService.cs new file mode 100644 index 0000000..0ab7d55 --- /dev/null +++ b/SlnMesnac.Repository/service/IReal_workdataService.cs @@ -0,0 +1,19 @@ +using Models; +using SlnMesnac.Model.domain; +using SlnMesnac.Repository.service.@base; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace SlnMesnac.Repository.service +{ + public interface IReal_workdataService : IBaseService + { + Task AddAsync(Real_workdata record); + + List GetDeviceInfos(); + + string GetPort(string collectid); + } +} \ No newline at end of file diff --git a/SlnMesnac.Repository/service/Impl/Real_mesdataServiceImpl.cs b/SlnMesnac.Repository/service/Impl/Real_mesdataServiceImpl.cs new file mode 100644 index 0000000..112ae45 --- /dev/null +++ b/SlnMesnac.Repository/service/Impl/Real_mesdataServiceImpl.cs @@ -0,0 +1,26 @@ +using ATC_MaterialBind.Entity; +using Models; +using SlnMesnac.Model.domain; +using SlnMesnac.Repository.service.@base; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace SlnMesnac.Repository.service.Impl +{ + public class Real_mesdataServiceImpl : BaseServiceImpl, IReal_mesdataService + { + public Real_mesdataServiceImpl(Repository repository):base(repository) + { + } + + public async Task AddAsync(Real_mesdata record) + { + var newDb = _rep.CopyNew(); + + bool result = await newDb.InsertAsync(record); + return result; + } + } +} \ No newline at end of file diff --git a/SlnMesnac.Repository/service/Impl/Real_workdataServiceImpl.cs b/SlnMesnac.Repository/service/Impl/Real_workdataServiceImpl.cs new file mode 100644 index 0000000..75eed7f --- /dev/null +++ b/SlnMesnac.Repository/service/Impl/Real_workdataServiceImpl.cs @@ -0,0 +1,56 @@ +using ATC_MaterialBind.Entity; +using Models; +using SlnMesnac.Model.domain; +using SlnMesnac.Repository.service.@base; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace SlnMesnac.Repository.service.Impl +{ + public class Real_workdataServiceImpl : BaseServiceImpl, IReal_workdataService + { + public Real_workdataServiceImpl(Repository repository):base(repository) + { + } + + public async Task AddAsync(Real_workdata record) + { + var newDb = _rep.CopyNew(); + bool result = await newDb.InsertAsync(record); + return result; + } + + public List GetDeviceInfos() + { + List taskInfos = null; + try + { + String sql = "select t1.connectstr, t2.combineid,t1.addr,t3.port from base_device_info t1 left join [dbo].[base_sensor_info] t2 on t1.deviceid = t2.deviceid left join [dbo].[base_collect_info] t3 on t1.collectid = t3.collectId where t1.deleteflag != 1 "; + taskInfos = base._rep.AsTenant().GetConnection("mes").Ado.SqlQuery(sql); + } + catch (Exception ex) + { + + } + return taskInfos; + } + + public string GetPort(string collectid) + { + string port = "9880"; + try + { + List device = new List(); + String sql = " SELECT [port] FROM [WLDB].[dbo].[base_collect_info] where deleteflag != 1 and collectId = "+ collectid; + device = base._rep.AsTenant().GetConnection("mes").Ado.SqlQuery(sql); + return device[0].port; + } + catch (Exception ex) + { + return port; + } + } + } +} \ No newline at end of file diff --git a/SlnMesnac.Rfid/ApiServer.cs b/SlnMesnac.Rfid/ApiServer.cs new file mode 100644 index 0000000..87f3c36 --- /dev/null +++ b/SlnMesnac.Rfid/ApiServer.cs @@ -0,0 +1,271 @@ + +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Models; +using Nancy; +using SlnMesnac.Model.AirportApiEntity; +using SlnMesnac.Model.domain; +using SlnMesnac.Model.dto; +using SlnMesnac.Repository.service; +using SlnMesnac.Repository.service.@base; +using SlnMesnac.Rfid; +using SlnMesnac.Rfid.Factory; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; +using TouchSocket.Rpc; +using TouchSocket.WebApi; + +#region << 版 本 注 释 >> +/*-------------------------------------------------------------------- +* 版权所有 (c) 2024 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:T14-GEN3-7895 +* 命名空间:SlnMesnac.TouchSocket +* 唯一标识:649766cc-308e-4bf3-8d69-dea48ec40642 +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2024-09-04 10:51:54 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ +#endregion << 版 本 注 释 >> +namespace SlnMesnac.TouchSocket +{ + public class ApiServer: RpcServer + { + private ILogger _logger; + private List rfidAbsractFactory; + private List base_Sensor_Infos; + public static Action _RefreshLogMessageAction; + public static Action RefreshStateEvent; + private IReal_mesdataService _real_MesdataService; + private IReal_workdataService _real_WorkdataService; + + public ApiServer(ILogger logger, List rfidAbsractFactory, IReal_mesdataService real_MesdataService, IReal_workdataService real_WorkdataService) + { + _logger = logger; + this.rfidAbsractFactory = rfidAbsractFactory; + _real_MesdataService = real_MesdataService; + _real_WorkdataService = real_WorkdataService; + } + /// + /// 测试 + /// + /// + /// + [WebApi(Method = HttpMethodType.POST)] + public async Task> autoread() + { + + return new ApiResponse + { + Code = 200, + Data = null, + Msg = "sucess", + }; + + } + /// + /// 查询设备信息 + /// + /// + /// + [WebApi(Method = HttpMethodType.POST)] + public async Task> basedata(string Requesttime) + { + List rFIDDeviceInfos = _real_WorkdataService.GetDeviceInfos(); + return new RFIDDeviceApiResponse + { + Code = 200, + Data = rFIDDeviceInfos, + Msg = "sucess", + }; + + } + private bool iFlag = false; + /// + /// MES主动请求读取标签 + /// + /// + /// + /// + [WebApi(Method = HttpMethodType.POST)] + public async Task> read(MesReadPara mesReadPara) + { + ApiResponse response = new ApiResponse(); + int code = 400; + string Msg = "error"; + MesReadRespon mesReadRespon = new MesReadRespon(); + try + { + if (iFlag) + { + response = new ApiResponse() + { + Code = code, + Data = mesReadRespon, + Msg = Msg, + }; + return response; + } + // 设置标志位为 true,表示方法正在执行 + iFlag = true; + _RefreshLogMessageAction?.Invoke("接收MES主动读取指令" + JsonSerializer.Serialize(mesReadPara)); + _logger.LogInformation("接收MES主动读取指令{0}", JsonSerializer.Serialize(mesReadPara)); + + string FilterData = rfidAbsractFactory.Find(x => x.ConfigKey == mesReadPara.EQUID).FilterData; + List rfid = await rfidAbsractFactory.Find(x => x.ConfigKey == mesReadPara.EQUID).GetRFIDAsync(); + rfid = rfid.Where((x, i) => rfid.FindIndex(z => z.EPCstring == x.EPCstring) == i).ToList(); + //新增工位过滤 + if (!string.IsNullOrEmpty(FilterData)) + { + rfid = FilterByEPCString(rfid, FilterData); + } + if (rfid != null && rfid.Count > 0) + { + + if (rfid.Count > 1) + { + if (rfid != null && rfid.Any()) + { + mesReadRespon.EPCID = string.Join(",", rfid.Select(item => item.EPCstring)); + //mesReadRespon.EPCID = "MORE"; + Msg = "multiple EPC"; + } + } + else + { + mesReadRespon.EPCID = rfid[0].EPCstring; + code = 200; + Msg = "sucess"; + } + + mesReadRespon.Respontime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + Real_workdata real_Workdata = new Real_workdata() + { + Combineid = mesReadPara.EQUID.ToString(), + Data = mesReadRespon.EPCID, + Tm = DateTime.Now, + Deleteflag = 0, + Reportmode = 0, + Edittime = DateTime.Now, + }; + await _real_WorkdataService.AddAsync(real_Workdata); + + } + else + { + Msg = "nodata"; + } + response = new ApiResponse() + { + Code = code, + Data = mesReadRespon, + Msg = Msg, + }; + _RefreshLogMessageAction?.Invoke("发送MES主动读取指令" + JsonSerializer.Serialize(response)); + _logger.LogInformation("发送MES主动读取指令{0}", JsonSerializer.Serialize(response)); + Real_mesdata real_Mesdata = new Real_mesdata() + { + Combineid = mesReadPara.EQUID.ToString(), + Data = JsonSerializer.Serialize(mesReadPara), + Response = JsonSerializer.Serialize(response), + Reportmode = 0, + Edittime = DateTime.Now, + Tm = DateTime.Now, + Deleteflag = 0, + }; + + + //InsertRealMesData(mesReadPara.EQUID.ToString(), JsonSerializer.Serialize(mesReadPara), JsonSerializer.Serialize(response), 0); + RefreshStateEvent?.Invoke(mesReadPara.EQUID, mesReadRespon.EPCID); + await _real_MesdataService.AddAsync(real_Mesdata); + return response; + } + catch (Exception ex) + { + _logger.LogInformation("read接口异常" + ex.ToString()); + return response; + } + finally + { + iFlag = false; + } + + } + private static List FilterByEPCString(List tagList, string searchText) + { + return tagList + .Where(tag => tag.EPCstring != null && tag.EPCstring.Contains(searchText)) + .ToList(); + } + + + /// + /// MES主动回复处理结果,控制报警灯 + /// + /// + /// + /// + [WebApi(Method = HttpMethodType.POST)] + public async Task> revresult(MesAlarmLightPara mesAlarmLightPara) + { + ApiResponse response = new ApiResponse(); + _RefreshLogMessageAction?.Invoke("接收MES控制报警灯指令" + JsonSerializer.Serialize(mesAlarmLightPara)); + + _logger.LogInformation("接收MES控制报警灯指令{0}", JsonSerializer.Serialize(mesAlarmLightPara)); + + if (mesAlarmLightPara.Code == "0") + { + mesAlarmLightPara.Code = "2"; + } + else if (mesAlarmLightPara.Code == "1") + { + mesAlarmLightPara.Code = "3"; + } + else + { + mesAlarmLightPara.Code = "1"; + } + + await rfidAbsractFactory.Find(x => x.ConfigKey == mesAlarmLightPara.EQUID).WriteAlarmLight(int.Parse(mesAlarmLightPara.Code),10000); + //m_EquipClient.WriteAlarmLight(mesAlarmLightPara.EQUID, mesAlarmLightPara.Code); + + response = new ApiResponse() + { + Code = 200, + Data = null, + Msg = "sucess", + }; + _RefreshLogMessageAction?.Invoke("发送MES控制报警灯指令" + JsonSerializer.Serialize(response)); + _logger.LogInformation("发送MES控制报警灯指令{0}", JsonSerializer.Serialize(response)); + Real_mesdata real_Mesdata = new Real_mesdata() + { + Combineid = mesAlarmLightPara.EQUID.ToString(), + Data = JsonSerializer.Serialize(mesAlarmLightPara), + Response = JsonSerializer.Serialize(response), + Reportmode = 1, + Edittime = DateTime.Now, + Tm = DateTime.Now, + Deleteflag = 0, + }; + await _real_MesdataService.AddAsync(real_Mesdata); + //InsertRealMesData(mesAlarmLightPara.EQUID.ToString(), JsonSerializer.Serialize(mesAlarmLightPara), JsonSerializer.Serialize(response), 1); + return response; + } + } + +} diff --git a/SlnMesnac.Rfid/Factory/RflyFactory.cs b/SlnMesnac.Rfid/Factory/RflyFactory.cs index 27f015a..dfb8668 100644 --- a/SlnMesnac.Rfid/Factory/RflyFactory.cs +++ b/SlnMesnac.Rfid/Factory/RflyFactory.cs @@ -1,14 +1,20 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; +using Models; using SlnMesnac.Common; +using SlnMesnac.Model.domain; using SlnMesnac.Model.dto; +using SlnMesnac.Repository.service; using SlnMesnac.Rfid.Dto; using SlnMesnac.Rfid.Enum; +using SlnMesnac.TouchSocket; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; using TouchSocket.Core; using TouchSocket.Sockets; @@ -41,11 +47,15 @@ namespace SlnMesnac.Rfid.Factory private ILogger _logger; private readonly TcpClient _tcpClient = new TcpClient(); private readonly StringChange _stringChange; + private string m_strIP; + private string m_deviceID; + private MeshttpClient _meshttpClient; - public RflyFactory(ILogger logger,StringChange stringChange) + public RflyFactory(ILogger logger,StringChange stringChange, MeshttpClient meshttpClient) { _logger = logger; _stringChange = stringChange; + _meshttpClient = meshttpClient; } /// @@ -65,10 +75,62 @@ namespace SlnMesnac.Rfid.Factory } catch (Exception e) { - throw new InvalidOperationException($"设备连接异常:{e.Message}"); + return false; + //throw new InvalidOperationException($"设备连接异常:{e.Message}"); } } + /// + /// 异步建立连接 + /// + /// + /// + /// + public override async Task ConnectAsync(string ip, int port,string deviceid) + { + try + { + m_deviceID = deviceid; + m_strIP = ip; + _tcpClient.Setup(new TouchSocketConfig().SetRemoteIPHost($"{ip}:{port}")); + await _tcpClient.ConnectAsync(1500); + _tcpClient.Received = (client, e) => + { + //从客户端收到信息 + var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意:数据长度是byteBlock.Len + byte[] receivedBuffer = new byte[e.ByteBlock.Len]; + Array.Copy(e.ByteBlock.Buffer, 0, receivedBuffer, 0, e.ByteBlock.Len); + byte[] resultBuffer = PareReceiveBufferData(receivedBuffer, receivedBuffer.Length); + List tagInfoList = Device_DealTagInfoList(resultBuffer); + string info = ""; + if (tagInfoList!=null && tagInfoList.Count > 0) + { + tagInfoList = tagInfoList.Where((x, i) => tagInfoList.FindIndex(z => z.EPCstring == x.EPCstring) == i).ToList(); + info = string.Join(",", tagInfoList.Select(item => item.EPCstring)); + } + else + { + info = "Nodata"; + } + MesParaData mesParaData = new MesParaData() + { + EQUID = deviceid, + EPCID = info, + READSTATUS = info == "NoData" ? "1" : "0", + READTIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + }; + _meshttpClient.autoread(mesParaData); + //ReceivedClientBufferEvent?.Invoke(receivedBuffer); + + return EasyTask.CompletedTask; + }; + return true; + } + catch (Exception e) + { + return false; + } + } /// /// 按时间段盘点 /// @@ -119,6 +181,301 @@ namespace SlnMesnac.Rfid.Factory throw new InvalidOperationException($"按时间段盘点异常:{e.Message}"); } } + /// + /// 异步按时间段盘点 + /// + /// + /// + /// + public override async Task> GetRFIDAsync(int timeout = 1500) + { + List tagInfoList = new List(); + byte[] u16byte = new byte[2]; + byte[] bCRC = new byte[4]; + try + { + #region 指令封装 + + MessagePack pMessagePack = new MessagePack(); + pMessagePack.m_pData = new byte[8]; + pMessagePack.m_pData[0] = 0xAA; + pMessagePack.m_pData[1] = 0x55; + pMessagePack.m_pData[2] = 0x02; + pMessagePack.m_pData[3] = 0x02; + //1s + pMessagePack.m_pData[4] = 0x03; + pMessagePack.m_pData[5] = 0xE8; + //2s + //pMessagePack.m_pData[4] = 0x07; + //pMessagePack.m_pData[5] = 0xD0; + //3s + //pMessagePack.m_pData[4] = 0x0B; + //pMessagePack.m_pData[5] = 0xA0; + + Array.Copy(pMessagePack.m_pData, 2, bCRC, 0, 4); + pMessagePack.m_pData[6] = _stringChange.CalculateVerify(bCRC, bCRC.Length); + pMessagePack.m_pData[7] = 0x0D; + + #endregion 指令封装 + + var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions() + { + FilterFunc = response => + { + // 检查响应数据是否符合预期 + if (response.Data != null && response.Data.Length > 0) + { + // 可以根据实际情况添加更多的检查逻辑 + return true; + } + return false; + } + }); + + byte[] reciveBuffer = await waitClient.SendThenReturnAsync(pMessagePack.m_pData, timeout); + _logger.LogInformation($"{m_deviceID}发送读取指令{_stringChange.bytesToHexStr(pMessagePack.m_pData,pMessagePack.m_pData.Length)}"); + + byte[] resultBuffer = PareReceiveBufferData(reciveBuffer, reciveBuffer.Length); + _logger.LogInformation($"{m_deviceID}接收读取指令{_stringChange.bytesToHexStr(resultBuffer,resultBuffer.Length)}"); + + tagInfoList = Device_DealTagInfoList(resultBuffer); + + return tagInfoList; + } + catch (Exception e) + { + return tagInfoList; + //throw new InvalidOperationException($"{m_strIP}按时间段盘点异常:{e.Message}"); + } + } + + /// + /// 设置GPIO + /// + /// + /// + /// + /// + public override async Task WriteAlarmLight(int port, UInt16 Timedout) + { + byte[] u16byte = new byte[2]; + byte[] bCRC = new byte[6]; + try + { + #region 指令封装 + + MessagePack pMessagePack = new MessagePack(); + pMessagePack.m_pData = new byte[10]; + pMessagePack.m_pData[0] = 0xAA; + pMessagePack.m_pData[1] = 0x55; + pMessagePack.m_pData[2] = 0x04; + pMessagePack.m_pData[3] = 0x51; + pMessagePack.m_pData[4] = (byte)port; + pMessagePack.m_pData[5] = 0x00; + u16byte = BitConverter.GetBytes(Timedout); //超时时间 + u16byte = _stringChange.Swap16Bytes(u16byte); //协议里为大端在前 + Array.Copy(u16byte, 0, pMessagePack.m_pData, 6, 2); + Array.Copy(pMessagePack.m_pData, 2, bCRC, 0, 6); + pMessagePack.m_pData[8] = _stringChange.CalculateVerify(bCRC, bCRC.Length); + pMessagePack.m_pData[9] = 0x0D; + + #endregion 指令封装 + + var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions() + { + FilterFunc = response => + { + // 检查响应数据是否符合预期 + if (response.Data != null && response.Data.Length > 0) + { + // 可以根据实际情况添加更多的检查逻辑 + return true; + } + return false; + } + }); + + byte[] reciveBuffer = await waitClient.SendThenReturnAsync(pMessagePack.m_pData, 2000); + + //byte[] resultBuffer = PareReceiveBufferData(reciveBuffer, reciveBuffer.Length); + + if (reciveBuffer[3] == 0x51) + { + return true; + } + + return false; + } + catch (Exception e) + { + throw new InvalidOperationException($"{m_strIP}设置GPIO异常:{e.Message}"); + } + } + + /// + /// 设置功率 + /// + /// + /// + public override async Task Set_Rf(int iDbi) + { + byte[] u16byte = new byte[2]; + byte[] bCRC = new byte[22]; + try + { + #region 指令封装 + iDbi = iDbi * 100; + MessagePack pMessagePack = new MessagePack(); + pMessagePack.m_pData = new byte[26]; + pMessagePack.m_pData[0] = 0xAA; + pMessagePack.m_pData[1] = 0x55; + pMessagePack.m_pData[2] = 0x14; + pMessagePack.m_pData[3] = 0x42; + pMessagePack.m_pData[4] = 0x01; + u16byte = BitConverter.GetBytes(iDbi); //功率 + u16byte = _stringChange.Swap16Bytes(u16byte); //协议里为大端在前 + Array.Copy(u16byte, 0, pMessagePack.m_pData, 5, 2); + u16byte = BitConverter.GetBytes(iDbi); //功率 + u16byte = _stringChange.Swap16Bytes(u16byte); //协议里为大端在前 + Array.Copy(u16byte, 0, pMessagePack.m_pData, 7, 2); + + pMessagePack.m_pData[9] = 0x02; + u16byte = BitConverter.GetBytes(iDbi); //功率 + u16byte = _stringChange.Swap16Bytes(u16byte); //协议里为大端在前 + Array.Copy(u16byte, 0, pMessagePack.m_pData, 10, 2); + u16byte = BitConverter.GetBytes(iDbi); //功率 + u16byte = _stringChange.Swap16Bytes(u16byte); //协议里为大端在前 + Array.Copy(u16byte, 0, pMessagePack.m_pData, 12, 2); + pMessagePack.m_pData[14] = 0x03; + u16byte = BitConverter.GetBytes(iDbi); //功率 + u16byte = _stringChange.Swap16Bytes(u16byte); //协议里为大端在前 + Array.Copy(u16byte, 0, pMessagePack.m_pData, 15, 2); + u16byte = BitConverter.GetBytes(iDbi); //功率 + u16byte = _stringChange.Swap16Bytes(u16byte); //协议里为大端在前 + Array.Copy(u16byte, 0, pMessagePack.m_pData, 17, 2); + pMessagePack.m_pData[19] = 0x04; + u16byte = BitConverter.GetBytes(iDbi); //功率 + u16byte = _stringChange.Swap16Bytes(u16byte); //协议里为大端在前 + Array.Copy(u16byte, 0, pMessagePack.m_pData, 20, 2); + u16byte = BitConverter.GetBytes(iDbi); //功率 + u16byte = _stringChange.Swap16Bytes(u16byte); //协议里为大端在前 + Array.Copy(u16byte, 0, pMessagePack.m_pData, 22, 2); + Array.Copy(pMessagePack.m_pData, 2, bCRC, 0, 22); + pMessagePack.m_pData[24] = _stringChange.CalculateVerify(bCRC, bCRC.Length); + pMessagePack.m_pData[25] = 0x0D; + #endregion 指令封装 + + var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions() + { + FilterFunc = response => + { + // 检查响应数据是否符合预期 + if (response.Data != null && response.Data.Length > 0) + { + // 可以根据实际情况添加更多的检查逻辑 + return true; + } + return false; + } + }); + _logger.LogInformation($"{m_deviceID}发送修改功率指令{_stringChange.bytesToHexStr(pMessagePack.m_pData, pMessagePack.m_pData.Length)}"); + + byte[] reciveBuffer = await waitClient.SendThenReturnAsync(pMessagePack.m_pData, 2000); + _logger.LogInformation($"{m_deviceID}接收修改功率指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}"); + //byte[] resultBuffer = PareReceiveBufferData(reciveBuffer, reciveBuffer.Length); + + if (reciveBuffer[3] == 0x42) + { + return true; + } + + return false; + } + catch (Exception e) + { + return false; + //throw new InvalidOperationException($"{m_strIP}设置功率异常:{e.Message}"); + } + } + + public override async Task Get_Rf() + { + int DB = 0; + byte[] u16byte = new byte[2]; + byte[] bCRC = new byte[2]; + try + { + #region 指令封装 + + MessagePack pMessagePack = new MessagePack(); + pMessagePack.m_pData = new byte[6]; + pMessagePack.m_pData[0] = 0xAA; + pMessagePack.m_pData[1] = 0x55; + pMessagePack.m_pData[2] = 0x00; + pMessagePack.m_pData[3] = 0x72; + Array.Copy(pMessagePack.m_pData, 2, bCRC, 0, 2); + pMessagePack.m_pData[4] = _stringChange.CalculateVerify(bCRC, bCRC.Length); + pMessagePack.m_pData[5] = 0x0D; + #endregion 指令封装 + + var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions() + { + FilterFunc = response => + { + // 检查响应数据是否符合预期 + if (response.Data != null && response.Data.Length > 0) + { + // 可以根据实际情况添加更多的检查逻辑 + return true; + } + return false; + } + }); + + byte[] reciveBuffer = await waitClient.SendThenReturnAsync(pMessagePack.m_pData, 2000); + + if (reciveBuffer[3] == 0x72) + { + byte[] bDB = new byte[2]; + bDB[0] = reciveBuffer[6]; + bDB[1] = reciveBuffer[7]; + DB = Convert.ToInt32(_stringChange.bytesToHexStr(bDB, 2), 16) / 100; + return DB; + } + + return DB; + } + catch (Exception e) + { + return DB; + //throw new InvalidOperationException($"{m_strIP}设置功率异常:{e.Message}"); + } + } + + public override bool GetOnlineStatus() + { + try + { + return _tcpClient.Online; + } + catch (Exception e) + { + return false; + } + } + + public override void Close() + { + try + { + _tcpClient.SafeDispose(); + } + catch (Exception ex) + { + + throw; + } + } #region 标签解析 @@ -188,6 +545,18 @@ namespace SlnMesnac.Rfid.Factory m_iPosition++; enumRecvState = RecvState.WaitingForStus_State; } + else if (buffer[i] == 0x42) + { + m_szFullMessage[m_iPosition] = buffer[i]; + m_iPosition++; + enumRecvState = RecvState.WaitingForStus_State; + } + else if (buffer[i] == 0x72) + { + m_szFullMessage[m_iPosition] = buffer[i]; + m_iPosition++; + enumRecvState = RecvState.WaitingForStus_State; + } else if (buffer[i] == 0x90) // 如果是心跳BB DD 01 90 00 1F 8E 0D { m_szFullMessage[m_iPosition] = buffer[i]; @@ -333,7 +702,7 @@ namespace SlnMesnac.Rfid.Factory } } - private Mutex mutauto = new Mutex(); + //private Mutex mutauto = new Mutex(); /// /// 解析函数 /// @@ -348,7 +717,7 @@ namespace SlnMesnac.Rfid.Factory int m_readEPCDataLen = 0; try { - mutauto.WaitOne(); + //mutauto.WaitOne(); int iFirstCountPos = 6; //第一次读取标签次数位置 int iFirstRSSIPos = 7; //第一次读取标签强度位置 int iFirstAnt = 8; @@ -358,7 +727,7 @@ namespace SlnMesnac.Rfid.Factory int tempDataRSSI = 0; UInt16 tempDataANT = 0; int iBarcodeGroupCount = Convert.ToInt32(AutoDealReportData[5].ToString()); //标签组数 - int iBarcodeLength = 16; //标签长度 + int iBarcodeLength = 12; //标签长度 int iCommonSecondFlag = 0; for (int j = 0; j < iBarcodeGroupCount; j++) { @@ -367,8 +736,11 @@ namespace SlnMesnac.Rfid.Factory Array.Clear(tempPCByte, 0, 2); Array.Copy(AutoDealReportData, iFirstPC, tempPCByte, 0, 2); - int pc = Convert.ToInt32(tempPCByte[0].ToString("X")); - int epcLength = EPCLengthByPC(pc); + //int pc = Convert.ToInt32(tempPCByte[0].ToString("X")); + //PC转二进制取前五位转十进制 + int epcLength = Convert.ToInt32(Convert.ToString(Convert.ToInt64(tempPCByte[0].ToString("X"), 16), 2).PadLeft(8, '0').Substring(0, 5), 2) * 2; + + //int epcLength = EPCLengthByPC(pc); iBarcodeLength = epcLength; byte[] tempDataByte = new byte[epcLength]; @@ -396,15 +768,7 @@ namespace SlnMesnac.Rfid.Factory tag.Count = tempDataCount; tag.RSSI = tempDataRSSI; tag.EPC = tempDataByte; - - if (pc == 24) - { - tag.EPCstring = _stringChange.bytesToHexStr(tempDataByte, tempDataByte.Length).Substring(0, 7); - } - else - { - tag.EPCstring = Encoding.ASCII.GetString(tempDataByte); - } + tag.EPCstring = _stringChange.bytesToHexStr(tempDataByte, tempDataByte.Length).Substring(0,8); tag.PC = tempPCByte; tag.Antana = tempDataANT; @@ -417,12 +781,12 @@ namespace SlnMesnac.Rfid.Factory iFirstPC = iFirstAnt + 1; iFirstLeftBarcketPos = iFirstLeftBarcketPos + iBarcodeLength + 5; - _logger.LogInformation("----函数调用:Device_DealTagInfoList 第[" + (iCommonSecondFlag + 1) + "]次数据解析为:" + tag.EPCstring + ",读取标签次数:[" + tempDataCount + "],标签信号强度:[" + tempDataRSSI + "],天线号:[" + tempDataANT + "]"); + _logger.LogInformation($"----{m_deviceID}函数调用:Device_DealTagInfoList 第[" + (iCommonSecondFlag + 1) + "]次数据解析为:" + tag.EPCstring + ",读取标签次数:[" + tempDataCount + "],标签信号强度:[" + tempDataRSSI + "],天线号:[" + tempDataANT + "]"); iCommonSecondFlag++; if (iCommonSecondFlag == iBarcodeGroupCount) { - mutauto.ReleaseMutex(); - _logger.LogInformation("《《《返回标签数据!"); + //mutauto.ReleaseMutex(); + //_logger.LogInformation("《《《返回标签数据!"); return tagInfoList; } } @@ -430,7 +794,7 @@ namespace SlnMesnac.Rfid.Factory } catch (Exception ex) { - mutauto.ReleaseMutex(); + //mutauto.ReleaseMutex(); throw new InvalidOperationException($"Device_AutoDealContent 自动处理函数异常:{ex.Message}"); } } @@ -478,6 +842,7 @@ namespace SlnMesnac.Rfid.Factory return epcLength; } + #endregion } } \ No newline at end of file diff --git a/SlnMesnac.Rfid/MeshttpClient.cs b/SlnMesnac.Rfid/MeshttpClient.cs new file mode 100644 index 0000000..5fd55c2 --- /dev/null +++ b/SlnMesnac.Rfid/MeshttpClient.cs @@ -0,0 +1,111 @@ +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Nancy; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Serilog; +using Serilog.Events; +using SlnMesnac.Config; +using SlnMesnac.Model.AirportApiEntity; +using SlnMesnac.Model.domain; +using SQLitePCL; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using TouchSocket.Rpc; +using TouchSocket.Sockets; +using TouchSocket.WebApi; +using JsonSerializer = System.Text.Json.JsonSerializer; + +namespace SlnMesnac.TouchSocket +{ + public class MeshttpClient + { + private readonly AppConfig _appConfig; + private readonly ILogger _logger; + public static Action RefreshStateEvent; + public static Action _RefreshLogMessageAction; + public MeshttpClient(AppConfig appConfig, ILogger logger) + { + _appConfig = appConfig; + _logger = logger; + } + + public static WebApiClient MESHttpClient; + + public WebApiClient CreateWebApiClient(string IpHost) + { + MESHttpClient = new WebApiClient(); + try + { + _logger.LogInformation("正在连接:" + IpHost); + MESHttpClient.Connect(IpHost); + _logger.LogInformation(IpHost + "连接成功"); + return MESHttpClient; + } + catch (Exception ex) + { + _logger.LogError("ERROR: " + ex.Message); + return null; + } + } + + + /// + /// 获取到的JToken类型转换为实体类 + /// + /// + /// + /// + public T JTokenToEntity(JToken value) where T : class + { + if (value == null) + { + return null; + } + string json = value.ToString(); + if (string.IsNullOrEmpty(json)) + { + return null; + } + T ResponseEntity; + ResponseEntity = JsonSerializer.Deserialize(json); + return ResponseEntity; + } + + /// + /// 主动上报 + /// + /// + /// + public ApiResponse autoread(MesParaData requestValue) + { + try + { + if (MESHttpClient == null) + { + return null; + } + JToken responseValue = MESHttpClient.InvokeT("POST:/autoread", null, requestValue); + //JToken responseValue = MESHttpClient.InvokeT("POST:/ApiServer/autoread", null, requestValue); + _RefreshLogMessageAction?.Invoke("发送MES自动读取指令"+JsonSerializer.Serialize(requestValue)); + _logger.LogInformation("发送MES自动读取指令{0}", JsonSerializer.Serialize(requestValue)); + + RefreshStateEvent?.Invoke(requestValue.EQUID,requestValue.EPCID); + return JTokenToEntity>(responseValue); + } + catch (Exception ex) + { + _logger.LogError("ERROR: " + ex.Message); + return new ApiResponse(); + } + + } + + } + +} diff --git a/SlnMesnac.Rfid/RfidAbsractFactory.cs b/SlnMesnac.Rfid/RfidAbsractFactory.cs index 2a2c1b7..0cf4329 100644 --- a/SlnMesnac.Rfid/RfidAbsractFactory.cs +++ b/SlnMesnac.Rfid/RfidAbsractFactory.cs @@ -1,6 +1,7 @@ -using System; +using SlnMesnac.Model.dto; +using System; using System.Collections.Generic; -using SlnMesnac.Model.dto; +using System.Threading.Tasks; #region << 版 本 注 释 >> /*-------------------------------------------------------------------- @@ -31,9 +32,17 @@ namespace SlnMesnac.Rfid /// public abstract class RfidAbsractFactory { - + public string FilterData; + public string ip; + public int port; public string ConfigKey { get; set; } - + /// + /// 异步建立连接 + /// + /// + /// + /// + public abstract Task ConnectAsync(string ip, int port,string deviceid); /// /// 建立连接 /// @@ -41,12 +50,41 @@ namespace SlnMesnac.Rfid /// /// public abstract bool Connect(string ip, int port); + /// + /// 获取设备在线状态 + /// + /// + /// + /// + public abstract bool GetOnlineStatus(); + public abstract void Close(); /// /// 按时间段盘点 /// /// /// - public abstract List TimePeriodRead(int timeout = 5000); + public abstract List TimePeriodRead(int timeout = 3000); + + /// + /// 使用--异步按时间段盘点 + /// + /// + /// + /// + public abstract Task> GetRFIDAsync(int timeout = 1500); + + /// + /// 设置GPIO + /// + /// + /// + /// + public abstract Task WriteAlarmLight(int port, UInt16 Timedout); + + public abstract Task Set_Rf(int iDbi); + + public abstract Task Get_Rf(); + } } \ No newline at end of file diff --git a/SlnMesnac.Rfid/SlnMesnac.Rfid.csproj b/SlnMesnac.Rfid/SlnMesnac.Rfid.csproj index ac2b62d..8652722 100644 --- a/SlnMesnac.Rfid/SlnMesnac.Rfid.csproj +++ b/SlnMesnac.Rfid/SlnMesnac.Rfid.csproj @@ -8,6 +8,7 @@ + diff --git a/SlnMesnac.TouchSocket/TouchSocketSetup.cs b/SlnMesnac.Rfid/TouchSocketSetup.cs similarity index 79% rename from SlnMesnac.TouchSocket/TouchSocketSetup.cs rename to SlnMesnac.Rfid/TouchSocketSetup.cs index 374dfbb..157b13b 100644 --- a/SlnMesnac.TouchSocket/TouchSocketSetup.cs +++ b/SlnMesnac.Rfid/TouchSocketSetup.cs @@ -39,11 +39,13 @@ namespace SlnMesnac.TouchSocket public static IApplicationBuilder UseTouchSocketExtensions(this IApplicationBuilder app) { - var _server = app.ApplicationServices.GetService(); - var _httpclient = app.ApplicationServices.GetService(); - + //var _server = app.ApplicationServices.GetService(); + var _httpclient = app.ApplicationServices.GetService(); + var _apiServer = app.ApplicationServices.GetService(); + _apiServer.Init(); //_server.Init(6001); - //_httpclient.init(); + _httpclient.CreateWebApiClient("172.16.0.106:9880"); + //_httpclient.CreateWebApiClient("127.0.0.1:9880"); return app; } } diff --git a/SlnMesnac.TouchSocket/WebApiServer.cs b/SlnMesnac.Rfid/WebApiServer.cs similarity index 84% rename from SlnMesnac.TouchSocket/WebApiServer.cs rename to SlnMesnac.Rfid/WebApiServer.cs index 219b2d0..cd57a9e 100644 --- a/SlnMesnac.TouchSocket/WebApiServer.cs +++ b/SlnMesnac.Rfid/WebApiServer.cs @@ -1,4 +1,6 @@ -using System; +using SlnMesnac.Config; +using SlnMesnac.Repository.service; +using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; @@ -35,19 +37,24 @@ namespace SlnMesnac.TouchSocket public class WebApiServer { private ApiServer _apiServer; - - public WebApiServer(ApiServer apiServer) + private readonly AppConfig _appConfig; + private IReal_workdataService _real_WorkdataService; + public WebApiServer(ApiServer apiServer, AppConfig appConfig, IReal_workdataService real_WorkdataService) { _apiServer = apiServer; + _real_WorkdataService = real_WorkdataService; + _appConfig = appConfig; } public void Init() { try { + //获取汇集软件服务端口号 + string port = _real_WorkdataService.GetPort(_appConfig.StationCode); var service = new HttpService(); service.Setup(new TouchSocketConfig() - .SetListenIPHosts(7789) + .SetListenIPHosts(int.Parse(port)) .ConfigureContainer(a => { a.AddRpcStore(store => diff --git a/SlnMesnac.TouchSocket/AirPorthttpClient.cs b/SlnMesnac.TouchSocket/AirPorthttpClient.cs deleted file mode 100644 index 1ca9a79..0000000 --- a/SlnMesnac.TouchSocket/AirPorthttpClient.cs +++ /dev/null @@ -1,167 +0,0 @@ -using Microsoft.Extensions.Hosting; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using SlnMesnac.Config; -using SlnMesnac.Model.AirportApiEntity; -using SQLitePCL; -using SqlSugar; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Text.Json; -using TouchSocket.Rpc; -using TouchSocket.Sockets; -using TouchSocket.WebApi; -using JsonSerializer = System.Text.Json.JsonSerializer; -using Serilog; -using Serilog.Events; -using Microsoft.Extensions.Logging; - -namespace SlnMesnac.TouchSocket -{ - public class AirPorthttpClient - { - private readonly AppConfig _appConfig; - private readonly ILogger _logger; - - public AirPorthttpClient(AppConfig appConfig, ILogger logger) - { - _appConfig = appConfig; - _logger = logger; - } - - public static WebApiClient AirportAGVClient; - - private WebApiClient CreateWebApiClient(string IpHost) - { - var client = new WebApiClient(); - try - { - _logger.LogInformation("正在连接:" + IpHost); - client.Connect(IpHost); - _logger.LogInformation(IpHost + "连接成功"); - return client; - } - catch (Exception ex) - { - _logger.LogError("ERROR: " + ex.Message); - return null; - } - } - - - /// - /// 获取到的JToken类型转换为实体类 - /// - /// - /// - /// - public T JTokenToEntity(JToken value) where T : class - { - if (value == null) - { - return null; - } - string json = value.ToString(); - if (string.IsNullOrEmpty(json)) - { - return null; - } - T ResponseEntity; - ResponseEntity = JsonSerializer.Deserialize(json); - return ResponseEntity; - } - - /// - /// AGV下发任务请求 - /// - /// - /// - public AGVResponseEntity AGVAddTaskRequest(AGVRequestAddTaskEntity requestValue) - { - if (AirportAGVClient == null) - { - return null; - } - JToken responseValue = AirportAGVClient.InvokeT("POST:/api/task/addTask", null, requestValue); - return JTokenToEntity>(responseValue); - } - - /// - /// 取消/终止任务请求 - /// - /// - /// - public AGVResponseEntity AGVOperationalTaskRequest(AGVRequestOperationalTaskEntity requestValue) - { - if (AirportAGVClient == null) - { - return null; - } - JToken responseValue = AirportAGVClient.InvokeT("POST:/api/task/operationalTask", null, requestValue); - return JTokenToEntity>(responseValue); - } - - /// - /// 查询任务状态请求 - /// - /// - /// - public AGVResponseEntity AGVGetTaskStateDetailRequest(AGVRequestTaskStateDetailEntity requestValue) - { - if (AirportAGVClient == null) - { - return null; - } - JToken responseValue = AirportAGVClient.InvokeT("PUT:/api/task/getTaskStateDetail", null, requestValue); - return JTokenToEntity>(responseValue); - } - - /// - /// 获取所有AGV信息请求 - /// - /// - public AGVResponseEntity> AGVAllStateRequest() - { - if (AirportAGVClient == null) - { - return null; - } - JToken responseValue = AirportAGVClient.InvokeT("GET:/api/task/robot/getRobot", null); - return JTokenToEntity>>(responseValue); - } - - /// - /// 获取当前激活地图信息请求 - /// - /// - public AGVResponseEntity AGVMapActiveRequest() - { - if (AirportAGVClient == null) - { - return null; - } - JToken responseValue = AirportAGVClient.InvokeT("GET:/api/v1.0.0/Maps/mapActive", null); - return JTokenToEntity>(responseValue); - } - - /// - /// 获取当前地图所有位置点请求 - /// - /// - /// - public AGVResponseEntity> AGVMapPositionRequest(string requestValue) - { - if (AirportAGVClient == null) - { - return null; - } - JToken responseValue = AirportAGVClient.InvokeT("GET:/api/v1.0.0/Positions?mapId={0}", null, requestValue); - return JTokenToEntity>>(responseValue); - } - - } - -} diff --git a/SlnMesnac.TouchSocket/ApiServer.cs b/SlnMesnac.TouchSocket/ApiServer.cs deleted file mode 100644 index f294450..0000000 --- a/SlnMesnac.TouchSocket/ApiServer.cs +++ /dev/null @@ -1,74 +0,0 @@ -using SlnMesnac.Model.AirportApiEntity; -using System; -using System.Collections.Generic; -using System.Text; -using TouchSocket.Rpc; -using TouchSocket.WebApi; - -#region << 版 本 注 释 >> -/*-------------------------------------------------------------------- -* 版权所有 (c) 2024 WenJY 保留所有权利。 -* CLR版本:4.0.30319.42000 -* 机器名称:T14-GEN3-7895 -* 命名空间:SlnMesnac.TouchSocket -* 唯一标识:649766cc-308e-4bf3-8d69-dea48ec40642 -* -* 创建者:WenJY -* 电子邮箱: -* 创建时间:2024-09-04 10:51:54 -* 版本:V1.0.0 -* 描述: -* -*-------------------------------------------------------------------- -* 修改人: -* 时间: -* 修改说明: -* -* 版本:V1.0.0 -*--------------------------------------------------------------------*/ -#endregion << 版 本 注 释 >> -namespace SlnMesnac.TouchSocket -{ - public class ApiServer: RpcServer - { - public ApiServer() - { - - } - - public delegate void AGVArrivalStart(string message, AGVSingalEntity aGVArrivalSingalEntity); - /// - /// AGV到位信号刷新 - /// - public event AGVArrivalStart AGVArrivalStartEvent; - - /// - /// AGV到位信号接口 - /// - /// - /// - [EnableCors("cors")] - [WebApi(HttpMethodType.POST)] - public object AGVSignal(string messageHeader, AGVSingalEntity aGVArrivalSingalEntity) - { - AGVArrivalStartEvent?.Invoke(messageHeader, aGVArrivalSingalEntity); - return "Success"; - } - - public void SubscribeToAGVArrivalEvent() - { - // 订阅 AGV 到位事件 - AGVArrivalStartEvent += OnAGVArrival; - } - - // 处理 AGV 到位事件的方法 - public void OnAGVArrival(string message, AGVSingalEntity aGVArrivalSingalEntity) - { - Console.WriteLine($"收到AGV到位信号: {message}"); - Console.WriteLine($"AGV编号: {aGVArrivalSingalEntity.AGVNo}, 到达位置: {aGVArrivalSingalEntity.DestinationNo}"); - // 这里可以处理更多的业务逻辑,比如记录日志、更新系统状态等 - } - - } - -} diff --git a/SlnMesnac.WPF/App.xaml.cs b/SlnMesnac.WPF/App.xaml.cs index 189cacd..151a30a 100644 --- a/SlnMesnac.WPF/App.xaml.cs +++ b/SlnMesnac.WPF/App.xaml.cs @@ -1,15 +1,16 @@ -using Lierda.WPFHelper; +using Autofac.Extensions.DependencyInjection; +using Lierda.WPFHelper; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Serilog; using SlnMesnac.Config; -using System; -using System.Windows; -using Autofac.Extensions.DependencyInjection; using SlnMesnac.Plc; -using System.Collections.Generic; using SlnMesnac.Rfid; +using System; +using System.Collections.Generic; +using System.Windows; namespace SlnMesnac.WPF { @@ -21,30 +22,60 @@ namespace SlnMesnac.WPF private System.Threading.Mutex? mutex = null; private LierdaCracker cracker = new LierdaCracker(); public static IServiceProvider? ServiceProvider = null; - + private static IHost? host; + private AppConfig appConfig; // Startup事件 protected override async void OnStartup(StartupEventArgs e) { try { bool ret; - mutex = new System.Threading.Mutex(true, System.Diagnostics.Process.GetCurrentProcess().ProcessName, out ret); - if (!ret) - { - MessageBox.Show("应用程序已开启,禁止重复运行"); - Environment.Exit(0); - } + //mutex = new System.Threading.Mutex(true, System.Diagnostics.Process.GetCurrentProcess().ProcessName, out ret); + //if (!ret) + //{ + // MessageBox.Show("应用程序已开启,禁止重复运行"); + // Environment.Exit(0); + //} cracker.Cracker(100); //设置GC回收间隔 base.OnStartup(e); - var host = CreateHostBuilder(e.Args).Build();//生成宿主。 + //var host = CreateHostBuilder(e.Args).Build();//生成宿主。 - ServiceProvider = host.Services; + //ServiceProvider = host.Services; - await host.StartAsync(); + //await host.StartAsync(); + var instanceId = GetInstanceId(e.Args); + // 创建完全独立的Host构建器 + host = CreateHostBuilder(e.Args, instanceId).Build(); - var appConfig = host.Services.GetService(); + // 预先验证服务 + using (var scope = host.Services.CreateScope()) + { + ServiceProvider = scope.ServiceProvider; + + try + { + + //serilogHelper = services.GetRequiredService(); + //serilogHelper.Info($"启动服务"); + //var appConfig = services.GetRequiredService(); + appConfig = host.Services.GetService(); + + // 强制设置实例ID到配置对象 + SetInstanceSpecificConfiguration(appConfig, instanceId); + + //serilogHelper.Info($"实例 {instanceId} 服务初始化完成"); + Console.WriteLine($"实例 {instanceId} 服务初始化完成"); + } + catch (Exception ex) + { + Console.WriteLine($"实例 {instanceId} 服务初始化失败: {ex.Message}"); + //serilogHelper.Info($"详细错误: {ex}"); + } + } + //await host.StartAsync(); + var hostTask = host.RunAsync(); var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/"; Log.Information($"系统初始化完成,日志存放路径:{appConfig.logPath}"); } @@ -56,7 +87,147 @@ namespace SlnMesnac.WPF } + private static void SetInstanceSpecificConfiguration(AppConfig appConfig, string instanceId) + { + try + { + Console.WriteLine($"为实例 {instanceId} 设置特定配置..."); + // 使用反射设置所有可能的配置属性 + var configType = appConfig.GetType(); + var properties = configType.GetProperties(); + + foreach (var property in properties) + { + if (property.CanWrite) + { + var value = property.GetValue(appConfig); + if (value is string stringValue) + { + // 替换路径中的占位符 + if (stringValue.Contains("{Instance}") || + stringValue.Contains("{instance}")) + { + var newValue = stringValue + .Replace("{Instance}", instanceId) + .Replace("{instance}", instanceId); + property.SetValue(appConfig, newValue); + Console.WriteLine($" 更新 {property.Name}: {newValue}"); + } + else if (IsPathProperty(property.Name) && + !stringValue.Contains(instanceId)) + { + // 为路径属性添加实例ID + var newValue = $"{stringValue}_Instance{instanceId}"; + property.SetValue(appConfig, newValue); + Console.WriteLine($" 更新 {property.Name}: {newValue}"); + } + } + else if (property.PropertyType == typeof(int) && + IsPortProperty(property.Name)) + { + // 调整端口号 + var basePort = (int)value; + var newPort = basePort + (int.Parse(instanceId) - 1) * 10; + property.SetValue(appConfig, newPort); + Console.WriteLine($" 更新 {property.Name}: {newPort}"); + } + } + } + } + catch (Exception ex) + { + Console.WriteLine($"设置实例配置时出错: {ex.Message}"); + //serilogHelper?.Info($"设置实例配置时出错: {ex.Message}"); + } + } + private static bool IsPortProperty(string propertyName) + { + return propertyName.ToLower().Contains("port"); + } + private static bool IsPathProperty(string propertyName) + { + return propertyName.ToLower().Contains("path") || + propertyName.ToLower().Contains("dir") || + propertyName.ToLower().Contains("file"); + } + public static IHostBuilder CreateHostBuilder(string[] args, string instanceId) => + Host.CreateDefaultBuilder(args) + .UseSerilog((context, config) => + { + // 为每个实例配置独立的Serilog + config.WriteTo.Console( + outputTemplate: $"[{{Timestamp:HH:mm:ss}} {{Level:u3}}] Instance{instanceId}: {{Message:lj}}{{NewLine}}{{Exception}}") + .WriteTo.File( + path: $"./Logs/{DateTime.UtcNow:yyyy-MM-dd}/log-.txt", + rollingInterval: RollingInterval.Day, + outputTemplate: $"[{{Timestamp:yyyy-MM-dd HH:mm:ss}} {{Level:u3}}] Instance{instanceId}: {{Message:lj}}{{NewLine}}{{Exception}}"); + }) + .UseServiceProviderFactory(new AutofacServiceProviderFactory()) + .ConfigureAppConfiguration((context, config) => + { + // 清除默认配置,从头开始构建 + config.Sources.Clear(); + + // 按优先级添加配置源 + config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) + .AddJsonFile($"appsettings.{context.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true) + .AddJsonFile($"appsettings.instance{instanceId}.json", optional: true, reloadOnChange: true) + .AddEnvironmentVariables("INSTANCE_") + .AddCommandLine(args); + }) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + + webBuilder.ConfigureKestrel(serverOptions => + { + Console.WriteLine(int.Parse(instanceId)); + + serverOptions.ListenAnyIP(1 + (int.Parse(instanceId) - 1)); + }); + }) + .ConfigureServices((context, services) => + { + services.AddSingleton(new InstanceInfo { Id = instanceId }); + }); + public class InstanceInfo + { + public string Id { get; set; } = "1"; + + } + private static string GetInstanceId(string[] args) + { + // 支持多种参数格式 + foreach (var arg in args) + { + if (arg.StartsWith("--instance")) + { + if (arg == "--instance") + { + // 查找下一个参数作为实例ID + var index = Array.IndexOf(args, arg); + if (index + 1 < args.Length) + { + return args[index + 1]; + } + } + else if (arg.StartsWith("--instance=")) + { + return arg.Substring("--instance=".Length); + } + else + { + // 格式: --instance1, --instance2 + return arg.Substring("--instance".Length); + } + } + } + + // 如果没有指定实例ID,使用随机ID避免冲突 + Random random = new Random(); + return random.Next(0000, 9999).ToString(); + } /// /// CreateHostBuilder /// @@ -64,6 +235,7 @@ namespace SlnMesnac.WPF /// public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) + .UseSerilog() .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureWebHostDefaults(webBuilder => diff --git a/SlnMesnac.WPF/MainWindow.xaml b/SlnMesnac.WPF/MainWindow.xaml index 9c09c0b..2756c3a 100644 --- a/SlnMesnac.WPF/MainWindow.xaml +++ b/SlnMesnac.WPF/MainWindow.xaml @@ -5,10 +5,10 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:SlnMesnac.WPF" mc:Ignorable="d" - Title="MainWindow" WindowStartupLocation="CenterScreen" WindowState="Maximized" Height="1080" Width="1920" Topmost="False" Loaded="Window_Loaded" Closing="Window_Closing"> - + Title="汇集软件" WindowStartupLocation="CenterScreen" WindowState="Normal" Height="1000" Width="1420" Topmost="False" Loaded="Window_Loaded" Closing="Window_Closing"> + @@ -17,10 +17,9 @@ - - + - + @@ -29,29 +28,17 @@ - + - - - - - - - - - - - - - + - + + --> + --> + --> + --> diff --git a/SlnMesnac.WPF/Model/RfidInfo.cs b/SlnMesnac.WPF/Model/RfidInfo.cs new file mode 100644 index 0000000..e56cbfe --- /dev/null +++ b/SlnMesnac.WPF/Model/RfidInfo.cs @@ -0,0 +1,72 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SlnMesnac.WPF.Model +{ + public class RfidInfo : INotifyPropertyChanged + { + /// + /// 备 注: + /// 默认值: + /// + public string Deviceid { get; set; } = null!; + + /// + /// 备 注: + /// 默认值: + /// + public string? Name { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + public string? Connectstr { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + public decimal? Connectmode { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + public string? Devicetype { get; set; } + + /// + /// 备 注:所属汇集软件ID + /// 默认值: + /// + public string? Collectid { get; set; } + + private string _isOnline ="未连接"; + + public string IsOnline + { + get { return _isOnline; } + set + { + if (_isOnline != value) + { + _isOnline = value; + OnPropertyChanged(nameof(IsOnline)); + } + } + } + + + public event PropertyChangedEventHandler? PropertyChanged; + + protected virtual void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} \ No newline at end of file diff --git a/SlnMesnac.WPF/Model/SenorInfo.cs b/SlnMesnac.WPF/Model/SenorInfo.cs new file mode 100644 index 0000000..ffffe14 --- /dev/null +++ b/SlnMesnac.WPF/Model/SenorInfo.cs @@ -0,0 +1,92 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SlnMesnac.WPF.Model +{ + public class SenorInfo : INotifyPropertyChanged + { + /// + /// 备 注: + /// 默认值: + /// + public string Sensorid { get; set; } = null!; + + /// + /// 备 注: + /// 默认值: + /// + public string Combineid { get; set; } = null!; + + /// + /// 备 注: + /// 默认值: + /// + public string? Name { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + public decimal? Sensorser { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + public decimal? Sensortypeid { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + public string? Deviceid { get; set; } + + /// + /// 备 注: + /// 默认值: + /// + public decimal? Readinterval { get; set; } + + private string _readtime; + + public string Readtime + { + get { return _readtime; } + set + { + if (_readtime != value) + { + _readtime = value; + OnPropertyChanged(nameof(Readtime)); + } + } + } + private string _readdata; + + public string Readdata + { + get { return _readdata; } + set + { + if (_readdata != value) + { + _readdata = value; + OnPropertyChanged(nameof(Readdata)); + } + } + } + + + public event PropertyChangedEventHandler? PropertyChanged; + + protected virtual void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} \ No newline at end of file diff --git a/SlnMesnac.WPF/Page/IndexPage/MiddleWare.xaml b/SlnMesnac.WPF/Page/IndexPage/MiddleWare.xaml new file mode 100644 index 0000000..b96a9d1 --- /dev/null +++ b/SlnMesnac.WPF/Page/IndexPage/MiddleWare.xaml @@ -0,0 +1,220 @@ + + + + + + + + + + + + + + + + +