lixun 2 anos atrás
pai
commit
7993e30bf6

+ 1 - 1
src/YSAI.DAQ/YSAI.Can/CanOperator.cs

@@ -289,7 +289,7 @@ namespace YSAI.Can
 
         public Task<OperateResult> ReadAsync(Address address)
         {
-            throw new NotImplementedException();
+            return Task.Run(()=> Read(address));
         }
 
         public OperateResult Write(ConcurrentDictionary<int, byte[]> Values)

+ 24 - 54
src/YSAI.DAQ/YSAI.Core/data/AddressHandler.cs

@@ -133,22 +133,19 @@ namespace YSAI.Core.data
 
             try
             {
-                if (RegisterEvent())
+                //类的唯一标识符
+                string ClassSN = "YSAI.RelayManage.RelayManageOperate[Instance]";
+                //方法的唯一标识符
+                string MethodSN = "[Produce]";
+                //执行转发方法
+                OperateResult operateResult = reflectionOperate.ExecuteMethod($"{ClassSN}{MethodSN}", new object[] { PacketType.Message.ToString(), addressValue.ToJson().JsonFormatting() }) as OperateResult;
+                //状态判断
+                if (!operateResult.State)
                 {
-                    //类的唯一标识符
-                    string ClassSN = "YSAI.RelayManage.RelayManageOperate[Instance]";
-                    //方法的唯一标识符
-                    string MethodSN = "[Produce]";
-                    //执行转发方法
-                    OperateResult operateResult = reflectionOperate.ExecuteMethod($"{ClassSN}{MethodSN}", new object[] { PacketType.Message.ToString(), addressValue.ToJson().JsonFormatting() }) as OperateResult;
-                    //状态判断
-                    if (!operateResult.State)
-                    {
-                        DynamicObj.Value = addressValue;
-                        DynamicObj.State = operateResult.State;
-                        DynamicObj.Exception = operateResult.Message;
-                        LogHelper.Error(DynamicObj.ToJson(), logName);
-                    }
+                    DynamicObj.Value = addressValue;
+                    DynamicObj.State = operateResult.State;
+                    DynamicObj.Exception = operateResult.Message;
+                    LogHelper.Error(DynamicObj.ToJson(), logName);
                 }
             }
             catch (Exception ex)
@@ -158,52 +155,25 @@ namespace YSAI.Core.data
         }
 
         /// <summary>
-        /// 注册事件状态
-        /// </summary>
-        private static bool RegisterEventState = false;
-        /// <summary>
-        /// 执行注册事件
+        /// 转发事件外部注册
         /// </summary>
         /// <returns></returns>
-        private static bool RegisterEvent()
+        public static bool RelayEventRegister(Action<object, object> action)
         {
-            if (!RegisterEventState)
+            //类的唯一标识符
+            string ClassSN = "YSAI.RelayManage.RelayManageOperate[Instance]";
+            //事件的唯一标识符
+            string EventSN = "[OnEvent]";
+            //注册事件
+            OperateResult operateResult = reflectionOperate.RegisterEvent($"{ClassSN}{EventSN}", true, P2: action);
+            if (!operateResult.State)
             {
-                //类的唯一标识符
-                string ClassSN = "YSAI.RelayManage.RelayManageOperate[Instance]";
-                //事件的唯一标识符
-                string EventSN = "[OnEvent]";
-                //注册事件
-                OperateResult operateResult = reflectionOperate.RegisterEvent($"{ClassSN}{EventSN}", true, P2: RelayManageOperate_OnEvent);
-                if (!operateResult.State)
-                {
-                    throw new Exception($"注册事件失败:{operateResult.Message}");
-                }
-                RegisterEventState = operateResult.State;
-                return operateResult.State;
+                throw new Exception($"注册事件失败:{operateResult.Message}");
             }
-            return true;
+            return operateResult.State;
         }
 
