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 { /// /// MainWindow.xaml 的交互逻辑 /// 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 DIs { get; set; } public ObservableCollection DOs { get; set; } public ObservableCollection AIs { get; set; } public ObservableCollection 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(OnSetValue); } //设置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_DOChecked(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_DOUnChecked(object sender, RoutedEventArgs e) { IOs.DO[GetDOName(e)].Value = false; DOAccessor do1 = IoManager.Instance.GetIO(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(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(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; /// /// LP1 Wafer Operation /// /// /// 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; } /// /// LP2 Wafer Operation /// /// /// 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; } } }