lixun před 2 roky
rodič
revize
70cb683c9b

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

@@ -31,7 +31,7 @@ namespace YSAI.Can
             /// 打开的CAN通道
             /// </summary>
             [Description("打开的CAN通道")]
-            public int CanChannel { get; set; }
+            public int CanChannel { get; set; } = 0;
             /// <summary>
             /// 重写基类中的Equals方法
             /// </summary>

+ 1 - 1
src/YSAI.DAQ/YSAI.Controls/hamburgermenu/HamburgerMenuItem.xaml

@@ -30,7 +30,7 @@
                                             <ColumnDefinition/>
                                         </Grid.ColumnDefinitions>
                                         <Grid Grid.Column="1">
-                                            <TextBlock Text="{TemplateBinding Text}" Margin="5,10,10,10" HorizontalAlignment="Left" VerticalAlignment="Center"  FontSize="{DynamicResource AllContentFontSize}" Foreground="{TemplateBinding Foreground}" TextWrapping="Wrap"/>
+                                            <TextBlock Text="{TemplateBinding Text}" Margin="5,10,10,10" HorizontalAlignment="Left" VerticalAlignment="Center"  FontSize="{DynamicResource AllFontSize}" Foreground="{TemplateBinding Foreground}" TextWrapping="Wrap"/>
                                         </Grid>
                                         <Grid Grid.Column="0">
                                             <Image Source="{TemplateBinding Icon}" Margin="15,10,10,10" Height="20"/>

+ 13 - 11
src/YSAI.DAQ/YSAI.Manage.Core/base/ManageBaseOperate.cs

@@ -610,7 +610,7 @@ namespace YSAI.Manage.Core.@base
                             case DaqType.Modbus:
 
                                 //判断是否有此实例
-                                if (!DBDaqObjArray.ContainsKey(SN))
+                                if (!ModbusDaqObjArray.ContainsKey(SN))
                                 {
                                     return Break("On", false, $"[ {DType} ] [ {SN} ] 实例不存在");
                                 }
@@ -632,14 +632,14 @@ namespace YSAI.Manage.Core.@base
                                 break;
                             case DaqType.OpcDaHttp:
                                 //判断是否有此实例
-                                if (!DBDaqObjArray.ContainsKey(SN))
+                                if (!OpcDaHttpDaqObjArray.ContainsKey(SN))
                                 {
                                     return Break("On", false, $"[ {DType} ] [ {SN} ] 实例不存在");
                                 }
                                 break;
                             case DaqType.S7:
                                 //判断是否有此实例
-                                if (!DBDaqObjArray.ContainsKey(SN))
+                                if (!S7DaqObjArray.ContainsKey(SN))
                                 {
                                     return Break("On", false, $"[ {DType} ] [ {SN} ] 实例不存在");
                                 }
@@ -735,11 +735,13 @@ namespace YSAI.Manage.Core.@base
                                     }
                                     break;
                                 case DaqType.Modbus:
+
                                     //判断是否有此实例
                                     if (!ModbusDaqObjArray.ContainsKey(SN))
                                     {
                                         return Break("On", false, $"[ {DType} ] [ {SN} ] 实例不存在");
                                     }
+
                                     break;
                                 case DaqType.OpcUa:
                                     //判断是否有此实例
@@ -873,7 +875,7 @@ namespace YSAI.Manage.Core.@base
                             case DaqType.Modbus:
 
                                 //判断是否有此实例
-                                if (!DBDaqObjArray.ContainsKey(SN))
+                                if (!ModbusDaqObjArray.ContainsKey(SN))
                                 {
                                     return Break("On", false, $"[ {DType} ] [ {SN} ] 实例不存在");
                                 }
@@ -895,14 +897,14 @@ namespace YSAI.Manage.Core.@base
                                 break;
                             case DaqType.OpcDaHttp:
                                 //判断是否有此实例
-                                if (!DBDaqObjArray.ContainsKey(SN))
+                                if (!OpcDaHttpDaqObjArray.ContainsKey(SN))
                                 {
                                     return Break("On", false, $"[ {DType} ] [ {SN} ] 实例不存在");
                                 }
                                 break;
                             case DaqType.S7:
                                 //判断是否有此实例
-                                if (!DBDaqObjArray.ContainsKey(SN))
+                                if (!S7DaqObjArray.ContainsKey(SN))
                                 {
                                     return Break("On", false, $"[ {DType} ] [ {SN} ] 实例不存在");
                                 }
