Procházet zdrojové kódy

primarily complete

chenzk před 4 dny
rodič
revize
c4595c599f

+ 47 - 4
Beckoff/BeckhoffIOManager.cs

@@ -5,6 +5,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using TwinCAT.TypeSystem;
 
 namespace FestoDebugger.Beckoff
 {
@@ -41,6 +42,12 @@ namespace FestoDebugger.Beckoff
         /// IO数据长度
         /// </summary>
         public int Size { get { return _size; } }
+        /// <summary>
+        /// 模块变量-数值字典
+        /// </summary>
+        private Dictionary<string, object> _moduleNameVariableValueDic = new Dictionary<string, object>();
+
+
         #endregion
         /// <summary>
         /// 初始化
@@ -48,8 +55,25 @@ namespace FestoDebugger.Beckoff
         /// <param name="cfg"></param>
         public void Initialize(BeckhoffCfg cfg)
         {
+            SubscribeIoItemList();
             InitialAccessors(cfg);
         }
+
+        public Dictionary<string, object> GetNameValueDic()
+        {
+            _moduleNameVariableValueDic.Clear();
+            List<string> keys = _nameVariableValueDic.Keys.ToList();
+            foreach (string item in keys)
+            {
+                if(!_nameVariableValueDic.ContainsKey(item))
+                {
+                    continue;
+                }
+                string ModuleName = BeckhoffModuleIOManager.Instance.GetInnerModuleNameByIOName(item);
+                _moduleNameVariableValueDic.Add(ModuleName, _nameVariableValueDic[item]);
+            }
+            return _moduleNameVariableValueDic;
+        } 
         /// <summary>
         /// 初始化
         /// </summary>
@@ -103,14 +127,30 @@ namespace FestoDebugger.Beckoff
         /// <param name="arg1"></param>
         /// <param name="args"></param>
         /// <returns></returns>
-        private bool WriteDoOperation(string arg1, object[] args)
+        public bool WriteDoOperation(string arg1, object[] args)
         {
-            string name = (string)args[0];
+            string moduleName = (string)args[0];
             bool setpoint = (bool)args[1];
-            BeckhoffItem item = BeckhoffItemManager.Instance.GetWriteBeckhoffItem(name);
-            return TwincatAdoManager.Instance.WriteValue(name, setpoint);
+            string IOName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName(moduleName);
+            BeckhoffItem item = BeckhoffItemManager.Instance.GetWriteBeckhoffItem(IOName);
+            return TwincatAdoManager.Instance.WriteValue(IOName, setpoint);
         }
         
+        /// <summary>
+        /// 订阅IO集合
+        /// </summary>
+        private void SubscribeIoItemList()
+        {
+            if (!_ioItemList.ContainsKey(DI_ITEMLIST))
+            {
+                _ioItemList[DI_ITEMLIST] = new List<NotifiableIoItem>();
+            }
+
+            if (!_ioItemList.ContainsKey(DO_ITEMLIST))
+            {
+                _ioItemList[DO_ITEMLIST] = new List<NotifiableIoItem>();
+            }
+        }
 
         #region 获取Accessor和Item
         public BeckhoffDIAccessor GetDIAccessor(string name)
@@ -124,6 +164,7 @@ namespace FestoDebugger.Beckoff
 
         #endregion
 
+
         /// <summary>
         /// 注册变量数值发生变化回调
         /// </summary>
@@ -144,6 +185,8 @@ namespace FestoDebugger.Beckoff
                 }
             }
         }
+
+
         /// <summary>
         /// 更新IO数值
         /// </summary>

+ 2 - 8
Beckoff/BeckhoffManager.cs

