123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using Aitex.Common.Util;
- using Aitex.Core.UI.MVVM;
- using Aitex.Core.Util;
- using Aitex.Core.Utilities;
- using CyberX8_Simulator.Devices;
- using MECF.Framework.Common.Device.Festo;
- using MECF.Framework.Simulator.Core.Commons;
- using System.Collections.ObjectModel;
- using System.IO;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- namespace CyberX8_Simulator.Views
- {
- /// <summary>
- /// FestoView.xaml 的交互逻辑
- /// </summary>
- public partial class FestoView : UserControl
- {
- public FestoView()
- {
- InitializeComponent();
- this.Loaded += OnViewLoaded;
- }
- private void OnViewLoaded(object sender, RoutedEventArgs e)
- {
- (DataContext as TimerViewModelBase)?.Start();
- }
- }
- class FestoViewModel : SocketDeviceViewModel
- {
- #region 属性
- public string Title
- {
- get { return "Festo Simulator"; }
- }
- private string _DOSelectedItem;
- [IgnorePropertyChange]
- public string DOSelectedItem
- {
- get
- {
- return _DOSelectedItem;
- }
- set
- {
- _DOSelectedItem = value;
- }
- }
- private int _DOInputValue;
- [IgnorePropertyChange]
- public int DOInputValue
- {
- get
- {
- return _DOInputValue;
- }
- set
- {
- _DOInputValue = value;
- }
- }
- public ObservableCollection<string> DONameItems { get; set; }
- public ObservableCollection<int> DigitalOutputSelected { get; set; }
- #endregion
- public ICommand SetDOCommand { get; set; }
- private FestoSocketSimulator _sim;
- public FestoViewModel(string str) : base("FestoViewModel")
- {
- int.TryParse(str, out int port);
- _sim = new FestoSocketSimulator(port);
- Init(_sim);
- InitData(port);
- SetDOCommand = new DelegateCommand<object>(SetDOAction);
- }
- private void InitData(int port)
- {
- DigitalOutputSelected = new ObservableCollection<int> { 0, 1 };
- string oldXmlPath = PathManager.GetCfgDir();
- string newXmlPath = oldXmlPath.Replace("CyberX8_Simulator", "CyberX8_RT") + "Devices\\FestoControllerCfg-Simulator.xml";
- FestoControllerCfg cfg = CustomXmlSerializer.Deserialize<FestoControllerCfg>(new FileInfo(newXmlPath));
- DONameItems = new ObservableCollection<string>();
- foreach (FestoDeviceConfig config in cfg.FestoDeviceConfigs)
- {
- if (port == config.Port)
- {
- foreach (FestoDO item in config.FestoDoes)
- {
- DONameItems.Add(item.Name);
- }
- }
- }
-
-
- }
- private void SetDOAction(object obj)
- {
- _sim.UpdataDOBytes(DOSelectedItem, DOInputValue);
- }
- }
- }
|