@@ -1013,7 +1015,7 @@ namespace YSAI.Manage.Core.@base
                             case DaqType.Modbus:
 
                                 //判断是否有此实例
-                                if (!DBDaqObjArray.ContainsKey(SN))
+                                if (!ModbusDaqObjArray.ContainsKey(SN))
                                 {
                                     return Break("On", false, $"[ {DType} ] [ {SN} ] 实例不存在");
                                 }
@@ -1035,14 +1037,14 @@ namespace YSAI.Manage.Core.@base
                                 break;
                             case DaqType.OpcDaHttp:
                                 //判断是否有此实例
-                                if (!DBDaqObjArray.ContainsKey(SN))
+                                if (!OpcDaHttpDaqObjArray.ContainsKey(SN))
                                 {
                                     return Break("On", false, $"[ {DType} ] [ {SN} ] 实例不存在");
                                 }
                                 break;
                             case DaqType.S7:
                                 //判断是否有此实例
-                                if (!DBDaqObjArray.ContainsKey(SN))
+                                if (!S7DaqObjArray.ContainsKey(SN))
                                 {
                                     return Break("On", false, $"[ {DType} ] [ {SN} ] 实例不存在");
                                 }
@@ -1066,8 +1068,8 @@ namespace YSAI.Manage.Core.@base
                                         case DataType.Bool:
                                             pairs.TryAdd(int.Parse(AddressName).ToUshort(), bool.Parse(Value));
                                             break;
-                                        case DataType.Double:
-                                            pairs.TryAdd(int.Parse(AddressName).ToUshort(), double.Parse(Value));
+                                        case DataType.Float:
+                                            pairs.TryAdd(int.Parse(AddressName).ToUshort(), float.Parse(Value));
                                             break;
                                         case DataType.Int:
                                             pairs.TryAdd(int.Parse(AddressName).ToUshort(), int.Parse(Value));

+ 2 - 2
src/YSAI.DAQ/YSAI.Resources/style/Style_Button.xaml

@@ -57,7 +57,7 @@
         <Setter Property="VerticalAlignment" Value="Center"/>
     </Style>
     <Style x:Key="ButtonTextBlockStyle" TargetType="{x:Type TextBlock}">
-        <Setter Property="FontSize" Value="{DynamicResource AllContentFontSize}"/>
+        <Setter Property="FontSize" Value="{DynamicResource AllFontSize}"/>
         <Setter Property="VerticalAlignment" Value="Center"/>
         <Setter Property="HorizontalAlignment" Value="Center"/>
         <Setter Property="Width" Value="auto"/>
@@ -124,7 +124,7 @@
         <Setter Property="Background" Value="White"/>
         <Setter Property="BorderBrush" Value="{DynamicResource Control.Border.Color}"/>
         <Setter Property="BorderThickness" Value="0,0,0,1"></Setter>
-        <Setter Property="FontSize" Value="{DynamicResource AllContentFontSize}"/>
+        <Setter Property="FontSize" Value="{DynamicResource AllFontSize}"/>
         <Setter Property="Template">
             <Setter.Value>
                 <ControlTemplate TargetType="{x:Type Button}">

+ 21 - 7
src/YSAI.DAQ/YSAI.S7/client/S7ClientOperate.cs

@@ -1,8 +1,11 @@
 
 using S7.Net;
+using S7.Net.Types;
 using StackExchange.Redis;
 using System.Collections.Concurrent;
 using System.Net.Sockets;
+using System.Runtime.CompilerServices;
+using System.Text;
 using YSAI.Core.data;
 using YSAI.Core.@interface.only;
 using YSAI.Core.@interface.unify;
