123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Windows;
- using System.Windows.Controls;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.IOCore;
- using Aitex.Core.UI.MVVM;
- using MECF.Framework.Common.IOCore;
- namespace EFEM.RT.Backends
- {
- /// <summary>
- /// IOView.xaml 的交互逻辑
- /// </summary>
- public partial class IOView : UserControl
- {
- public IOView()
- {
- InitializeComponent();
- this.Loaded += IOView_Loaded;
- this.IsVisibleChanged += IOView_IsVisibleChanged;
- }
- private void IOView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
- if (this.DataContext == null)
- {
- DataContext = new IOMonitorViewModel();
- }
- (DataContext as TimerViewModelBase).EnableTimer(IsVisible);
- }
- private void IOView_Loaded(object sender, RoutedEventArgs e)
- {
- if (this.DataContext == null)
- {
- DataContext = new IOMonitorViewModel();
- }
- }
- }
-
- public class IOMonitorViewModel : TimerViewModelBase
- {
- public static readonly int IoCardQuantity = int.Parse(DATA.Poll("DeviceDefine.IoCardQuantity").ToString());
- public static readonly bool MotionAxisInstalled = bool.Parse(DATA.Poll("DeviceDefine.MotionAxisInstalled").ToString());
- private static readonly string[] Source = new []
- {
- "System.dio000",
- "System.dio001",
- "System.dio002",
- "System.dio003",
- "System.dio004",
- "System.dio005",
- "System.dio006",
- };
- public const string MotionAxis = "System.MotionAxis";
- public ObservableCollection<NotifiableIoItem> DiItemList { get; set; }
- public ObservableCollection<NotifiableIoItem> DoItemList { get; set; }
- public ObservableCollection<NotifiableIoItem> AiItemList { get; set; }
- public ObservableCollection<NotifiableIoItem> AoItemList { get; set; }
- //public ICommand SetScCommand { get; set; }
- public IOMonitorViewModel():base(nameof(IOMonitorViewModel))
- {
- Init();
- //SetScCommand = new DelegateCommand<string>(SetSc);
- }
-
- void Init()
- {
- if (DiItemList != null)
- return;
- {
- DiItemList = new ObservableCollection<NotifiableIoItem>();
- for (int i = 0; i < IoCardQuantity; i++)
- {
- List<DIAccessor> diItems = IO.GetDiList(Source[i]);
- if (diItems==null)
- continue;
- foreach (var diItem in diItems)
- {
- NotifiableIoItem item = new NotifiableIoItem()
- {
- Name = diItem.Name,
- Index = diItem.Index,
- Description = diItem.Description,
- BoolValue = diItem.Value,
- Address = diItem.Addr,
- };
- DiItemList.Add(item);
- }
- }
- InvokePropertyChanged(nameof(DiItemList));
- }
-
- if (DoItemList != null)
- return;
- {
- DoItemList = new ObservableCollection<NotifiableIoItem>();
- for (int i = 0; i < IoCardQuantity; i++)
- {
- List<DOAccessor> doItems = IO.GetDoList(Source[i]);
- if (doItems==null)
- continue;
- foreach (var doItem in doItems)
- {
- NotifiableIoItem item = new NotifiableIoItem()
- {
- Name = doItem.Name,
- Index = doItem.Index,
- Description = doItem.Description,
- BoolValue = doItem.Value,
- Address = doItem.Addr,
- };
- DoItemList.Add(item);
- }
- }
- InvokePropertyChanged(nameof(DoItemList));
- }
-
- if (MotionAxisInstalled)
- {
- if (AiItemList != null)
- return;
- {
- AiItemList = new ObservableCollection<NotifiableIoItem>();
- List<AIAccessor> aiItems = IO.GetAiList(MotionAxis);
- if (aiItems!=null)
- foreach (var aiItem in aiItems)
- {
- NotifiableIoItem item = new NotifiableIoItem()
- {
- Name = aiItem.Name,
- Index = aiItem.Index,
- Description = aiItem.Description,
- ShortValue = aiItem.Value,
- Address = aiItem.Addr,
- };
- AiItemList.Add(item);
- }
- InvokePropertyChanged(nameof(AiItemList));
- }
-
- if (AoItemList != null)
- return;
- {
- AoItemList = new ObservableCollection<NotifiableIoItem>();
- List<AOAccessor> aoItems = IO.GetAoList(MotionAxis);
- if (aoItems!=null)
- foreach (var aoItem in aoItems)
- {
- NotifiableIoItem item = new NotifiableIoItem()
- {
- Name = aoItem.Name,
- Index = aoItem.Index,
- Description = aoItem.Description,
- ShortValue = aoItem.Value,
- Address = aoItem.Addr,
- };
- AoItemList.Add(item);
- }
- InvokePropertyChanged(nameof(AoItemList));
- }
- }
-
- }
- protected override void Poll()
- {
- string[] values = new string[128];
- int i = 0;
- foreach (var notifiableIoItem in DiItemList)
- {
- notifiableIoItem.BoolValue = IO.DI[notifiableIoItem.Name].Value;
- notifiableIoItem.InvokePropertyChanged(nameof(notifiableIoItem.BoolValue));
- values[i++] = notifiableIoItem.BoolValue ? "1" : "0";
- }
-
- foreach (var notifiableIoItem in DoItemList)
- {
- notifiableIoItem.BoolValue = IO.DO[notifiableIoItem.Name].Value;
- notifiableIoItem.InvokePropertyChanged(nameof(notifiableIoItem.BoolValue));
- values[i++] = notifiableIoItem.BoolValue ? "1" : "0";
- }
-
- //System.Diagnostics.Trace.WriteLine(string.Join(",", values));
- }
- }
- }
|