-        /// <summary>
-        /// 转发的事件注册
-        /// </summary>
-        /// <param name="sender"></param>
-        /// <param name="e"></param>
-        /// <exception cref="NotImplementedException"></exception>
-        private static void RelayManageOperate_OnEvent(object? sender, object e)
-        {
-            //日志文件名称
-            string logName = "RelayEvent.log";
-            EventResult eventResult = e as EventResult;
-            if (eventResult != null)
-            {
-                if (!eventResult.State)
-                {
-                    LogHelper.Error(eventResult.ToJson().JsonFormatting(), logName);
-                }
-            }
-        }
+       
 
     }
 }

+ 3 - 3
src/YSAI.DAQ/YSAI.DAQ.sln

@@ -67,9 +67,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "manage", "manage", "{ECAD41
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YSAI.DaqManage", "YSAI.DaqManage\YSAI.DaqManage.csproj", "{41AB3A5A-5372-4A75-898C-9A4F9454F8A5}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YSAI.RelayManage", "YSAI.RelayManage\YSAI.RelayManage.csproj", "{DD9020DC-A51F-48F2-83FA-A3F10A43220F}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YSAI.RelayManage", "YSAI.RelayManage\YSAI.RelayManage.csproj", "{DD9020DC-A51F-48F2-83FA-A3F10A43220F}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YSAI.Test.Console", "YSAI.Test.Console\YSAI.Test.Console.csproj", "{623C8558-8901-4D69-B1AC-1615597E8B88}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YSAI.Test.Console", "YSAI.Test.Console\YSAI.Test.Console.csproj", "{623C8558-8901-4D69-B1AC-1615597E8B88}"
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lib", "lib", "{7EB5153B-7702-4D7B-8592-FE6D992682AB}"
 EndProject
@@ -224,7 +224,7 @@ Global
 		{0EA9373C-B55A-4400-82AC-7681AA996229} = {6F526F44-A5B0-49D5-8E04-DBFDB5F8E6C6}
 		{257F1474-B220-4C61-88C6-5B83BEF7B3A7} = {D60224CF-7F12-453B-851E-B5C01F9D2BBE}
 		{49133ADB-D3BF-4682-AA5A-CC1CF1917D45} = {1856E9E1-33C4-45C1-832C-854F9BE1ACC4}
-		{2221CE78-FA24-40E3-8453-9C66E32F9C0C} = {ECAD410C-2895-4836-BCA7-D4EF340E778E}
+		{2221CE78-FA24-40E3-8453-9C66E32F9C0C} = {1856E9E1-33C4-45C1-832C-854F9BE1ACC4}
 		{9D8EDBBA-7A97-4D84-9B12-7FCC2F834046} = {7EB5153B-7702-4D7B-8592-FE6D992682AB}
 		{41AB3A5A-5372-4A75-898C-9A4F9454F8A5} = {ECAD410C-2895-4836-BCA7-D4EF340E778E}
 		{DD9020DC-A51F-48F2-83FA-A3F10A43220F} = {ECAD410C-2895-4836-BCA7-D4EF340E778E}

+ 25 - 17
src/YSAI.DAQ/YSAI.DaqManage/DaqManageOperate.cs

@@ -375,28 +375,36 @@ namespace YSAI.DaqManage
         /// <param name="lib">库文件</param>
         private void SearchType(string lib)
         {
-            //加载程序集
-            Assembly assembly = Assembly.LoadFrom(lib);
-            //获取所有类
-            Type[] types = assembly.GetExportedTypes();
-            //过滤器
-            TypeFilter typeFilter = new TypeFilter(InterfaceFilter);
-            //集合
-            List<Type> typesArray = new List<Type>();
-            //检索类是否继承接口
-            foreach (Type type in types)
+            try
             {
-                if (type.FindInterfaces(typeFilter, basics.InterfaceFullName).Count() > 0)
+                //加载程序集
+                Assembly assembly = Assembly.LoadFrom(lib);
+                //获取所有类
+                Type[] types = assembly.GetExportedTypes();
+                //过滤器
+                TypeFilter typeFilter = new TypeFilter(InterfaceFilter);
+                //集合
+                List<Type> typesArray = new List<Type>();
+                //检索类是否继承接口
+                foreach (Type type in types)
+                {
+                    if (type.FindInterfaces(typeFilter, basics.InterfaceFullName).Count() > 0)
+                    {
+                        typesArray.Add(type);
+                    }
+                }
+                //添加至集合
+                foreach (Type type in typesArray)
                 {
-                    typesArray.Add(type);
+                    TypeIoc.TryAdd(type.FullName, type);
+                    //抛出信息
+                    OnEventHandler?.Invoke(this, new EventResult(true, $"{type.FullName} 程序集添加成功"));
                 }
             }
-            //添加至集合
-            foreach (Type type in typesArray)
+            catch (Exception)
             {
-                TypeIoc.TryAdd(type.FullName, type);
-                //抛出信息
-                OnEventHandler?.Invoke(this, new EventResult(true, $"{type.FullName} 程序集添加成功"));
+                Thread.Sleep(1);
+                SearchType(lib);
             }
         }
         /// <summary>