@@ -178,22 +181,26 @@ namespace YSAI.S7.client
                         }
                         else
                         {
+                            //获取地址数据项
+                            DataItem dataItem = DataItem.FromAddress(item.AddressName);
                             switch (item.AddressDataType)
                             {
                                 case Core.@enum.DataType.Bool:
-                                    Value = ((byte)PlcS7?.Read(item.AddressName)).SelectBit(0).ToString();
+                                    Value = PlcS7?.ReadBytes(dataItem.DataType, dataItem.DB, dataItem.StartByteAdr, dataItem.Count).ValToBinString().BinStringToByte().Value.SelectBit(0).ToString();
                                     break;
                                 case Core.@enum.DataType.String:
-                                    Value = PlcS7?.Read(item.AddressName).ValToBinString();
+                                    byte[]? head = PlcS7?.ReadBytes(dataItem.DataType, dataItem.DB, dataItem.StartByteAdr, 2);
+                                    byte[]? bytes = PlcS7?.ReadBytes(dataItem.DataType, dataItem.DB, dataItem.StartByteAdr + 2, head[1]);
+                                    Value = Encoding.ASCII.GetString(bytes).TrimEnd(new char[] { '\0' });
                                     break;
                                 case Core.@enum.DataType.Float:
-                                    Value = ((uint)PlcS7?.Read(item.AddressName)).ConvertToFloat().ToString();
+                                    Value = ((uint)PlcS7?.Read(dataItem.DataType, dataItem.DB, dataItem.StartByteAdr, dataItem.VarType, dataItem.Count)).ConvertToFloat().ToString();
                                     break;
                                 case Core.@enum.DataType.Int:
-                                    Value = ((uint)PlcS7?.Read(item.AddressName)).ConvertToInt().ToString();
+                                    Value = ((uint)PlcS7?.Read(dataItem.DataType, dataItem.DB, dataItem.StartByteAdr, dataItem.VarType, dataItem.Count)).ConvertToInt().ToString();
                                     break;
                                 default:
-                                    Value = "不支持此类型读取";
+                                    Value = $"不支持{item.AddressDataType}类型读取";
                                     break;
                             }
                         }
@@ -229,7 +236,7 @@ namespace YSAI.S7.client
         {
             return Task.Run(() => Write(Values));
         }
-
+       
         public OperateResult Write<V>(ConcurrentDictionary<string, V> Values)
         {
             //开始记录运行时间
@@ -254,7 +261,14 @@ namespace YSAI.S7.client
                         }
                         else
                         {
-                            PlcS7.Write(Param.Key, Param.Value);
+                            if (typeof(V).Name.Contains("String"))
+                            {
+                                PlcS7.Write(Param.Key, Param.Value.ToString().GetString());
+                            }
+                            else
+                            {
+                                PlcS7.Write(Param.Key, Param.Value);
+                            }
                         }
                     }
                     if (FailMessage.Count > 0)

+ 4 - 0
src/YSAI.DAQ/YSAI.S7/client/S7Unility.cs

@@ -1,4 +1,5 @@
 using System.Globalization;
+using System.Text;
 using S7.Net;
 using S7.Net.Types;
 
@@ -220,5 +221,8 @@ namespace YSAI.S7.client
             output = Real.FromByteArray(DWord.ToByteArray(input));
             return output;
         }
+
+
+       
     }
 }

+ 4 - 4
src/YSAI.DAQ/YSAI.Test/TestAll.cs

@@ -195,7 +195,7 @@ namespace YSAI.Test
                 address.AddressArray.Add(new AddressDetails()
                 {
                     AddressName = "Õâ.ÊÇ.Ò».¸ö.Ðé.Äâ.µã",
-                    AddressDataType = DataType.String,
+                    AddressDataType = Core.@enum.DataType.String,
                     AddressType = AddressType.Virtual
                 });
 
@@ -925,7 +925,7 @@ namespace YSAI.Test
             address.AddressArray.Add(new AddressDetails()
             {
                 AddressName = "DB71.DBD4",
-                AddressDataType = Core.@enum.DataType.Float,
+                AddressDataType = Core.@enum.DataType.String,
                 AddressType = AddressType.Reality
             });
 
@@ -942,8 +942,8 @@ namespace YSAI.Test
             }
 
             //дÈë
-            ConcurrentDictionary<string, float> keyValuePairs = new ConcurrentDictionary<string, float>();
-            keyValuePairs.TryAdd("DB71.DBD4", 1.6666f);
+            ConcurrentDictionary<string, string> keyValuePairs = new ConcurrentDictionary<string, string>();
+            keyValuePairs.TryAdd("DB71.DBD4", "bbbb");
             operateResult = s7ClientOperate.Write(keyValuePairs);
             Console.WriteLine(operateResult.Message);
         }

+ 4 - 3
src/YSAI.DAQ/YSAI.TestConsole/Program.cs

@@ -22,6 +22,7 @@ using YSAI.Unility;
 using static YSAI.Core.reflection.ReflectionData;
 using static YSAI.Core.reflection.ReflectionData.Basics.DllData.NamespaceData;
 using YSAI.Core.@enum;
+using System.Text;
 
 namespace YSAI.TestConsole
 {
@@ -29,17 +30,17 @@ namespace YSAI.TestConsole
     {
         static void Main(string[] args)
         {
-           
-            
 
 
+           
+
 
             while (true)
             {
                 Console.ReadKey();
             }
         }
-
+       
 
     }
 }

