林豪 左 3 years ago
parent
commit
0b9ae9c850

+ 9 - 9
DBHelper/DB.cs

@@ -53,7 +53,7 @@ namespace DBHelper
             SetDefaultDbContextType(typeof(T));
         }
 
-        private Dictionary<Type, DbContext> Contexts = new Dictionary<Type, DbContext>();
+        private Dictionary<Type, DbContext> _contexts = new Dictionary<Type, DbContext>();
 
         public T Context<T>() where T : DbContext
         {
@@ -72,13 +72,13 @@ namespace DBHelper
 
         public DbContext Context(Type type)
         {
-            if (Contexts.ContainsKey(type))
-                return Contexts[type];
+            if (_contexts.ContainsKey(type))
+                return _contexts[type];
             else
             {
                 var ctx = Activator.CreateInstance(type) as DbContext;
                 ctx.Database.BeginTransaction();
-                Contexts.Add(type, ctx);
+                _contexts.Add(type, ctx);
                 return ctx;
             }
         }
@@ -88,7 +88,7 @@ namespace DBHelper
             Exception exception = null;
             try
             {
-                foreach (var ctx in Contexts.Values)
+                foreach (var ctx in _contexts.Values)
                 {
                     ctx.SaveChanges();
                 }
@@ -106,7 +106,7 @@ namespace DBHelper
                 exception = ex.GetBaseException();
             }
 
-            foreach (var ctx in Contexts.Values)
+            foreach (var ctx in _contexts.Values)
             {
                 try
                 {
@@ -127,10 +127,10 @@ namespace DBHelper
 
         public void Dispose()
         {
-            foreach (var ctx in Contexts.Values)
+            foreach (var ctx in _contexts.Values)
                 ctx.Dispose();
-            Contexts.Clear();
-            Contexts = null;
+            _contexts.Clear();
+            _contexts = null;
         }
     }
 

+ 1 - 1
PLC.Siemens/Communication/IsoSocket.cs

@@ -100,7 +100,7 @@ namespace PLC.Siemens.Communication
                     conneted = true;
                 }
             }
-            catch(Exception ex)
+            catch(Exception)
             {
                 conneted = false;
             }

+ 1 - 1
PLC.Siemens/Core/Extension/ByteExtenstion.cs

@@ -114,7 +114,7 @@ namespace Core.Util.Extension
                     }
                 }
             }
