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 { /// /// MainWindow.xaml 的交互逻辑 /// public partial class MainWindow : Window { public SimulatorPlc Plc { get; set; } public ObservableCollection DIs { get; set; } public ObservableCollection DOs { get; set; } public ObservableCollection AIs { get; set; } public ObservableCollection 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 diItems = IOs.GetDiList("Simulator->IO"); if (diItems != null) { DIs = new ObservableCollection(); 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 doItems = IOs.GetDoList("Simulator->IO"); if (doItems != null) { DOs = new ObservableCollection(); 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 aiItems = IOs.GetAiList("Simulator->IO"); if (aiItems != null) { AIs = new ObservableCollection(); 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 aoItems = IOs.GetAoList("Simulator->IO"); if (aoItems != null) { AOs = new ObservableCollection(); 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(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(GetDOName(e)); //string reason = ""; //bool flag = do1.SetValue(true,out reason); } private string GetDOName(RoutedEventArgs e) => ((NotifiableIoItem)((CheckBox)e.OriginalSource).DataContext).Name; } }