123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Reflection;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using Aitex.Core.RT.IOCore;
- using Aitex.Core.UI.MVVM;
- using MECF.Framework.Common.IOCore;
- namespace VirgoRT.Backends
- {
- /// <summary>
- /// IOView.xaml 的交互逻辑
- /// </summary>
- public partial class IOView : UserControl
- {
- public IOView()
- {
- InitializeComponent();
- DataContext = new IOMonitorViewModel();
-
- this.IsVisibleChanged += IOView_IsVisibleChanged;
- }
- private void IOView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
-
- (DataContext as TimerViewModelBase).EnableTimer(IsVisible);
- }
-
- }
- public class IoValues
- {
- public ObservableCollection<NotifiableIoItem> DiItemList { get; set; }
- public ObservableCollection<NotifiableIoItem> DoItemList { get; set; }
- public ObservableCollection<NotifiableIoItem> AiItemList { get; set; }
- public ObservableCollection<NotifiableIoItem> AoItemList { get; set; }
- #region InitDefine
- public IoValues(string source)
- {
- DiItemList = new ObservableCollection<NotifiableIoItem>();
- List<DIAccessor> diItems = IO.GetDiList(source);
- if (diItems != null)
- {
- 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);
- }
- }
- DoItemList = new ObservableCollection<NotifiableIoItem>();
- List<DOAccessor> doItems = IO.GetDoList(source);
- if (doItems != null)
- {
- 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);
- }
- }
- AiItemList = new ObservableCollection<NotifiableIoItem>();
- List<AIAccessor> aiItems = IO.GetAiList(source);
- 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);
- }
- }
- AoItemList = new ObservableCollection<NotifiableIoItem>();
- List<AOAccessor> aoItems = IO.GetAoList(source);
- 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);
- }
- }
- }
- #endregion
- public void UpdateData()
- {
- foreach (var item in DiItemList)
- {
- item.BoolValue = IO.DI[item.Name].Value;
- item.InvokePropertyChanged("BoolValue");
- }
- foreach (var item in DoItemList)
- {
- item.BoolValue = IO.DO[item.Name].Value;
- }
- foreach (var item in AiItemList)
- {
- item.ShortValue = IO.AI[item.Name].Value;
- }
- foreach (var item in AoItemList)
- {
- item.ShortValue = IO.AO[item.Name].Value;
- }
- }
- }
- public class IOMonitorViewModel : TimerViewModelBase
- {
- public IoValues[] IoList { get; set; }
-
-
- public IOMonitorViewModel():base(nameof(IOMonitorViewModel))
- {
- IoList = new IoValues[2];
- for (int i = 0; i < IoList.Length; i++)
- {
- IoList[i] = new IoValues("System.io"+(i+1));
- }
-
- }
- protected override void Poll()
- {
- for (int i = 0; i < IoList.Length; i++)
- {
- IoList[i].UpdateData();
- }
- //string[] values = new string[128];
- //int i = 0;
- //foreach (var notifiableIoItem in Card1.DiItemList)
- //{
- // notifiableIoItem.BoolValue = IO.DI[notifiableIoItem.Name].Value;
- // notifiableIoItem.InvokePropertyChanged(nameof(notifiableIoItem.BoolValue));
- // values[i++] = notifiableIoItem.BoolValue ? "1" : "0";
- //}
- //System.Diagnostics.Trace.WriteLine(string.Join(",", values));
- }
- }
- }
|