+ 17 - 0
src/YSAI.DAQ/YSAI.Tool.Windows/YSAI.Tool.Windows.csproj

@@ -22,4 +22,21 @@
     <PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1988-prerelease" />
   </ItemGroup>
 
+  <ItemGroup>
+    <Folder Include="modbus\client\" />
+    <Folder Include="modbus\service\" />
+    <Folder Include="mqtt\client\" />
+    <Folder Include="mqtt\service\webScoket\" />
+    <Folder Include="opc\da\client\" />
+    <Folder Include="opc\da\http\" />
+    <Folder Include="opc\ua\client\" />
+    <Folder Include="opc\ua\service\" />
+    <Folder Include="can\" />
+    <Folder Include="kafka\" />
+    <Folder Include="rabbitMQ\" />
+    <Folder Include="s7\client\" />
+    <Folder Include="s7\service\" />
+    <Folder Include="apiOperate\" />
+  </ItemGroup>
+
 </Project>

+ 3 - 3
src/YSAI.DAQ/YSAI.Unility/EnumTool.cs

@@ -56,7 +56,7 @@ namespace YSAI.Unility
                 }
                 // get enum value
                 int value = (int)enumName.InvokeMember(field.Name, BindingFlags.GetField, null, null, null);
-                string text = field.Name;
+                string name = field.Name;
                 string description = string.Empty;
                 object[] array = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
                 if (array.Length > 0)
@@ -70,8 +70,8 @@ namespace YSAI.Unility
                 //add to list
                 dynamic obj = new ExpandoObject();
                 obj.Value = value;
-                obj.Text = text;
-                obj.Description = description;
+                obj.Name = name;
+                obj.Describe = description;
                 list.Add(obj);
             }
             return list;

+ 15 - 0
src/YSAI.DAQ/YSAI.Unility/ExtensionTool.cs

@@ -730,5 +730,20 @@ namespace YSAI.Unility
             string str = ASCIIEncoding.ASCII.GetString(outByte).Trim();
             return str;
         }
+
+        /// <summary>
+        /// 获取西门子PLC字符串数组--String
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static byte[] GetString(this string str)
+        {
+            byte[] value = Encoding.ASCII.GetBytes(str);
+            byte[] head = new byte[2];
+            head[0] = System.Convert.ToByte(254);
+            head[1] = System.Convert.ToByte(str.Length);
+            value = head.Concat(value).ToArray();
+            return value;
+        }
     }
 }

+ 16 - 16
src/YSAI.DAQ/YSAI.Unility/ReflexTool.cs

@@ -151,17 +151,17 @@ namespace YSAI.Unility
             foreach (PropertyInfo pi in t.GetProperties())
             {
                 LibInstanceParam libInstanceParam = new LibInstanceParam();
-                libInstanceParam.name = pi.Name;
-                libInstanceParam.describe = pi.GetDescription();
-                libInstanceParam.paramType = pi.PropertyType.Name.ToString();
+                libInstanceParam.Name = pi.Name;
+                libInstanceParam.Describe = pi.GetDescription();
+                libInstanceParam.ParamType = pi.PropertyType.Name.ToString();
                 if (pi.PropertyType.BaseType.Name.Equals("Enum"))
                 {
-                    libInstanceParam.paramType = "Enum";
-                    libInstanceParam.enumArray = pi.PropertyType.GetAllItems();
+                    libInstanceParam.ParamType = "Enum";
+                    libInstanceParam.EnumArray = pi.PropertyType.GetAllItems();
                 }
                 else
                 {
-                    libInstanceParam.objArray= GetClassAllPropertyData(pi.PropertyType);
+                    libInstanceParam.ObjArray= GetClassAllPropertyData(pi.PropertyType);
                 }
                 libInstanceParams.Add(libInstanceParam);
             }
@@ -183,13 +183,13 @@ namespace YSAI.Unility
                 foreach (PropertyInfo pi in t.GetProperties())
                 {
                     LibInstanceParam libInstanceParam = new LibInstanceParam();
-                    libInstanceParam.name = pi.Name;
-                    libInstanceParam.describe = pi.GetDescription();
-                    libInstanceParam.paramType = pi.PropertyType.Name.ToString();
+                    libInstanceParam.Name = pi.Name;
+                    libInstanceParam.Describe = pi.GetDescription();
+                    libInstanceParam.ParamType = pi.PropertyType.Name.ToString();
                     if (pi.PropertyType.BaseType.Name.Equals("Enum"))
                     {
-                        libInstanceParam.paramType = "Enum";
-                        libInstanceParam.enumArray = pi.PropertyType.GetAllItems();
+                        libInstanceParam.ParamType = "Enum";
+                        libInstanceParam.EnumArray = pi.PropertyType.GetAllItems();
                     }
                     libInstanceParams.Add(libInstanceParam);
                 }