-            catch (Exception ex)
+            catch (Exception)
             {
                // XTrace.WriteException(ex);
                 // ignored

+ 32 - 0
Projects/永冠OPP/WCS.Service/PLCAccessors/AllenBradleyPLC.cs

@@ -0,0 +1,32 @@
+using HslCommunication.Profinet.AllenBradley;
+using System;
+
+namespace WCS.Service.PLCAccessors
+{
+    public class AllenBradleyPLC : AllenBradleyNet
+    {
+        public AllenBradleyNet plc;
+
+        public AllenBradleyPLC(string ipAddress)
+        {
+            plc = new AllenBradleyNet(ipAddress);
+        }
+
+        public byte[] ReadBytes(ushort db, ushort address, ushort length)
+        {
+            var addr = "DB" + db + "." + address;
+            var res = plc.Read(addr, length);
+            if (res.IsSuccess)
+                return res.Content;
+            throw new Exception("读取PLC数据失败:" + res.Message);
+        }
+
+        public void WriteBytes(ushort db, ushort address, byte[] data)
+        {
+            var start = db + address / 2;
+            var res = plc.Write("D" + start, data);
+            if (!res.IsSuccess)
+                throw new Exception("写入PLC数据失败:" + res.Message);
+        }
+    }
+}

+ 1 - 2
Projects/永冠OPP/WCS.Service/PLCAccessors/MelsecPLC.cs

@@ -9,14 +9,13 @@ using HslCommunication.Profinet.Melsec;
 
 namespace WCS.Service.PLCAccessors
 { 
-    public class MelsecPLC : IPLCAccessor
+    public class MelsecPLC : MelsecMcNet
     {
         MelsecMcNet plc;
         public MelsecPLC(string ip,int port)
         {
             plc = new MelsecMcNet(ip, port);
             plc.ConnectTimeOut = 3000;
-            //plc.ReceiveTimeOut = 500;
             plc.ConnectServer();
           
         }

+ 12 - 13
Projects/永冠OPP/WCS.Service/PLCAccessors/PLCAccessorsCreater.cs

@@ -1,22 +1,21 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using WCS.Core;
+using HslCommunication.Core;
+using System;
+using WCS.Core.DataTrans;
 using WCS.Entity;
-using HslCommunication.Profinet.Melsec; 
 
 namespace WCS.Service.PLCAccessors
 {
-    public class PLCAccessorsCreater : IPLCAccessorCreater
+    public class PlcAccessorsCreater : IPlcAccessorCreater
     {
-        public IPLCAccessor Create(WCS_PLC data)
+        public IReadWriteNet Create(WCS_PLC data)
         {
-            if (data.TYPE == PLCType.西门子)
-                return new SiemensS7PLC(data.IP, data.PORT,data.RACK,data.SLOT);
-            else
-                throw new Exception("不支持此PLC");
+            return data.TYPE switch
+            {
+                PLCType.西门子 => new SiemensS7PLC((int)data.MODEL, data.IP),
+                PLCType.三菱 => new MelsecPLC(data.IP, data.PORT),
+                //PLCType.AB=>
+                _ => throw new Exception("不支持此PLC")
+            };
         }
     }
 }

+ 10 - 35
Projects/永冠OPP/WCS.Service/PLCAccessors/SiemensS7PLC.cs

@@ -1,49 +1,24 @@
-using System;
-using HslCommunication.Profinet.Siemens;
-using WCS.Core;
+using HslCommunication.Profinet.Siemens;
+using System;
 
 namespace WCS.Service.PLCAccessors
 {
-    public class SiemensS7PLC : IPLCAccessor
+    public class SiemensS7PLC : SiemensS7Net
     {
-        private PLC.Siemens.O.SimenssPlc plc;
-
-        public SiemensS7PLC(string ip, int port, int rack, int slot)
-        {
-            plc = new PLC.Siemens.O.SimenssPlc(ip, rack, slot);
-            plc.Connect();
-        }
+        private SiemensS7Net plc;
 
-        public byte[] ReadBytes(ushort db, ushort address, ushort length)
+        public SiemensS7PLC(SiemensPLCS type) : base(type)
         {
-            if (!plc.Connected)
-                plc.Connect();
-            var res = plc.ReadArea(PLC.Siemens.Protocol.Common.AreaType.DB, db, address, length, PLC.Siemens.Protocol.Common.DataType.Byte);
-            if (res == null)
-                throw new Exception("读取DB块数据失败");
-            return res.Data;
         }
 
-        public void WriteBytes(ushort db, ushort address, byte[] data)
+        public SiemensS7PLC(SiemensPLCS type, string ip) : base(type, ip)
         {
-            if (!plc.Connected)
-                plc.Connect();
-            var res = plc.WriteArea(PLC.Siemens.Protocol.Common.AreaType.DB, db, address, (ushort)data.Length, PLC.Siemens.Protocol.Common.DataType.Byte, data);
-            if (!res)
-                throw new Exception("写入DB块数据失败");
+            plc = new SiemensS7Net(type, ip);
         }
-    }
-
-    public class SiemensS7PLCHsl : IPLCAccessor
-    {
-        private SiemensS7Net plc;
 
-        public SiemensS7PLCHsl(string ip)
+        public SiemensS7PLC(int type, string ip) : base((SiemensPLCS)type, ip)
         {
-            plc = new SiemensS7Net(SiemensPLCS.S1500, ip);
-            plc.ConnectTimeOut = 3000;
-            //plc.ReceiveTimeOut = 500;
-            plc.ConnectServer();
+            plc = new SiemensS7Net((SiemensPLCS)type, ip);
         }
 
         public byte[] ReadBytes(ushort db, ushort address, ushort length)
@@ -63,4 +38,4 @@ namespace WCS.Service.PLCAccessors
                 throw new Exception("写入PLC数据失败:" + res.Message);
         }
     }
-}
+}

+ 2 - 1
Projects/永冠OPP/WCS.Service/Program.cs

@@ -48,10 +48,11 @@ namespace WCS.Service
                         web.UseUrls("http://*:8080"); //设备访问端口
                         web.UseStartup<Startup>(); //调用启动服务
                     })
