123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- using Aitex.Core.RT.IOCore;
- using Aitex.Core.UI.MVVM;
- using Aitex.Core.Util;
- using athosSimulator.IO;
- using athosSimulator.LoadPort;
- using athosSimulator.Robot;
- using MECF.Framework.Common.IOCore;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Data.SqlClient;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using IOs = Aitex.Core.RT.IOCore.IO;
- namespace athosSimulator
- {
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MainWindow : Window
- {
- private string[] _lp1slotMap = new string[25];
- private string[] _lp2slotMap = new string[25];
- public static readonly DependencyProperty LP1SlotMapProperty = DependencyProperty.Register("LP1SlotMap", typeof(string), typeof(MainWindow));
- public string LP1SlotMap
- {
- get { return (string)this.GetValue(LP1SlotMapProperty); }
- set { this.SetValue(LP1SlotMapProperty, value); }
- }
- public static readonly DependencyProperty LP2SlotMapProperty = DependencyProperty.Register("LP2SlotMap", typeof(string), typeof(MainWindow));
- public string LP2SlotMap
- {
- get { return (string)this.GetValue(LP2SlotMapProperty); }
- set { this.SetValue(LP2SlotMapProperty, value); }
- }
- public SimulatorPlc Plc { get; set; }
- public ICommand SetCommand { get; private 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;
- private RorzeRobot751Simulator _robotSimulator;
- private Hirata _lp1Simulator;
- private Hirata _lp2Simulator;
- private Hirata _lp3Simulator;
- public MainWindow()
- {
- InitializeComponent();
- IOShow();
- DISource.ItemsSource = DIs;
- DOSource.ItemsSource = DOs;
- AISource.ItemsSource = AIs;
- AOSource.ItemsSource = AOs;
- _task = new PeriodicJob(500, IOShow, "Simulator",true);
- _robotSimulator = SystemSimulator.Instance.RobotSimulator;
- _lp1Simulator = SystemSimulator.Instance.LP1Simulator;
- _lp2Simulator = SystemSimulator.Instance.LP2Simulator;
- //_lp3Simulator = SystemSimulator.Instance.LP3Simulator;
- //SetCommand = new DelegateCommand<object>(OnSetValue);
- }
- //设置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_DOChecked(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_DOUnChecked(object sender, RoutedEventArgs e)
- {
- IOs.DO[GetDOName(e)].Value = false;
- DOAccessor do1 = IoManager.Instance.GetIO<DOAccessor>(GetDOName(e));
- string reason = "";
- bool flag = do1.SetValue(false, out reason);
- }
- private void CheckBox_DIChecked(object sender, RoutedEventArgs e)
- {
- IOs.DI[GetDIName(e)].Value = true;
- //DIAccessor do1 = IoManager.Instance.GetIO<DIAccessor>(GetDIName(e));
- //string reason = "";
- //bool flag = do1.SetValue(true, out reason);
- }
- private void CheckBox_DIUnChecked(object sender, RoutedEventArgs e)
- {
- IOs.DI[GetDIName(e)].Value = false;
- //DIAccessor do1 = IoManager.Instance.GetIO<DIAccessor>(GetDIName(e));
- //string reason = "";
- //bool flag = do1.SetValue(true, out reason);
- }
- private string GetDOName(RoutedEventArgs e) => ((NotifiableIoItem)((CheckBox)e.OriginalSource).DataContext).Name;
- private string GetDIName(RoutedEventArgs e) => ((NotifiableIoItem)((CheckBox)e.OriginalSource).DataContext).Name;
- /// <summary>
- /// LP1 Wafer Operation
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void LP1SetAll(object sender, RoutedEventArgs e)
- {
- for (int i = 0; i < _lp1slotMap.Length; i++)
- {
- _lp1slotMap[i] = "1";
- }
- LP1SlotMap = string.Join("", _lp1slotMap);
- _lp1Simulator.MapStr = LP1SlotMap;
- }
- private void LP1SetRandom(object sender, RoutedEventArgs e)
- {
- Random _rd = new Random();
- for (int i = 0; i < _lp1slotMap.Length; i++)
- {
- //_slotMap[i] = (i % 9).ToString();
- _lp1slotMap[i] = _rd.Next(0, 10) < 6 ? "0" : "1";
- }
- LP1SlotMap = string.Join("", _lp1slotMap);
- _lp1Simulator.MapStr = LP1SlotMap;
- }
- private void LP1ClearAll(object sender, RoutedEventArgs e)
- {
- for (int i = 0; i < _lp1slotMap.Length; i++)
- {
- _lp1slotMap[i] = "0";
- }
- LP1SlotMap = string.Join("", _lp1slotMap);
- _lp1Simulator.MapStr = LP1SlotMap;
- }
- /// <summary>
- /// LP2 Wafer Operation
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void LP2SetAll(object sender, RoutedEventArgs e)
- {
- for (int i = 0; i < _lp2slotMap.Length; i++)
- {
- _lp2slotMap[i] = "1";
- }
- LP2SlotMap = string.Join("", _lp2slotMap);
- _lp2Simulator.MapStr = LP2SlotMap;
- }
- private void LP2SetRandom(object sender, RoutedEventArgs e)
- {
- Random _rd = new Random();
- for (int i = 0; i < _lp2slotMap.Length; i++)
- {
- //_slotMap[i] = (i % 9).ToString();
- _lp2slotMap[i] = _rd.Next(0, 10) < 6 ? "0" : "1";
- }
- LP2SlotMap = string.Join("", _lp2slotMap);
- _lp2Simulator.MapStr = LP2SlotMap;
- }
- private void LP2ClearAll(object sender, RoutedEventArgs e)
- {
- for (int i = 0; i < _lp2slotMap.Length; i++)
- {
- _lp2slotMap[i] = "0";
- }
- LP2SlotMap = string.Join("", _lp2slotMap);
- _lp2Simulator.MapStr = LP2SlotMap;
- }
- }
- }
|