+ 25 - 17
src/YSAI.DAQ/YSAI.RelayManage/RelayManageOperate.cs

@@ -397,28 +397,36 @@ namespace YSAI.RelayManage
         /// <param name="lib">库文件</param>
         private void SearchType(string lib)
         {
-            //加载程序集
-            Assembly assembly = Assembly.LoadFrom(lib);
-            //获取所有类
-            Type[] types = assembly.GetExportedTypes();
-            //过滤器
-            TypeFilter typeFilter = new TypeFilter(InterfaceFilter);
-            //集合
-            List<Type> typesArray = new List<Type>();
-            //检索类是否继承接口
-            foreach (Type type in types)
+            try
             {
-                if (type.FindInterfaces(typeFilter, basics.InterfaceFullName).Count() > 0)
+                //加载程序集
+                Assembly assembly = Assembly.LoadFrom(lib);
+                //获取所有类
+                Type[] types = assembly.GetExportedTypes();
+                //过滤器
+                TypeFilter typeFilter = new TypeFilter(InterfaceFilter);
+                //集合
+                List<Type> typesArray = new List<Type>();
+                //检索类是否继承接口
+                foreach (Type type in types)
+                {
+                    if (type.FindInterfaces(typeFilter, basics.InterfaceFullName).Count() > 0)
+                    {
+                        typesArray.Add(type);
+                    }
+                }
+                //添加至集合
+                foreach (Type type in typesArray)
                 {
-                    typesArray.Add(type);
+                    TypeIoc.TryAdd(type.FullName, type);
+                    //抛出信息
+                    OnEventHandler?.Invoke(this, new EventResult(true, $"{type.FullName} 程序集添加成功"));
                 }
             }
-            //添加至集合
-            foreach (Type type in typesArray)
+            catch (Exception)
             {
-                TypeIoc.TryAdd(type.FullName, type);
-                //抛出信息
-                OnEventHandler?.Invoke(this, new EventResult(true, $"{type.FullName} 程序集添加成功"));
+                Thread.Sleep(1);
+                SearchType(lib);
             }
         }
         /// <summary>

+ 11 - 4
src/YSAI.DAQ/YSAI.Test.Console/Program.cs

@@ -25,9 +25,9 @@ foreach (var item in ints)
 
 
 DaqManageOperate manageOperate = new DaqManageOperate();
-manageOperate.OnEvent += ManageOperate_OnEvent;
-
+manageOperate.OnEvent += DaqEvent;
 
+AddressHandler.RelayEventRegister(RelayEvent);
 
 while (manageOperate != null)
 {
@@ -113,9 +113,16 @@ while (manageOperate != null)
 }
 
 
-
- void ManageOperate_OnEvent(object? sender, YSAI.Core.data.EventResult e)
+void RelayEvent(object? sender, object e)
+{
+    EventResult? result = JsonTool.StringToJsonEntity<EventResult>(e.ToJson());
+    Console.ForegroundColor = ConsoleColor.Red;
+    Console.WriteLine(result.Message);
+}
+void DaqEvent(object? sender, YSAI.Core.data.EventResult e)
 {
+    if (e.Message == "点位数据更新")
+        return;
     Console.ForegroundColor = ConsoleColor.Green;
     Console.WriteLine(e.Message);
 }