-                    .ConfigureServices((hostContext, services) =>
+                    .ConfigureServices((_, services) =>
                     {
                         //services.AddDbContext<WCSDB>();
                         services.AddHostedService<Worker>();
+                        services.AddHttpClient();
                     });
             }
             return Host.CreateDefaultBuilder(args)

+ 3 - 9
Projects/永冠OPP/WCS.Service/ProtocolProxy.cs

@@ -26,7 +26,7 @@ namespace WCS.Service
             _setMethod = typeof(DbContext).GetMethod("Set", new Type[] { })?.MakeGenericMethod(this.ProtocolDataType);
         }
 
-        private static readonly ConcurrentDictionary<Type, object[]> LastDatas = new ConcurrentDictionary<Type, object[]>();
+        private static readonly ConcurrentDictionary<Type, object[]> LastDatas = new();
 
         protected override WCS_PROTOCOLDATA GetLastData(Db db)
         {
@@ -83,9 +83,6 @@ namespace WCS.Service
             return newobj;
         }
 
-        //static ConcurrentQueue<PackInfo> Packs = new ConcurrentQueue<PackInfo>();
-        private static Dictionary<string, Playerback> _clients = new Dictionary<string, Playerback>();
-
         private static readonly RedisClient Redis;
         public static RedisClient Yg150Redis;
         public static RedisClient Ygwms150Redis;
@@ -94,7 +91,6 @@ namespace WCS.Service
         static ProtocolProxy()
         {
             MessagePackSerializer.DefaultOptions = StandardResolver.Options.WithCompression(MessagePackCompression.Lz4Block);
-            //Redis = new RedisClient("192.168.249.120,password=123456,database=11");
             Redis = new RedisClient("212.64.66.35,database=10");
             Redis.Serialize = obj =>
             {
@@ -168,9 +164,7 @@ namespace WCS.Service
             }
         }
 
-        private static Dictionary<string, string> _lastInfo = new Dictionary<string, string>();
-
-        public static ConcurrentDictionary<string, DeviceData> AllDatas = new ConcurrentDictionary<string, DeviceData>();
+        public static ConcurrentDictionary<string, DeviceData> AllDatas = new();
 
         public static void Do()
         {
@@ -225,7 +219,6 @@ namespace WCS.Service
 
                 foreach (var data in AllDatas)
                 {
-                    // LastInfo[data.Key] = data.Value.Info;
                     data.Value.Info = "";
                     if (data.Value is not ProdLineData pld) continue;
                     pld.TaskList.Clear();
@@ -235,6 +228,7 @@ namespace WCS.Service
             }
             catch (Exception)
             {
+                // ignored
             }
         }
     }

+ 2 - 1
Projects/永冠OPP/WCS.Service/Uploader.cs

@@ -17,7 +17,7 @@ namespace WCS.Service
                 {
                     try
                     {
-                        WMS.UpdateTask(task.ADDRNEXT?.ToString(), task.WMSTASK, (int)task.STATUS, task.HEIGHT);
+                        WMS.UpdateTask(task.ADDRNEXT, task.WMSTASK, (int)task.STATUS, task.HEIGHT);
                         var st = task.UPLOADED;
                         task.UPLOADED = task.STATUS;
                         InfoLog.INFO_SYTASKSTATUS($"[{task.ID}]---old:[{st}]-new:[{task.UPLOADED}]---{task.HEIGHT}");
@@ -32,6 +32,7 @@ namespace WCS.Service
             }
             catch
             {
+                // ignored
             }
         }
     }

+ 2 - 11
Projects/永冠OPP/WCS.Service/WCS.Service.csproj

@@ -13,7 +13,6 @@
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="Logs" Version="1.0.0.1" />
     <PackageReference Include="MessagePack" Version="2.4.35" />
     <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
     <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.6">
@@ -31,21 +30,13 @@
     <PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" />
     <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.6" />
     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.1" />
