diff --git a/Entity/DbModel/Station/BinInfo.cs b/Entity/DbModel/Station/BinInfo.cs index 9409db5..6aed776 100644 --- a/Entity/DbModel/Station/BinInfo.cs +++ b/Entity/DbModel/Station/BinInfo.cs @@ -1,7 +1,4 @@ -using System; -using System.Linq; -using System.Text; -using SqlSugar; +using SqlSugar; namespace Entity.DbModel.Station { @@ -11,201 +8,200 @@ namespace Entity.DbModel.Station [SugarTable("bin_info")] public partial class BinInfo { - public BinInfo(){ - - - } - /// - /// Desc:id - /// Default: - /// Nullable:False - /// - [SugarColumn(IsPrimaryKey=true,IsIdentity=true,ColumnName="id")] - public int Id {get;set;} - - /// - /// Desc:仓位编号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="no")] - public string No {get;set;} - - /// - /// Desc:仓位编码 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="code")] - public string Code {get;set;} - - /// - /// Desc:仓位名称 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="name")] - public string Name {get;set;} - - /// - /// Desc:在位状态:0-不在位;1-在位;2-无效 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="exists")] - public int? Exists {get;set;} - - /// - /// Desc:电池编号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="battery_no")] - public string BatteryNo {get;set;} - - /// - /// Desc:充电机编号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="charger_no")] - public string ChargerNo {get;set;} - - /// - /// Desc:充电枪编号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="charger_gun_no")] - public string ChargerGunNo {get;set;} - - /// - /// Desc:水冷编号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="water_cool_no")] - public string WaterCoolNo {get;set;} - - /// - /// Desc:是否有电插头;0-无电插头;1-有电插头 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="elec_plugin_flag")] - public int? ElecPluginFlag {get;set;} - - /// - /// Desc:电插头状态;0-未知;1-已经连接;2-未连接 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="elec_plugin_status")] - public string ElecPluginStatus {get;set;} - - /// - /// Desc:是否有水插头;0-无水插头;1-有水插头 - /// Default: - /// Nullable:False - /// - [SugarColumn(ColumnName="water_plugin_flag")] - public string WaterPluginFlag {get;set;} - - /// - /// Desc:预约锁定;0-未锁定;1-锁定 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="amt_lock")] - public int AmtLock {get;set;} - - /// - /// Desc:soc - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="soc")] - public decimal? Soc {get;set;} - - /// - /// Desc:soe - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="soe")] - public decimal? Soe {get;set;} - - /// - /// Desc:soh - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="soh")] - public decimal? Soh {get;set;} - - /// - /// Desc:电池入仓顺序 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="battery_enter_seq")] - public int? BatteryEnterSeq {get;set;} - - /// - /// Desc:充电状态;0-未知;1-正在充电;2-无电池;3-禁用 - /// Default:0 - /// Nullable:True - /// - [SugarColumn(ColumnName="charge_status")] - public int? ChargeStatus {get;set;} - - /// - /// Desc:仓位状态;0-禁用;1-启用 - /// Default:1 - /// Nullable:True - /// - [SugarColumn(ColumnName="status")] - public int? Status {get;set;} - - /// - /// Desc:创建人 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="created_by")] - public string CreatedBy {get;set;} - - /// - /// Desc:创建时间 - /// Default:CURRENT_TIMESTAMP - /// Nullable:True - /// - [SugarColumn(ColumnName="created_time")] - public DateTime? CreatedTime {get;set;} - - /// - /// Desc:更新人 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="updated_by")] - public string UpdatedBy {get;set;} - - /// - /// Desc:最后结束充电时间 结束充电后更新 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="last_charge_finish_time")] - public DateTime? LastChargeFinishTime {get;set;} - - /// - /// Desc:更新时间 - /// Default:CURRENT_TIMESTAMP - /// Nullable:True - /// - [SugarColumn(ColumnName="updated_time")] - public DateTime? UpdatedTime {get;set;} - + public BinInfo() + { + } + + /// + /// Desc:id + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")] + public int Id { get; set; } + + /// + /// Desc:仓位编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "no")] + public string No { get; set; } + + /// + /// Desc:仓位编码 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "code")] + public string Code { get; set; } + + /// + /// Desc:仓位名称 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "name")] + public string Name { get; set; } + + /// + /// Desc:在位状态:0-不在位;1-在位;2-无效 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "exists")] + public int Exists { get; set; } + + /// + /// Desc:电池编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "battery_no")] + public string BatteryNo { get; set; } + + /// + /// Desc:充电机编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "charger_no")] + public string ChargerNo { get; set; } + + /// + /// Desc:充电枪编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "charger_gun_no")] + public string ChargerGunNo { get; set; } + + /// + /// Desc:水冷编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "water_cool_no")] + public string WaterCoolNo { get; set; } + + /// + /// Desc:是否有电插头;0-无电插头;1-有电插头 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "elec_plugin_flag")] + public int? ElecPluginFlag { get; set; } + + /// + /// Desc:电插头状态;0-未知;1-已经连接;2-未连接 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "elec_plugin_status")] + public string ElecPluginStatus { get; set; } + + /// + /// Desc:是否有水插头;0-无水插头;1-有水插头 + /// Default: + /// Nullable:False + /// + [SugarColumn(ColumnName = "water_plugin_flag")] + public string WaterPluginFlag { get; set; } + + /// + /// Desc:预约锁定;0-未锁定;1-锁定 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "amt_lock")] + public int AmtLock { get; set; } + + /// + /// Desc:soc + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "soc")] + public decimal? Soc { get; set; } + + /// + /// Desc:soe + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "soe")] + public decimal? Soe { get; set; } + + /// + /// Desc:soh + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "soh")] + public decimal? Soh { get; set; } + + /// + /// Desc:电池入仓顺序 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "battery_enter_seq")] + public int? BatteryEnterSeq { get; set; } + + /// + /// Desc:充电状态;0-未知;1-正在充电;2-无电池;3-禁用 + /// Default:0 + /// Nullable:True + /// + [SugarColumn(ColumnName = "charge_status")] + public int? ChargeStatus { get; set; } + + /// + /// Desc:仓位状态;0-禁用;1-启用 + /// Default:1 + /// Nullable:True + /// + [SugarColumn(ColumnName = "status")] + public int? Status { get; set; } + + /// + /// Desc:创建人 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "created_by")] + public string CreatedBy { get; set; } + + /// + /// Desc:创建时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [SugarColumn(ColumnName = "created_time")] + public DateTime? CreatedTime { get; set; } + + /// + /// Desc:更新人 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "updated_by")] + public string UpdatedBy { get; set; } + + /// + /// Desc:最后结束充电时间 结束充电后更新 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "last_charge_finish_time")] + public DateTime? LastChargeFinishTime { get; set; } + + /// + /// Desc:更新时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [SugarColumn(ColumnName = "updated_time")] + public DateTime? UpdatedTime { get; set; } } -} +} \ No newline at end of file diff --git a/HybirdFrameworkCore/Autofac/Attribute/ScopeAttribute.cs b/HybirdFrameworkCore/Autofac/Attribute/ScopeAttribute.cs index 5e34d5a..2651c76 100644 --- a/HybirdFrameworkCore/Autofac/Attribute/ScopeAttribute.cs +++ b/HybirdFrameworkCore/Autofac/Attribute/ScopeAttribute.cs @@ -4,7 +4,11 @@ public class ScopeAttribute : System.Attribute { public readonly string Scope; - public ScopeAttribute(string scope) + /// + /// 向容器注入bean,默认单例模式 + /// + /// + public ScopeAttribute(string scope = "SingleInstance") { Scope = scope; } diff --git a/HybirdFrameworkDriver/ModbusTcpMaster/ModbusTcpMaster.cs b/HybirdFrameworkDriver/ModbusTcpMaster/ModbusTcpMaster.cs index 94b59ed..2787bca 100644 --- a/HybirdFrameworkDriver/ModbusTcpMaster/ModbusTcpMaster.cs +++ b/HybirdFrameworkDriver/ModbusTcpMaster/ModbusTcpMaster.cs @@ -12,7 +12,7 @@ public class ModbusTcpMaster private static readonly ILog Log = LogManager.GetLogger(typeof(ModbusTcpMaster)); - private ModbusTcpNet ModbusTcpNet; + private ModbusTcpNet? ModbusTcpNet; public string Ip { get; set; } = "127.0.0.1"; @@ -23,6 +23,11 @@ public class ModbusTcpMaster public int Duration { get; set; } = 1000; public bool Connected { get; set; } + /// + /// 自动重连开关 + /// + public bool AutoReConnect { get; set; } + public string connectId { get; set; } public MyReadAction? ReadAction { get; set; } @@ -36,8 +41,8 @@ public class ModbusTcpMaster public bool Connect() { + Thread.Sleep(Duration); GetLog().Info($"begin to connect {Ip}:{Port}"); - try { if (ModbusTcpNet == null) @@ -55,12 +60,20 @@ public class ModbusTcpMaster else { GetLog().Info($"connect {Ip}:{Port} failed {result.Message}"); + if (AutoReConnect) + { + return Connect(); + } } } } catch (Exception e) { GetLog().Error($"connect {Ip}:{Port} exception {e.Message}"); + if (AutoReConnect) + { + return Connect(); + } } return Connected; diff --git a/Repository/BaseRepository.cs b/Repository/BaseRepository.cs index 019e471..78023b2 100644 --- a/Repository/BaseRepository.cs +++ b/Repository/BaseRepository.cs @@ -1,5 +1,4 @@ using System.Linq.Expressions; -using Entity.Base; using Entity.Dto.Req; using HybirdFrameworkCore.Entity; using SqlSugar; @@ -915,6 +914,12 @@ public abstract class BaseRepository where T : class, new() .AnyAsync(expression); } + public int Update(Expression> columns, + Expression> expression) + { + return DbBaseClient.Updateable().SetColumns(columns).Where(expression).ExecuteCommand(); + } + public async Task UpdateAsync( Expression> columns, diff --git a/Service/EquipmentInit.cs b/Service/EquipmentInit.cs deleted file mode 100644 index e503c4a..0000000 --- a/Service/EquipmentInit.cs +++ /dev/null @@ -1,100 +0,0 @@ -using HybirdFrameworkCore.Autofac.Attribute; -using HybirdFrameworkDriver.ModbusTcpMaster; -using HybirdFrameworkDriver.Session; -using HybirdFrameworkServices.Plc; -using Newtonsoft.Json.Linq; -using Service.Execute.Api; -using Service.Init.Entity; -using Service.Plc; - -namespace Service -{ - [Scope("SingleInstance")] - public class EquipmentInit - { - /// - /// 连接所有数据 - /// - /// - public void Connect() - { - ConnectPlc(); - } - - /// - /// 连接PLC - /// - /// - /// - public int ConnectPlc() - { - Thread thread = new Thread(() => ConnectPlcAsync()); - thread.Start(); - - return 0; - } - - /// - /// 连接PLC - /// - private void ConnectPlcAsync() - { - bool connected = false; - - ModbusTcpMaster master = null; - //PLC连接 - while (!connected) - { - master = new ModbusTcpMaster() - { - Ip = "172.0.20.66", - Port = 502, - }; - master.ReadAction = BatchReadPlc; //启动线程一直读 - master.Duration = 3000; - connected = master.Connect(); - - if (connected) - { - PlcMgr.ModbusTcpMaster = master; - break; - } - - Thread.Sleep(5000); - } - } - - /** - * 一直读 - */ - private static void BatchReadPlc(ModbusTcpMaster master) - { - if (PlcMgr.ModbusTcpMaster!=null) - { - - - var bytes01 = master.BatchReadHolderRegister(1, 115); - if (bytes01 != null) - { - PlcMgr.DataValidityTime = DateTime.Now; - ModbusDecoder.Decode(bytes01, PlcMgr.HostToPlcData); - } - - var bytes02 = master.BatchReadHolderRegister(201, 222); - if (bytes02 != null) - { - PlcMgr.DataValidityTime = DateTime.Now; - ModbusDecoder.Decode(bytes02, PlcMgr.PlcToHostData); - } - - var bytes03 = master.BatchReadHolderRegister(701, 10); - if (bytes03 != null) - { - PlcMgr.DataValidityTime = DateTime.Now; - ModbusDecoder.Decode(bytes03, PlcMgr.PlcFaultData); - } - //OperateResult result2 = ModbusTcpNet.Read("x=3;201", 222); - } - } - } -} \ No newline at end of file diff --git a/Service/Execute/Api/PlcApi.cs b/Service/Execute/Api/PlcApi.cs index 488629b..37cae55 100644 --- a/Service/Execute/Api/PlcApi.cs +++ b/Service/Execute/Api/PlcApi.cs @@ -1,9 +1,9 @@ using HybirdFrameworkDriver.ModbusTcpMaster; -using HybirdFrameworkServices.Plc; using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using Service.Cloud.Msg.Cloud.Req; using Service.Init.Entity; using Service.Plc; +using Service.Plc.Client; namespace Service.Execute.Api; diff --git a/Service/Init/Entity/PlcInfo.cs b/Service/Init/Entity/PlcInfo.cs index c3465a0..e536bbe 100644 --- a/Service/Init/Entity/PlcInfo.cs +++ b/Service/Init/Entity/PlcInfo.cs @@ -1,11 +1,11 @@ using DotNetty.Codecs.Mqtt.Packets; using HybirdFrameworkDriver.ModbusTcpMaster; using HybirdFrameworkDriver.Session; -using HybirdFrameworkServices.Plc; using Newtonsoft.Json.Linq; using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using Pipelines.Sockets.Unofficial.Arenas; using System.Net.NetworkInformation; +using Service.Plc.Msg; namespace Service.Init.Entity { diff --git a/Service/Plc/Client/PlcClient.cs b/Service/Plc/Client/PlcClient.cs new file mode 100644 index 0000000..e14af51 --- /dev/null +++ b/Service/Plc/Client/PlcClient.cs @@ -0,0 +1,57 @@ +using HybirdFrameworkCore.Autofac.Attribute; +using HybirdFrameworkDriver.ModbusTcpMaster; +using Repository.Station; +using Service.Plc.Msg; + +namespace Service.Plc.Client; + +/// +/// +/// +[Scope] +public class PlcClient : ModbusTcpMaster +{ + private BinInfoRepository _binInfoRepository; + + public PlcClient(BinInfoRepository binInfoRepository) + { + ReadAction = BatchRead; + Ip = "172.0.20.66"; + Port = 502; + Duration = 2000; + AutoReConnect = true; + _binInfoRepository = binInfoRepository; + } + + private void BatchRead(ModbusTcpMaster master) + { + var bytes01 = master.BatchReadHolderRegister(1, 115); + if (bytes01 != null) + { + PlcMgr.DataValidityTime = DateTime.Now; + ModbusDecoder.Decode(bytes01, PlcMgr.HostToPlcData); + } + + var bytes02 = master.BatchReadHolderRegister(201, 222); + if (bytes02 != null) + { + PlcMgr.DataValidityTime = DateTime.Now; + ModbusDecoder.Decode(bytes02, PlcMgr.PlcToHostData); + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec01.Value, it => it.No == "1"); + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec02.Value, it => it.No == "2"); + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec03.Value, it => it.No == "3"); + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec04.Value, it => it.No == "4"); + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec05.Value, it => it.No == "5"); + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec06.Value, it => it.No == "6"); + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec07.Value, it => it.No == "7"); + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec08.Value, it => it.No == "8"); + } + + var bytes03 = master.BatchReadHolderRegister(701, 10); + if (bytes03 != null) + { + PlcMgr.DataValidityTime = DateTime.Now; + ModbusDecoder.Decode(bytes03, PlcMgr.PlcFaultData); + } + } +} \ No newline at end of file diff --git a/Service/Plc/PlcMgr.cs b/Service/Plc/Client/PlcMgr.cs similarity index 76% rename from Service/Plc/PlcMgr.cs rename to Service/Plc/Client/PlcMgr.cs index 01037d4..2b28ae1 100644 --- a/Service/Plc/PlcMgr.cs +++ b/Service/Plc/Client/PlcMgr.cs @@ -1,41 +1,52 @@ -using HybirdFrameworkDriver.ModbusTcpMaster; -using HybirdFrameworkServices.Plc; +using Autofac; +using HybirdFrameworkCore.Autofac; +using Service.Plc.Msg; -namespace Service.Plc; +namespace Service.Plc.Client; -public abstract class PlcMgr +public class PlcMgr { - public static ModbusTcpMaster ModbusTcpMaster; + public static PlcClient? PlcClient; public static readonly HostToPlc HostToPlcData = new HostToPlc(); public static readonly PlcToHost PlcToHostData = new PlcToHost(); public static readonly PlcFault PlcFaultData = new PlcFault(); - + /// /// 数据有效时间。单位秒 /// - static int DataTimeSeconds = 2; + static int DataTimeSeconds = 3; + /// /// 数据刷新时间 /// public static DateTime DataValidityTime = DateTime.Now; + public static bool Init() + { + if (PlcClient == null) + { + PlcClient = AppInfo.Container.Resolve(); + } + + return PlcClient.Connect(); + } - /// /// 写入口灯 /// 红灯:1020 /// 绿灯:1000 /// - /// + /// /// public static bool WriteEntranceLamp(byte value) { - if (ModbusTcpMaster != null) + if (PlcClient != null) { HostToPlcData.LightIn.Value = value; - return ModbusTcpMaster.WriteValue(HostToPlcData.LightIn); + return PlcClient.WriteValue(HostToPlcData.LightIn); } + return false; } @@ -96,12 +107,13 @@ public abstract class PlcMgr /// public static bool WriteExistLamp(int data) { - if (ModbusTcpMaster != null) + if (PlcClient != null) { HostToPlc writeHostToPlc = new HostToPlc(); writeHostToPlc.LightOut.Value = (ushort)data; - return ModbusTcpMaster.WriteValue(writeHostToPlc.LightIn); + return PlcClient.WriteValue(writeHostToPlc.LightIn); } + return false; } @@ -113,15 +125,16 @@ public abstract class PlcMgr /// public static bool DistributeSelectPack(string inBinNo, string outBinNo) { - if (ModbusTcpMaster != null) + if (PlcClient != null) { HostToPlc writeHostToPlc = new HostToPlc(); writeHostToPlc.EntrySelection.Value = Convert.ToUInt16(inBinNo); writeHostToPlc.ExitSelection.Value = Convert.ToUInt16(outBinNo); - bool write1 = ModbusTcpMaster.WriteValue(writeHostToPlc.EntrySelection); - bool write2 = ModbusTcpMaster.WriteValue(writeHostToPlc.ExitSelection); + bool write1 = PlcClient.WriteValue(writeHostToPlc.EntrySelection); + bool write2 = PlcClient.WriteValue(writeHostToPlc.ExitSelection); return write1 && write2; } + return false; } @@ -132,18 +145,19 @@ public abstract class PlcMgr /// public static bool StartSwapping() { - if (ModbusTcpMaster != null) + if (PlcClient != null) { - if (PlcToHostData.TaskType.Value == 0)//是否允许换电 + if (PlcToHostData.TaskType.Value == 0) //是否允许换电 return false; HostToPlc writeHostToPlc = new HostToPlc(); writeHostToPlc.TaskType.Value = (ushort)1; writeHostToPlc.TaskEnablement.Value = (ushort)1000; - bool write1 = ModbusTcpMaster.WriteValue(writeHostToPlc.TaskType); - bool write2 = ModbusTcpMaster.WriteValue(writeHostToPlc.TaskEnablement); + bool write1 = PlcClient.WriteValue(writeHostToPlc.TaskType); + bool write2 = PlcClient.WriteValue(writeHostToPlc.TaskEnablement); return write1 && write2; } + return false; } @@ -163,10 +177,11 @@ public abstract class PlcMgr /// 6未连接 public static int ReadPlcTaskStatus() { - if (ModbusTcpMaster != null) + if (PlcClient != null) { return PlcToHostData.TaskType.Value; } + return (-1); } } \ No newline at end of file diff --git a/Service/Plc/HostToPlc.cs b/Service/Plc/Msg/HostToPlc.cs similarity index 98% rename from Service/Plc/HostToPlc.cs rename to Service/Plc/Msg/HostToPlc.cs index fa6ba5e..c116148 100644 --- a/Service/Plc/HostToPlc.cs +++ b/Service/Plc/Msg/HostToPlc.cs @@ -1,12 +1,6 @@ -using HybirdFrameworkCore.Autofac.Attribute; -using HybirdFrameworkDriver.ModbusTcpMaster; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using HybirdFrameworkDriver.ModbusTcpMaster; -namespace HybirdFrameworkServices.Plc +namespace Service.Plc.Msg { public class HostToPlc { diff --git a/Service/Plc/PlcFault.cs b/Service/Plc/Msg/PlcFault.cs similarity index 86% rename from Service/Plc/PlcFault.cs rename to Service/Plc/Msg/PlcFault.cs index 0b35d9a..599cec9 100644 --- a/Service/Plc/PlcFault.cs +++ b/Service/Plc/Msg/PlcFault.cs @@ -1,11 +1,6 @@ using HybirdFrameworkDriver.ModbusTcpMaster; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace HybirdFrameworkServices.Plc +namespace Service.Plc.Msg { public class PlcFault { diff --git a/Service/Plc/PlcToHost.cs b/Service/Plc/Msg/PlcToHost.cs similarity index 67% rename from Service/Plc/PlcToHost.cs rename to Service/Plc/Msg/PlcToHost.cs index bc8cdbe..826973f 100644 --- a/Service/Plc/PlcToHost.cs +++ b/Service/Plc/Msg/PlcToHost.cs @@ -1,13 +1,6 @@ -using HybirdFrameworkCore.Autofac.Attribute; -using HybirdFrameworkDriver.ModbusTcpMaster; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using HybirdFrameworkDriver.ModbusTcpMaster; -namespace HybirdFrameworkServices.Plc +namespace Service.Plc.Msg { /// /// @@ -77,46 +70,26 @@ namespace HybirdFrameworkServices.Plc #region 舱位状态 bit0:有料检测 Bit1:有料检测开关故障 - public ModbusProperty MaterialDetec01 { get; set; } = new(40241,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec02 { get; set; } = new(40242,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec03 { get; set; } = new(40243,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec04 { get; set; } = new(40244,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec05 { get; set; } = new(40245,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec06 { get; set; } = new(40246,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec07 { get; set; } = new(40247,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec08 { get; set; } = new(40248,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec09 { get; set; } = new(40249,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec10 { get; set; } = new(40250,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec11 { get; set; } = new(40251,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec12 { get; set; } = new(40252,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec13 { get; set; } = new(40253,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec14 { get; set; } = new(40254,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec15 { get; set; } = new(40255,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec16 { get; set; } = new(40256,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec17 { get; set; } = new(40257,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec18 { get; set; } = new(40258,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec19 { get; set; } = new(40259,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetec20 { get; set; } = new(40260,0,0,ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault01 { get; set; } = new(40241, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault02 { get; set; } = new(40242, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault03 { get; set; } = new(40243, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault04 { get; set; } = new(40244, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault05 { get; set; } = new(40245, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault06 { get; set; } = new(40246, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault07 { get; set; } = new(40247, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault08 { get; set; } = new(40248, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault09 { get; set; } = new(40249, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault10 { get; set; } = new(40250, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault11 { get; set; } = new(40251, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault12 { get; set; } = new(40252, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault13 { get; set; } = new(40253, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault14 { get; set; } = new(40254, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault15 { get; set; } = new(40255, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault16 { get; set; } = new(40256, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault17 { get; set; } = new(40257, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault18 { get; set; } = new(40258, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault19 { get; set; } = new(40259, 0, 0, ModbusDataType.Bit); - public ModbusProperty MaterialDetecSwitchFault20 { get; set; } = new(40260, 0, 0, ModbusDataType.Bit); + public ModbusProperty MaterialDetec01 { get; set; } = new(40241,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec02 { get; set; } = new(40242,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec03 { get; set; } = new(40243,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec04 { get; set; } = new(40244,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec05 { get; set; } = new(40245,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec06 { get; set; } = new(40246,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec07 { get; set; } = new(40247,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec08 { get; set; } = new(40248,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec09 { get; set; } = new(40249,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec10 { get; set; } = new(40250,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec11 { get; set; } = new(40251,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec12 { get; set; } = new(40252,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec13 { get; set; } = new(40253,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec14 { get; set; } = new(40254,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec15 { get; set; } = new(40255,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec16 { get; set; } = new(40256,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec17 { get; set; } = new(40257,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec18 { get; set; } = new(40258,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec19 { get; set; } = new(40259,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec20 { get; set; } = new(40260,0,2,ModbusDataType.Bit); #endregion 舱位状态 diff --git a/WebStarter/Program.cs b/WebStarter/Program.cs index 47bb01e..49b742d 100644 --- a/WebStarter/Program.cs +++ b/WebStarter/Program.cs @@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.IdentityModel.Tokens; using Service.Cloud.Client; using Service.Execute; +using Service.Plc.Client; using SqlSugar; using SqlSugar.IOC; @@ -147,8 +148,12 @@ app.MapControllers(); AppInfo.Container = app.Services.GetAutofacRoot(); +//云平台 CloudClientMgr.Init(); +//PLC +PlcMgr.Init(); + //启动换电流程 StationSoftMgr.SwappingStateMachineStart(); diff --git a/WebStarter/obj/Debug/net6.0/staticwebassets.build.json b/WebStarter/obj/Debug/net6.0/staticwebassets.build.json index 26839c5..4499011 100644 --- a/WebStarter/obj/Debug/net6.0/staticwebassets.build.json +++ b/WebStarter/obj/Debug/net6.0/staticwebassets.build.json @@ -1,6 +1,6 @@ { "Version": 1, - "Hash": "zLyz6C3YNcAfQ4a3PqNREUoaDzuSSMCXv5JiEIrUCxU=", + "Hash": "6L5ya4V2yXT6SrMz9lvVeF6F81dXoy4XMjFW1sVbQpk=", "Source": "WebStarter", "BasePath": "_content/WebStarter", "Mode": "Default", @@ -10,17 +10,17 @@ { "Name": "WebStarter\\wwwroot", "Source": "WebStarter", - "ContentRoot": "D:\\项目文件\\项目报表\\19焕能后背式站控\\04项目源码\\主服务\\WebStarter\\wwwroot\\", + "ContentRoot": "D:\\vsproject\\hn_back_main\\WebStarter\\wwwroot\\", "BasePath": "_content/WebStarter", "Pattern": "**" } ], "Assets": [ { - "Identity": "D:\\项目文件\\项目报表\\19焕能后背式站控\\04项目源码\\主服务\\WebStarter\\wwwroot\\20240523\\0.jpg", + "Identity": "D:\\vsproject\\hn_back_main\\WebStarter\\wwwroot\\20240523\\0.jpg", "SourceId": "WebStarter", "SourceType": "Discovered", - "ContentRoot": "D:\\项目文件\\项目报表\\19焕能后背式站控\\04项目源码\\主服务\\WebStarter\\wwwroot\\", + "ContentRoot": "D:\\vsproject\\hn_back_main\\WebStarter\\wwwroot\\", "BasePath": "_content/WebStarter", "RelativePath": "20240523/0.jpg", "AssetKind": "All", @@ -34,10 +34,10 @@ "OriginalItemSpec": "wwwroot\\20240523\\0.jpg" }, { - "Identity": "D:\\项目文件\\项目报表\\19焕能后背式站控\\04项目源码\\主服务\\WebStarter\\wwwroot\\20240524\\0.jpg", + "Identity": "D:\\vsproject\\hn_back_main\\WebStarter\\wwwroot\\20240524\\0.jpg", "SourceId": "WebStarter", "SourceType": "Discovered", - "ContentRoot": "D:\\项目文件\\项目报表\\19焕能后背式站控\\04项目源码\\主服务\\WebStarter\\wwwroot\\", + "ContentRoot": "D:\\vsproject\\hn_back_main\\WebStarter\\wwwroot\\", "BasePath": "_content/WebStarter", "RelativePath": "20240524/0.jpg", "AssetKind": "All", @@ -51,10 +51,10 @@ "OriginalItemSpec": "wwwroot\\20240524\\0.jpg" }, { - "Identity": "D:\\项目文件\\项目报表\\19焕能后背式站控\\04项目源码\\主服务\\WebStarter\\wwwroot\\20240524\\0.png", + "Identity": "D:\\vsproject\\hn_back_main\\WebStarter\\wwwroot\\20240524\\0.png", "SourceId": "WebStarter", "SourceType": "Discovered", - "ContentRoot": "D:\\项目文件\\项目报表\\19焕能后背式站控\\04项目源码\\主服务\\WebStarter\\wwwroot\\", + "ContentRoot": "D:\\vsproject\\hn_back_main\\WebStarter\\wwwroot\\", "BasePath": "_content/WebStarter", "RelativePath": "20240524/0.png", "AssetKind": "All", diff --git a/WinFormStarter/FrmPlc.cs b/WinFormStarter/FrmPlc.cs index da27cdd..2e3514e 100644 --- a/WinFormStarter/FrmPlc.cs +++ b/WinFormStarter/FrmPlc.cs @@ -10,7 +10,6 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using HybirdFrameworkDriver.ModbusTcpMaster; -using HybirdFrameworkServices.Plc; using HybirdFrameworkDriver.TcpServer; using Newtonsoft.Json.Linq; using Service.Init.Entity; diff --git a/WinFormStarter/Program.cs b/WinFormStarter/Program.cs index b443774..a16ff66 100644 --- a/WinFormStarter/Program.cs +++ b/WinFormStarter/Program.cs @@ -1,7 +1,6 @@ using Autofac; using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Configuration; -using HybirdFrameworkServices; using log4net.Config; using Service; using SqlSugar; @@ -52,10 +51,7 @@ internal static class Program // 构建容器 Container = builder.Build(); AppInfo.Container = Container.BeginLifetimeScope("root"); - EquipmentInit equipmentInit = AppInfo.Container.Resolve(); - equipmentInit.Connect(); Application.Run(AppInfo.Container.ResolveNamed
("Form2")); - } private static void Application_ThreadException(object sender, ThreadExceptionEventArgs ex)