123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- using Aitex.Common.Util;
- using Aitex.Core.RT.IOCore;
- using Aitex.Core.Util;
- using athosSimulator.IO;
- using athosSimulator.LoadPort;
- using athosSimulator.PreAligner;
- using MECF.Framework.Common.IOCore;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Timers;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using IOs = Aitex.Core.RT.IOCore.IO;
- namespace athosSimulator
- {
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MainWindow : Window
- {
- public SimulatorPlc Plc { get; set; }
- public ObservableCollection<NotifiableIoItem> DIs { get; set; }
- public ObservableCollection<NotifiableIoItem> DOs { get; set; }
- public ObservableCollection<NotifiableIoItem> AIs { get; set; }
- public ObservableCollection<NotifiableIoItem> AOs { get; set; }
- private PeriodicJob _task;
- public MainWindow()
- {
- InitializeComponent();
- IOShow();
- DISource.ItemsSource = DIs;
- DOSource.ItemsSource = DOs;
- AISource.ItemsSource = AIs;
- AOSource.ItemsSource = AOs;
- _task = new PeriodicJob(500, IOShow, "Simulator",true);
- }
-
- //设置IO值 以及刷新
- private bool IOShow()
- {
- List<DIAccessor> diItems = IOs.GetDiList("Simulator->IO");
- if (diItems != null)
- {
- DIs = new ObservableCollection<NotifiableIoItem>();
- foreach (var diItem in diItems)
- {
- NotifiableIoItem item = new NotifiableIoItem()
- {
- Name = diItem.Name,
- Index = diItem.Index,
- Description = diItem.Description,
- BoolValue = diItem.Value,
- Address = diItem.Addr,
- BlockOffset = diItem.BlockOffset,
- BlockIndex = diItem.Index,
- };
- DIs.Add(item);
- }
- };
- List<DOAccessor> doItems = IOs.GetDoList("Simulator->IO");
- if (doItems != null)
- {
- DOs = new ObservableCollection<NotifiableIoItem>();
- foreach (var doItem in doItems)
- {
- NotifiableIoItem item = new NotifiableIoItem()
- {
- Name = doItem.Name,
- Index = doItem.Index,
- Description = doItem.Description,
- BoolValue = doItem.Value,
- Address = doItem.Addr,
- BlockOffset = doItem.BlockOffset,
- BlockIndex = doItem.Index,
- };
- DOs.Add(item);
- }
- };
- if (AIs == null)
- {
- List<AIAccessor> aiItems = IOs.GetAiList("Simulator->IO");
- if (aiItems != null)
- {
- AIs = new ObservableCollection<NotifiableIoItem>();
- foreach (var ioItem in aiItems)
- {
- NotifiableIoItem item = new NotifiableIoItem()
- {
- Name = ioItem.Name,
- Index = ioItem.Index,
- Description = ioItem.Description,
- ShortValue = ioItem.Value,
- Address = ioItem.Addr,
- BlockOffset = ioItem.BlockOffset,
- BlockIndex = ioItem.Index,
- };
- AIs.Add(item);
- }
- }
- }
- if (AOs == null)
- {
- List<AOAccessor> aoItems = IOs.GetAoList("Simulator->IO");
- if (aoItems != null)
- {
- AOs = new ObservableCollection<NotifiableIoItem>();
- foreach (var ioItem in aoItems)
- {
- NotifiableIoItem item = new NotifiableIoItem()
- {
- Name = ioItem.Name,
- Index = ioItem.Index,
- Description = ioItem.Description,
- ShortValue = ioItem.Value,
- Address = ioItem.Addr,
- BlockOffset = ioItem.BlockOffset,
- BlockIndex = ioItem.Index,
- };
- AOs.Add(item);
- }
- }
- }
- return true;
- }
- private void CheckBox_Checked(object sender, RoutedEventArgs e)
- {
- IOs.DO[GetDOName(e)].Value = true;
- //DOAccessor do1 = IoManager.Instance.GetIO<DOAccessor>(GetDOName(e));
- //string reason = "";
- //bool flag = do1.SetValue(true,out reason);
- }
- private void CheckBox_UnChecked(object sender, RoutedEventArgs e)
- {
- IOs.DO[GetDOName(e)].Value = false;
- //DOAccessor do1 = IoManager.Instance.GetIO<DOAccessor>(GetDOName(e));
- //string reason = "";
- //bool flag = do1.SetValue(true,out reason);
- }
- private string GetDOName(RoutedEventArgs e) => ((NotifiableIoItem)((CheckBox)e.OriginalSource).DataContext).Name;
- }
- }
|