+    <PackageReference Include="WCS.Core" Version="1.0.0.2" />
   </ItemGroup>
 
   <ItemGroup>
     <ProjectReference Include="..\..\..\DBHelper-SqlSugar\DBHelper-SqlSugar.csproj" />
-    <ProjectReference Include="..\..\..\WCS.Core\WCS.Core.csproj" />
+    <ProjectReference Include="..\..\..\Logs\Logs.csproj" />
     <ProjectReference Include="..\..\..\WCS.Entity\WCS.Entity.csproj" />
     <ProjectReference Include="..\WCS.Entity.Protocol\WCS.Entity.Protocol.csproj" />
   </ItemGroup>
-
-  <ItemGroup>
-    <Reference Include="PLC.Siemens">
-      <HintPath>..\..\..\PLC.Siemens\bin\Debug\PLC.Siemens.dll</HintPath>
-    </Reference>
-    <Reference Include="PLCConnecter">
-      <HintPath>..\..\..\DLL\PLCConnecter.dll</HintPath>
-    </Reference>
-  </ItemGroup>
 </Project>

+ 4 - 1
Projects/永冠OPP/WCS.Service/WebApi/APICaller.cs

@@ -8,6 +8,7 @@ using System.IO;
 using System.Net;
 using System.Text;
 using System.Threading.Tasks;