@@ -11,12 +11,6 @@ namespace FestoDebugger.Beckoff
     public class BeckhoffManager : Singleton<BeckhoffManager>
     {
         #region 内部常量
-        private const string DI_ITEMLIST = "System.DIItemList";
-        private const string DO_ITEMLIST = "System.DOItemList";
-        private const string AI_ITEMLIST = "System.AIItemList";
-        private const string AO_ITEMLIST = "System.AOItemList";
-        private const string DIGITAL = "Digital";
-        private const string ANALOG = "Analog";
         #endregion
         #region 内部变量
         BeckhoffCfg _cfg = null;
@@ -36,9 +30,9 @@ namespace FestoDebugger.Beckoff
         {
             string xmlPath = "";
     
-            xmlPath = Directory.GetParent(Directory.GetCurrentDirectory()).FullName + "Config\\Beckhoffcfg.xml";
+            xmlPath = Directory.GetParent(Directory.GetCurrentDirectory()).FullName + "\\net8.0-windows\\Config\\Beckhoffcfg.xml";
             
-            BeckhoffModuleIOManager.Instance.Initialize(Directory.GetParent(Directory.GetCurrentDirectory()).FullName + "Config\\ModuleIoCfg.xml");
+            BeckhoffModuleIOManager.Instance.Initialize(Directory.GetParent(Directory.GetCurrentDirectory()).FullName + "\\net8.0-windows\\Config\\ModuleIoCfg.xml");
             _cfg = CustomXmlSerializer.Deserialize<BeckhoffCfg>(new FileInfo(xmlPath));
             if (_cfg != null)
             {

+ 1 - 1
Beckoff/TwincatAdoManager.cs

@@ -151,7 +151,7 @@ namespace FestoDebugger.Beckoff
         private void CreateWriteHandle()
         {
             _writeNameHandleDic.Clear();
-            foreach (BeckhoffItem item in BeckhoffItemManager.Instance.GetWriteItems())
+            foreach (BeckhoffItem item in BeckhoffItemManager.Instance.GetIOItems())
             {
                 try
                 {

+ 12 - 14
Config/ModuleIoCfg.xml

@@ -1,36 +1,34 @@
 <?xml version="1.0" encoding="utf-8" ?>
 <BeckhoffModuleIOCfg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
-	<Module Name="SRD1">
+	<Module Name="N1">
 		
-		<IO Name="SRD1.DoorClosed" IOName="r_SRD1_SHUTTER_CLOSED"/>
-		<IO Name="SRD1.DoorOpened" IOName="r_SRD1_SHUTTER_OPEN"/>
+		<IO Name="DI1" IOName="r_SRD1_SHUTTER_CLOSED"/>
+		<IO Name="DI2" IOName="r_SRD1_SHUTTER_OPEN"/>
 
 	</Module>
 
-	<Module Name="Rinse1">
+	<Module Name="N2">
 
-		<IO Name="Rinse1.N2Valve" IOName="c_QDRD1_LO_PRESSURE"/>
+		<IO Name="DO1" IOName="c_QDRD1_LO_PRESSURE"/>
 	</Module>
 
 
-	<Module Name="Rinse2">
+	<Module Name="N3">
 	
 
-		<IO Name="Rinse2.N2Valve" IOName="c_QDRD2_LO_PRESSURE"/>
+		<IO Name="DO2" IOName="c_QDRD2_LO_PRESSURE"/>
 	</Module>
 
-	<Module Name="Rinse7">
+	<Module Name="N5">
 
 
-		<IO Name="Rinse7.N2Valve" IOName="c_QDRD7_LO_PRESSURE"/>
+		<IO Name="DO3" IOName="c_QDRD7_LO_PRESSURE"/>
 	</Module>
 
-	<Module Name="Rinse8">
-
->
-		<IO Name="Rinse8.N2Valve" IOName="c_QDRD8_LO_PRESSURE"/>
-	</Module>
+	<Module Name="N6">
 
 
+		<IO Name="DO4" IOName="c_QDRD8_LO_PRESSURE"/>
+	</Module>
 
 </BeckhoffModuleIOCfg>

+ 19 - 0
FestoDebugger.csproj

@@ -8,4 +8,23 @@
     <UseWPF>true</UseWPF>
   </PropertyGroup>
 
+  <ItemGroup>
+    <None Remove="Config\Beckhoffcfg.xml" />
+    <None Remove="Config\ModuleIoCfg.xml" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <Content Include="Config\Beckhoffcfg.xml">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+    <Content Include="Config\ModuleIoCfg.xml">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Autofac" Version="8.3.0" />
+    <PackageReference Include="Beckhoff.TwinCAT.Ads" Version="4.4.40" />
+  </ItemGroup>
+
 </Project>

+ 14 - 5
Models/SignalModuleData.cs

@@ -1,4 +1,5 @@
-using System;
+using FestoDebugger.Common;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -6,10 +7,18 @@ using System.Threading.Tasks;
 
 namespace FestoDebugger.Models
 {
-    public class SignalModuleData
+    public class SignalModuleData: NotifiableItem
     {
-        public string ModuleName { get; set; }
-        public bool SignalAOn { get; set; }
-        public bool SignalBOn { get; set; }
+        private string _moduleName;
+        
+        private bool _signalOn;
+
+        public string ModuleName
+        {
+            get { return _moduleName; }
+            set { _moduleName = value; InvokePropertyChanged(nameof(_moduleName)); }
+        }
+
+        public bool SignalOn { get { return _signalOn; } set { _signalOn = value; InvokePropertyChanged(nameof(SignalOn)); } }
     }
 }

+ 22 - 39
UserControls/FestoControl.xaml

@@ -5,7 +5,7 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:FestoDebugger.UserControls"
              mc:Ignorable="d" x:Name="self"
-             d:DesignHeight="180" d:DesignWidth="100">
+             d:DesignHeight="180" d:DesignWidth="50">
     <Border BorderBrush="Gray" BorderThickness="1">
     <Grid>
         <Grid.RowDefinitions>
@@ -13,52 +13,35 @@
             <RowDefinition Height="50"/>
             <RowDefinition Height="50"/>
             <RowDefinition Height="30"/>
-            <RowDefinition Height="30"/>
             <RowDefinition/>
         </Grid.RowDefinitions>
         <Grid.ColumnDefinitions>
 
             <ColumnDefinition Width="50"/>
-            <ColumnDefinition Width="50"/>
 
             <ColumnDefinition/>
         </Grid.ColumnDefinitions>
-        <Label  Grid.Row="0" Grid.Column="0"  HorizontalAlignment="Center" Content="A" FontSize="12" VerticalContentAlignment="Center" VerticalAlignment="Center" />
-        <Label  Grid.Row="0" Grid.Column="1"  HorizontalAlignment="Center" Content="B" FontSize="12" VerticalContentAlignment="Center" VerticalAlignment="Center" />
-        <Label  Grid.Row="4" Grid.Column="0"  Grid.ColumnSpan="2" HorizontalAlignment="Center" Content="{Binding ModuleName}" FontSize="12" VerticalContentAlignment="Center" VerticalAlignment="Top" />
+            <Label  Grid.Row="0" Grid.Column="0"   HorizontalAlignment="Center" Content="{Binding ModuleName}" FontSize="10" VerticalContentAlignment="Center" VerticalAlignment="Center" />
         
-        <Button  Grid.Row="1" Grid.Column="0" Width="40" Height="30" Background="DeepSkyBlue" Content="On" Click="AOn_Click" Canvas.Left="60" Canvas.Top="39"></Button>
-        <Button  Grid.Row="2" Grid.Column="0" Width="40" Height="30" Background="DeepSkyBlue" Content="Off"  Click="AOff_Click" Canvas.Left="101" Canvas.Top="40"></Button>
-        <Button  Grid.Row="1" Grid.Column="1" Width="40" Height="30" Background="DeepSkyBlue" Content="On" Click="BOn_Click" Canvas.Left="60" Canvas.Top="39"></Button>
-        <Button  Grid.Row="2" Grid.Column="1" Width="40" Height="30" Background="DeepSkyBlue" Content="Off"  Click="BOff_Click" Canvas.Left="101" Canvas.Top="40"></Button>
-        <Ellipse Grid.Row="3" Grid.Column="0" Width="16" Height="16" Stroke="Silver" HorizontalAlignment="Center" VerticalAlignment="Top">
-            <Ellipse.Style>
-                <Style TargetType="Ellipse">
-                    <!-- 默认颜色(SignalOn为false时) -->
-                    <Setter Property="Fill" Value="LightGray"/>
-                    <Style.Triggers>
-                        <!-- 当SignalOn为true时变为绿色 -->
-                        <DataTrigger Binding="{Binding SignalAOn}" Value="True">
-                            <Setter Property="Fill" Value="LimeGreen"/>
-                        </DataTrigger>
-                    </Style.Triggers>
-                </Style>
-            </Ellipse.Style>
-        </Ellipse>
-        <Ellipse Grid.Row="3" Grid.Column="1" Width="16" Height="16" Stroke="Silver" HorizontalAlignment="Center" VerticalAlignment="Top">
-            <Ellipse.Style>
-                <Style TargetType="Ellipse">
-                    <!-- 默认颜色(SignalOn为false时) -->
-                    <Setter Property="Fill" Value="LightGray"/>
-                    <Style.Triggers>
-                        <!-- 当SignalOn为true时变为绿色 -->
-                        <DataTrigger Binding="{Binding SignalBOn}" Value="True">
-                            <Setter Property="Fill" Value="LimeGreen"/>
-                        </DataTrigger>
-                    </Style.Triggers>
-                </Style>
-            </Ellipse.Style>
-        </Ellipse>
-    </Grid>
+        <Button  Grid.Row="1" Grid.Column="0" Width="40" Height="30" Background="DeepSkyBlue" Content="On" Click="On_Click" Canvas.Left="60" Canvas.Top="39"></Button>
+        <Button  Grid.Row="2" Grid.Column="0" Width="40" Height="30" Background="DeepSkyBlue" Content="Off"  Click="Off_Click" Canvas.Left="101" Canvas.Top="40"></Button>
+            <Ellipse Grid.Row="3" Grid.Column="0" Width="16" Height="16" Stroke="Silver" HorizontalAlignment="Center" VerticalAlignment="Top">
+                <Ellipse.Style>
+                    <Style TargetType="Ellipse">
+                        <!-- 默认颜色(SignalOn为false时) -->
+                        <Setter Property="Fill" Value="LightGray"/>
+                        <Style.Triggers>
+                            <!-- 当SignalOn为true时变为绿色 -->
+                            <DataTrigger Binding="{Binding SignalOn}" Value="True">
+                                <Setter Property="Fill" Value="LimeGreen"/>
+                            </DataTrigger>
+                            <DataTrigger Binding="{Binding SignalOn}" Value="False">
+                                <Setter Property="Fill" Value="LightGray"/>
+                            </DataTrigger>
+                        </Style.Triggers>
+                    </Style>
+                </Ellipse.Style>
+            </Ellipse>
+        </Grid>
     </Border>
 </UserControl>

+ 27 - 21
UserControls/FestoControl.xaml.cs

@@ -1,6 +1,9 @@
-using FestoDebugger.Service;
+using FestoDebugger.Beckoff;
+using FestoDebugger.Models;
+using FestoDebugger.Service;
 using System;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -44,58 +47,61 @@ namespace FestoDebugger.UserControls
             }
         }
 
-        public static readonly DependencyProperty SignalAOnProperty = DependencyProperty.Register(
-            "SignalAOn", typeof(bool), typeof(FestoControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
+        public static readonly DependencyProperty SignalOnProperty = DependencyProperty.Register(
+            "SignalOn", typeof(bool), typeof(FestoControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
         /// <summary>
         /// WaferPresent
         /// </summary>
-        public bool SignalAOn
+        public bool SignalOn
         {
             get
             {
-                return (bool)this.GetValue(SignalAOnProperty);
+                return (bool)this.GetValue(SignalOnProperty);
             }
             set
             {
-                this.SetValue(SignalAOnProperty, value);
+                this.SetValue(SignalOnProperty, value);
             }
         }
 
-        public static readonly DependencyProperty SignalBOnProperty = DependencyProperty.Register(
-            "SignalBOn", typeof(bool), typeof(FestoControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
+
+        public static readonly DependencyProperty ModuleDataProperty = DependencyProperty.Register(
+            "ModuleData", typeof(SignalModuleData), typeof(FestoControl), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnItemsSourceChanged)));
         /// <summary>
         /// WaferPresent
         /// </summary>
-        public bool SignalBOn
+        public SignalModuleData ModuleData
         {
             get
             {
-                return (bool)this.GetValue(SignalBOnProperty);
+                return (SignalModuleData)this.GetValue(ModuleDataProperty);
             }
             set
             {
-                this.SetValue(SignalBOnProperty, value);
+                this.SetValue(ModuleDataProperty, value);
             }
         }
 
-        private void AOn_Click(object sender, RoutedEventArgs e)
-        {
-            SignalOperationManager.Instance.opearte(ModuleName, "A", true);
-        }
 
-        private void AOff_Click(object sender, RoutedEventArgs e)
+        private void On_Click(object sender, RoutedEventArgs e)
         {
-            SignalOperationManager.Instance.opearte(ModuleName, "A", false);
+            object[] paramater = new object[] { $"{ModuleData.ModuleName}",true };
+            BeckhoffIOManager.Instance.WriteDoOperation(" ", paramater);
         }
 
-        private void BOn_Click(object sender, RoutedEventArgs e)
+        private void Off_Click(object sender, RoutedEventArgs e)
         {
-
+            object[] paramater = new object[] { $"{ModuleData.ModuleName}", false };
+            BeckhoffIOManager.Instance.WriteDoOperation(" ", paramater);
         }
 
-        private void BOff_Click(object sender, RoutedEventArgs e)
+        private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
         {
-
+            if (e.NewValue != null)
+            {
+                SignalModuleData newValue = (SignalModuleData)e.NewValue;
+                d.SetValue(SignalOnProperty, newValue.SignalOn);
+            }
         }
     }
 }

+ 49 - 9
ViewModels/MainViewModel.cs

@@ -10,8 +10,10 @@ using System.Net;
 using System.Net.Sockets;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows;
 using System.Windows.Input;
 using System.Windows.Media;
+using System.Windows.Threading;
 
 namespace FestoDebugger.ViewModels
 {
@@ -19,9 +21,15 @@ namespace FestoDebugger.ViewModels
     {
         #region 内部变量
 
+        private static bool IsInDesignMode => DesignerProperties.GetIsInDesignMode(new DependencyObject());
 
         private ObservableCollection<SignalModuleData> _signalModuleDatas;
 
+        /// <summary>
+        /// 定时器
+        /// </summary>
+        DispatcherTimer _timer;
+
         #endregion
 
         #region 属性
@@ -37,28 +45,60 @@ namespace FestoDebugger.ViewModels
 
         public MainViewModel()
         {
+            if (IsInDesignMode)
+            {
+                return;
+            }
+            
             LoadSignalConfig();
-
+            
             SignalModuleDatas = new ObservableCollection<SignalModuleData>();
-            for (int i = 1; i < 11; i++)
+
+            if (_timer == null)
             {
-                SignalModuleData data = new SignalModuleData();
-                data.ModuleName = $"V{i}";
-                data.SignalAOn = true;
-                data.SignalBOn = false;
-                SignalModuleDatas.Add(data);
+                _timer = new DispatcherTimer();
+                _timer.Interval = TimeSpan.FromMilliseconds(100);
+                _timer.Tick += Timer_Tick;
             }
-
-            //LoadSignalConfig();
+            _timer.Start();
+          
         }
+
+      
+
         /// <summary>
         /// 加载配置文件,初始化数据
         /// </summary>
         private void LoadSignalConfig()
         {
             BeckhoffManager.Instance.Initialize();
+            TwincatAdoManager.Instance.Initialize();
         }
 
+        /// <summary>
+        /// 定时器执行
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void Timer_Tick(object sender, EventArgs e)
+        {
+            Dictionary<string, object> NameValueDic = BeckhoffIOManager.Instance.GetNameValueDic();
+            foreach (KeyValuePair<string, object> kvp in NameValueDic)
+            {
+                bool exists = SignalModuleDatas.Any(p => p.ModuleName == kvp.Key);
+                if(!exists)
+                {
+                    SignalModuleData signalModuleData = new SignalModuleData();
+                    signalModuleData.ModuleName = kvp.Key;
+                    signalModuleData.SignalOn = (bool)kvp.Value;
+                    SignalModuleDatas.Add(signalModuleData);
+                }
+                else
+                {
+                    SignalModuleDatas.FirstOrDefault(p => p.ModuleName == kvp.Key).SignalOn = (bool)kvp.Value;
+                }
+            }
+        }
     }
 }
 

+ 2 - 2
Views/MainWindow.xaml

@@ -10,7 +10,7 @@
         mc:Ignorable="d"
         Title="FestoDebuger" Height="450" Width="800">
     <Window.DataContext>
-        <local1:MainViewModel />
+        <local1:MainViewModel/>
     </Window.DataContext>
     <Canvas>
         <ScrollViewer Height="450" Width="800">
@@ -22,7 +22,7 @@
             </ItemsControl.ItemsPanel>
             <ItemsControl.ItemTemplate>
                 <DataTemplate>
-                    <UserControls:FestoControl />
+                        <UserControls:FestoControl ModuleData="{Binding}"/>
                 </DataTemplate>
             </ItemsControl.ItemTemplate>
         </ItemsControl>