@@ -213,23 +213,23 @@ namespace YSAI.Unility
             /// <summary>
             /// 名称
             /// </summary>
-            public string name { get; set; }
+            public string Name { get; set; }
             /// <summary>
             /// 描述
             /// </summary>
-            public string describe { get; set; }
+            public string Describe { get; set; }
             /// <summary>
             /// 参数类型
             /// </summary>
-            public string paramType { get; set; }
+            public string ParamType { get; set; }
             /// <summary>
             /// 枚举集合
             /// </summary>
-            public object enumArray { get; set; }
+            public object EnumArray { get; set; }
             /// <summary>
             /// 对象数据集合
             /// </summary>
-            public object objArray { get; set; }
+            public object ObjArray { get; set; }
         }
     }
 }

+ 1 - 1
src/YSAI.DAQ/YSAI.Window/Themes/Property/Black.xaml

@@ -120,7 +120,7 @@
     <!--版本图标位置偏移-->
     <Thickness x:Key="VerImageMargin"  Left="4" Top="4" Right="0" Bottom="4" />
     <!--所有内容的字体大小-->
-    <sys:Double x:Key="AllContentFontSize">13</sys:Double>
+    <sys:Double x:Key="AllFontSize">13</sys:Double>
 
 
     <!--顶部的圆角控制-->

+ 1 - 1
src/YSAI.DAQ/YSAI.Window/Themes/Property/Blue.xaml

@@ -120,7 +120,7 @@
     <!--版本图标位置偏移-->
     <Thickness x:Key="VerImageMargin"  Left="4" Top="4" Right="0" Bottom="4" />
     <!--所有内容的字体大小-->
-    <sys:Double x:Key="AllContentFontSize">13</sys:Double>
+    <sys:Double x:Key="AllFontSize">13</sys:Double>
 
 
     <!--顶部的圆角控制-->

+ 1 - 1
src/YSAI.DAQ/YSAI.Window/Themes/Property/Cyan.xaml

@@ -120,7 +120,7 @@
     <!--版本图标位置偏移-->
     <Thickness x:Key="VerImageMargin"  Left="4" Top="4" Right="0" Bottom="4" />
     <!--所有内容的字体大小-->
-    <sys:Double x:Key="AllContentFontSize">13</sys:Double>
+    <sys:Double x:Key="AllFontSize">13</sys:Double>
 
 
     <!--顶部的圆角控制-->

+ 1 - 1
src/YSAI.DAQ/YSAI.Window/Themes/Property/White.xaml

@@ -120,7 +120,7 @@
     <!--版本图标位置偏移-->
     <Thickness x:Key="VerImageMargin"  Left="4" Top="4" Right="0" Bottom="4" />
     <!--所有内容的字体大小-->
-    <sys:Double x:Key="AllContentFontSize">13</sys:Double>
+    <sys:Double x:Key="AllFontSize">13</sys:Double>
 
 
     <!--顶部的圆角控制-->

+ 1 - 1
src/YSAI.DAQ/YSAI.WindowMessage/Window.xaml

@@ -26,7 +26,7 @@
                 <ColumnDefinition Width="auto"/>
             </Grid.ColumnDefinitions>
             <Image Grid.Column="0" Source="{Binding IconImage}" Width="32" VerticalAlignment="{Binding ImageVerticalAlignment}"/>
-            <Label Grid.Column="1" VerticalContentAlignment="Center"  FontSize="{DynamicResource AllContentFontSize}" HorizontalContentAlignment="Center" Content="{Binding Content_Info}" Name="ContentControl" Foreground="{DynamicResource Font.Content.Foreground}"/>
+            <Label Grid.Column="1" VerticalContentAlignment="Center"  FontSize="{DynamicResource AllFontSize}" HorizontalContentAlignment="Center" Content="{Binding Content_Info}" Name="ContentControl" Foreground="{DynamicResource Font.Content.Foreground}"/>
         </Grid>
         <Border Grid.Row="2" BorderThickness="0,1,0,0"  Height="45" CornerRadius="{DynamicResource DownCornerRadius}" VerticalAlignment="Bottom"  Background="{DynamicResource VerBackgroundBrush}">
             <Border.Effect>