+using static System.Net.WebRequest;
 
 namespace WCS.Service
 {
@@ -87,7 +88,9 @@ namespace WCS.Service
             var sw = new Stopwatch();
             sw.Start();
             var encoding = Encoding.UTF8;
-            var request = (HttpWebRequest)WebRequest.Create(url);//webrequest请求api地址
+#pragma warning disable SYSLIB0014
+            var request = (HttpWebRequest)Create(url);//webrequest请求api地址
+#pragma warning restore SYSLIB0014
             request.Timeout = 60000;//连接超时
             request.ReadWriteTimeout = 3600000;//读写超时
             request.Accept = "text/html,application/xhtml+xml,*/*";

+ 2 - 1
Projects/永冠OPP/WCS.Service/WebApi/ViewModels/DeviceStatusViewModel.cs

@@ -1,4 +1,5 @@
-using WCS.Entity;
+#nullable enable
+using WCS.Entity;
 
 namespace WCS.Service.WebApi.ViewModels
 {

+ 29 - 4
Projects/永冠OPP/WCS.Service/Worker.cs

@@ -13,7 +13,9 @@ using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
 using WCS.Core;
+using WCS.Core.DataTrans;
 using WCS.Entity;
+using WCS.Entity.Protocol;
 
 namespace WCS.Service
 {
@@ -34,10 +36,12 @@ namespace WCS.Service
             #region 启用日志
 
             var logConfig = JsonConvert.DeserializeObject<LogConfig>(await File.ReadAllTextAsync("config.json", Encoding.Default, stoppingToken));
-            Logs.LogHelper.SetConfigInfo(logConfig!);
+            LogHelper.SetConfigInfo(logConfig!);
 
             #endregion 启用日志
 
+            InfoLog.INFO_INIT("1111");
+
             _logger.LogInformation("WCS开始启动");
             //InfoLog.INFO_INIT("WCS开始启动");
             Configs.DebugRedisUrl = "127.0.0.1";
@@ -57,10 +61,31 @@ namespace WCS.Service
                 db.Default.CodeFirst.InitTables(typeof(WCS_CMD));
                 db.Default.CodeFirst.InitTables(typeof(WCS_PLC));
                 db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
+                db.Default.CodeFirst.InitTables(typeof(WCS_DEVICE));
+                db.Default.CodeFirst.InitTables(typeof(WCS_PATH));
+                db.Default.CodeFirst.InitTables(typeof(WCS_PATHPOINT));
+                db.Default.CodeFirst.InitTables(typeof(WCS_ROUTE));
+                db.Default.CodeFirst.InitTables(typeof(WCS_TASK));
+                db.Default.CodeFirst.InitTables(typeof(WCS_TASK_OLD));
+                db.Default.CodeFirst.InitTables(typeof(WCS_EXCEPTION));
+                db.Default.CodeFirst.InitTables(typeof(WCS_SystemConfig));
+                db.Default.CodeFirst.InitTables(typeof(WCS_AGVTask));
+                db.Default.CodeFirst.InitTables(typeof(WCS_DEVICEPROTOCOL));
+                db.Default.CodeFirst.InitTables(typeof(WCS_GROUPMEMBER));
+                db.Default.CodeFirst.InitTables(typeof(WCS_MAPPINGENTRY));
+                db.Default.CodeFirst.InitTables(typeof(WCS_USERS));
+                db.Default.CodeFirst.InitTables(typeof(WCS_StatusLog));
+                //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
+                //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
+                //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
+                //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
+                //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
+                //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
+                //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
                 //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
             });
 
-            //日志发布事件
+            //日志发布事件s
             Configs.PublishEvent += () =>
             {
                 WMS.UploadDevInfo();
@@ -81,7 +106,7 @@ namespace WCS.Service
 
             //LogicHandler.DbLog = Helpers.LogHelper.AddWCS_EXCEPTION;
 
-            PLCAccessor.Creater = new PLCAccessors.PLCAccessorsCreater();
+            PlcAccessor.Creater = new PLCAccessors.PlcAccessorsCreater();
             try
             {
                 Db.Do(db =>
@@ -90,7 +115,7 @@ namespace WCS.Service
                    .Includes(v => v.DEVICE.ROUTES)
                    .Includes(v => v.DEVICE.PATHS)
                    .Includes(v => v.DB.PLC).ToArray();
-                    var objects = items.Select(v => v.Data()).ToArray();
+                    items.Select(v => v.Data()).ToArray();
                     LogicHandler.AllObjects.AddRange(items);
 
                     var devices = db.Default.Queryable<WCS_DEVICE>().Includes(v => v.ROUTES).Includes(v => v.PATHS).Includes(v => v.DEVICEGROUP).ToArray();

+ 33 - 0
RabbitMQ/Class1.cs

@@ -0,0 +1,33 @@
+namespace RabbitMQ
+{
+    public class RB
+    {
+        /// <summary>
+        /// IP
+        /// </summary>
+        public static string IP { get; set; }
+
+        /// <summary>
+        /// 端口
+        /// </summary>
+        public static int Port { get; set; }
+
+        /// <summary>
+        /// 用户名
+        /// </summary>
+        public static string UserName { get; set; }
+
+        /// <summary>
+        /// 密码
+        /// </summary>
+        public static string Password { get; set; }
+
+        public RB(string _ip, int _port, string _userName, string _password)
+        {
+            IP = _ip;
+            Port = _port;
+            UserName = _userName;
+            Password = _password;
+        }
+    }
+}

+ 12 - 0
RabbitMQ/RabbitMQ.csproj

@@ -0,0 +1,12 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>netstandard2.1</TargetFramework>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="RabbitMQ.Client" Version="6.4.0" />
+  </ItemGroup>
+
+</Project>

+ 12 - 0
TEST/AppSettings.cs

@@ -0,0 +1,12 @@
+namespace TEST
+{
+    public class AppSettings
+    {
+        public static IConfiguration Config { get; private set; }
+
+        static AppSettings()
+        {
+            Config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json").Build();
+        }
+    }
+}

+ 10 - 0
TEST/Program.cs

@@ -0,0 +1,10 @@
+using TEST;
+
+IHost host = Host.CreateDefaultBuilder(args)
+    .ConfigureServices(services =>
+    {
+        services.AddHostedService<Worker>();
+    })
+    .Build();
+
+await host.RunAsync();

+ 11 - 0
TEST/Properties/launchSettings.json

@@ -0,0 +1,11 @@
+{
+  "profiles": {
+    "TEST": {
+      "commandName": "Project",
+      "dotnetRunMessages": true,
+      "environmentVariables": {
+        "DOTNET_ENVIRONMENT": "Development"
+      }
+    }
+  }
+}

+ 20 - 0
TEST/TEST.csproj

@@ -0,0 +1,20 @@
+<Project Sdk="Microsoft.NET.Sdk.Worker">
+
+  <PropertyGroup>
+    <TargetFramework>net6.0</TargetFramework>
+    <Nullable>enable</Nullable>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <UserSecretsId>dotnet-TEST-2751B22E-C0CE-443B-BEC8-5B1B6FF38409</UserSecretsId>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\DBHelper-SqlSugar\DBHelper-SqlSugar.csproj" />
+    <ProjectReference Include="..\Logs\Logs.csproj" />
+    <ProjectReference Include="..\Projects\永冠OPP\WCS.Entity.Protocol\WCS.Entity.Protocol.csproj" />
+    <ProjectReference Include="..\WCS.Entity\WCS.Entity.csproj" />
+  </ItemGroup>
+</Project>

+ 62 - 0
TEST/Worker.cs

@@ -0,0 +1,62 @@
+using DBHelper_SqlSugar;
+using SqlSugar;
+using WCS.Entity;
+using WCS.Entity.Protocol;
+
+namespace TEST
+{
+    public class Worker : BackgroundService
+    {
+        private readonly ILogger<Worker> _logger;
+
+        public Worker(ILogger<Worker> logger)
+        {
+            _logger = logger;
+        }
+
+        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
+        {
+            Db.CreateContext(new ConnectionConfig()
+            {
+                ConnectionString = AppSettings.Config.GetConnectionString("WCSDB"),
+                DbType = DbType.MySql
+            }, "WCSDB");
+            Db.SetDefaultDbContextType("WCSDB");
+            Db.Do(db =>
+            {
+                //TODO:DbMaintenance.CreateDatabase()并没起到作用,如果没有对应的数据库的话任然需要手动新建一个
+                db.Default.DbMaintenance.CreateDatabase();
+                db.Default.CodeFirst.InitTables(typeof(WCS_CMD));
+                db.Default.CodeFirst.InitTables(typeof(WCS_PLC));
+                db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
+                db.Default.CodeFirst.InitTables(typeof(WCS_DEVICE));
+                db.Default.CodeFirst.InitTables(typeof(WCS_PATH));
+                db.Default.CodeFirst.InitTables(typeof(WCS_PATHPOINT));
+                db.Default.CodeFirst.InitTables(typeof(WCS_ROUTE));
+                db.Default.CodeFirst.InitTables(typeof(WCS_TASK));
+                db.Default.CodeFirst.InitTables(typeof(WCS_TASK_OLD));
+                db.Default.CodeFirst.InitTables(typeof(WCS_EXCEPTION));
+                db.Default.CodeFirst.InitTables(typeof(WCS_SystemConfig));
+                db.Default.CodeFirst.InitTables(typeof(WCS_AGVTask));
+                db.Default.CodeFirst.InitTables(typeof(WCS_DEVICEPROTOCOL));
+                db.Default.CodeFirst.InitTables(typeof(WCS_GROUPMEMBER));
+                db.Default.CodeFirst.InitTables(typeof(WCS_MAPPINGENTRY));
+                db.Default.CodeFirst.InitTables(typeof(WCS_USERS));
+                db.Default.CodeFirst.InitTables(typeof(WCS_StatusLog));
+                //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
+                //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
+                //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
+                //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
+                //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
+                //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
+                //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
+                //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
+            });
+            //while (!stoppingToken.IsCancellationRequested)
+            //{
+            //    _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
+            //    await Task.Delay(1000, stoppingToken);
+            //}
+        }
+    }
+}

+ 8 - 0
TEST/appsettings.Development.json

@@ -0,0 +1,8 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Information",
+      "Microsoft.Hosting.Lifetime": "Information"
+    }
+  }
+}

+ 8 - 0
TEST/appsettings.json

@@ -0,0 +1,8 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Information",
+      "Microsoft.Hosting.Lifetime": "Information"
+    }
+  }
+}

+ 14 - 0
WCS Pedestal.sln

@@ -34,6 +34,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DBHelper-SqlSugar", "DBHelp
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlSugar", "..\..\..\..\开源\Src\Asp.NetCore2\SqlSugar\SqlSugar.csproj", "{9993C299-72BF-4F5A-AEAB-F1B41DF01FBC}"
 EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TEST", "TEST\TEST.csproj", "{71A6030B-66E3-4D6F-8EB6-6C102493AF74}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RabbitMQ", "RabbitMQ\RabbitMQ.csproj", "{8C246D8E-92CA-48EB-9694-4A9F4D03D9D0}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -80,6 +84,14 @@ Global
 		{9993C299-72BF-4F5A-AEAB-F1B41DF01FBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{9993C299-72BF-4F5A-AEAB-F1B41DF01FBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{9993C299-72BF-4F5A-AEAB-F1B41DF01FBC}.Release|Any CPU.Build.0 = Release|Any CPU
+		{71A6030B-66E3-4D6F-8EB6-6C102493AF74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{71A6030B-66E3-4D6F-8EB6-6C102493AF74}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{71A6030B-66E3-4D6F-8EB6-6C102493AF74}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{71A6030B-66E3-4D6F-8EB6-6C102493AF74}.Release|Any CPU.Build.0 = Release|Any CPU
+		{8C246D8E-92CA-48EB-9694-4A9F4D03D9D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{8C246D8E-92CA-48EB-9694-4A9F4D03D9D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{8C246D8E-92CA-48EB-9694-4A9F4D03D9D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{8C246D8E-92CA-48EB-9694-4A9F4D03D9D0}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -96,6 +108,8 @@ Global
 		{8F6C4A79-98EA-4019-B72A-29290328185A} = {2C6BCFE4-581D-4BC8-91EC-BD9FA91B9605}
 		{A3E602C7-597C-469F-A065-BBA5901FFE2C} = {2C6BCFE4-581D-4BC8-91EC-BD9FA91B9605}
 		{9993C299-72BF-4F5A-AEAB-F1B41DF01FBC} = {2C6BCFE4-581D-4BC8-91EC-BD9FA91B9605}
+		{71A6030B-66E3-4D6F-8EB6-6C102493AF74} = {2C6BCFE4-581D-4BC8-91EC-BD9FA91B9605}
+		{8C246D8E-92CA-48EB-9694-4A9F4D03D9D0} = {2C6BCFE4-581D-4BC8-91EC-BD9FA91B9605}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {75D30B04-ADD6-4FC6-8D7E-FAD45B731BB4}

+ 2 - 2
WCS.Core/DataTrans/Extentions.cs

@@ -525,9 +525,9 @@ namespace WCS.Core
             return GetEx<DataBlock>(source);
         }
 
-        public static PLCAccessor Ex(this WCS_PLC source)
+        public static PlcAccessor Ex(this WCS_PLC source)
         {
-            return GetEx<PLCAccessor>(source);
+            return GetEx<PlcAccessor>(source);
         }
 
         public static WCS_DEVICEPROTOCOL PROTOCOL(this IProtocol obj)

+ 15 - 16
WCS.Core/DataTrans/IPLCAccessor.cs

@@ -1,29 +1,28 @@
-using System;
-using System.Collections.Generic;
-using System.Data;
-using System.Text;
-using WCS.Entity; 
+using HslCommunication.Core;
+using WCS.Entity;
 
-namespace WCS.Core
+namespace WCS.Core.DataTrans
 {
-
-    public interface IPLCAccessorCreater
+    public interface IPlcAccessorCreater
     {
-        IPLCAccessor Create(WCS_PLC data);
+        IReadWriteNet Create(WCS_PLC data);
     }
-    public interface IPLCAccessor
+
+    public interface IPlcAccessor : IReadWriteNet
     {
         void WriteBytes(ushort db, ushort address, byte[] data);
+
         byte[] ReadBytes(ushort db, ushort address, ushort length);
     }
 
-    public class PLCAccessor : EntityEx<WCS_PLC>
+    public class PlcAccessor : EntityEx<WCS_PLC>
     {
-        public static IPLCAccessorCreater Creater;
-        public IPLCAccessor Accessor { get; private set; }
-        public PLCAccessor(WCS_PLC entity) : base(entity)
+        public static IPlcAccessorCreater Creater;
+        public IPlcAccessor Accessor { get; private set; }
+
+        public PlcAccessor(WCS_PLC entity) : base(entity)
         {
-            Accessor = Creater.Create(entity);
-        } 
+            Accessor = (IPlcAccessor)Creater.Create(entity);
+        }
     }
 }

+ 1 - 0
WCS.Core/LogicHandler.cs

@@ -116,6 +116,7 @@ namespace WCS.Core
         /// </summary>
         private static void Loop()
         {
+            //TODO:可能存在异常,使用时需验证一次
             var arr = AllObjects.OfType<WCS_DEVICE>().Where(v => v.ENABLED).SelectMany(v => v.DEVICEPROTOCOLS)
                 .Where(v => v.ENABLED && v.DB.ENABLED && v.DB.PLC.ENABLED)
                 .GroupBy(v => v.DB).Select(v => v.Key)

+ 5 - 1
WCS.Core/WCS.Core.csproj

@@ -2,6 +2,9 @@
 
   <PropertyGroup>
     <TargetFramework>net6.0</TargetFramework>
+    <AssemblyVersion>1.0.0.2</AssemblyVersion>
+    <FileVersion>1.0.0.2</FileVersion>
+    <Version>1.0.0.2</Version>
   </PropertyGroup>
 
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -9,8 +12,9 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="DBHelper-SqlSugar" Version="1.0.0" />
+    <PackageReference Include="DBHelper-SqlSugar" Version="1.0.0.1" />
     <PackageReference Include="FreeRedis" Version="0.3.5" />
+    <PackageReference Include="HslCommunication" Version="6.2.2" />
     <PackageReference Include="Logs" Version="1.0.0.1" />
   </ItemGroup>
 

+ 2 - 1
WCS.Entity/WCS_DATABLOCK.cs

@@ -12,7 +12,8 @@ namespace WCS.Entity
         /// <summary>
         /// ID
         /// </summary>
-        [SugarColumn(IsIgnore = true), Obsolete]
+        [SugarColumn(IsIgnore = true)]
+        [Obsolete]
         public override int ID { get; set; }
 
         /// <summary>

+ 2 - 1
WCS.Entity/WCS_DEVICE.cs

@@ -10,7 +10,8 @@ namespace WCS.Entity
     [SugarTable(nameof(WCS_DEVICE), "设备列表")]
     public class WCS_DEVICE : OBJ
     {
-        [SugarColumn(IsIgnore = true), Obsolete]
+        [SugarColumn(IsIgnore = true)]
+        [Obsolete]
         public override int ID { get; set; }
 
         /// <summary>

+ 0 - 0
WCS.Entity/WCS_DEVICEGROUP.cs → WCS.Entity/WCS_GROUPMEMBER.cs


+ 46 - 2
WCS.Entity/WCS_PLC.cs

@@ -9,7 +9,8 @@ namespace WCS.Entity
     [SugarTable(nameof(WCS_PLC), "PLC信息")]
     public class WCS_PLC : OBJ
     {
-        [SugarColumn(IsIgnore = true), Obsolete]
+        [SugarColumn(IsIgnore = true)]
+        [Obsolete]
         public override int ID { get; set; }
 
         /// <summary>
@@ -58,9 +59,12 @@ namespace WCS.Entity
         /// 型号
         /// </summary>
         [SugarColumn(ColumnDescription = "型号", Length = 10)]
-        public string MODEL { get; set; }
+        public PLCMODEL MODEL { get; set; }
     }
 
+    /// <summary>
+    /// 设备厂商
+    /// </summary>
     public enum PLCType
     {
         西门子 = 1,
@@ -68,4 +72,44 @@ namespace WCS.Entity
         AB = 3,
         欧姆龙 = 4,
     }
+
+    /// <summary>
+    /// PLC型号
+    /// </summary>
+    public enum PLCMODEL
+    {
+        #region 西门子
+
+        /// <summary>
+        /// 1200系列
+        /// </summary>
+        S1200 = 1,
+
+        /// <summary>
+        /// 300系列
+        /// </summary>
+        S300 = 2,
+
+        /// <summary>
+        /// 400系列
+        /// </summary>
+        S400 = 3,
+
+        /// <summary>
+        /// 1500系列PLC
+        /// </summary>
+        S1500 = 4,
+
+        /// <summary>
+        /// 200的smart系列
+        /// </summary>
+        S200Smart = 5,
+
+        /// <summary>
+        /// 200系统,需要额外配置以太网模块
+        /// </summary>
+        S200 = 6
+
+        #endregion 西门子
+    }
 }