123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- using System;
- using System.Collections.ObjectModel;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using Aitex.Core.UI.MVVM;
- using MECF.Framework.Simulator.Core.Commons;
- using MECF.Framework.Simulator.Core.Driver;
- using EfemDualSimulator.Devices;
- using EfemDualSimulator.Instances;
- namespace EfemDualSimulator.Views
- {
- /// <summary>
- /// Simu_CometRFView.xaml 的交互逻辑
- /// </summary>
- public partial class Simu_CometRFView : UserControl
- {
- public Simu_CometRFView(string port)
- {
- InitializeComponent();
- this.DataContext = new CometRFSimulatorViewModel("CometRFViewModel", port);
- this.Loaded += OnViewLoaded;
- }
- private void OnViewLoaded(object sender, RoutedEventArgs e)
- {
- (DataContext as TimerViewModelBase)?.Start();
- }
- }
- class CometRFSimulatorViewModel : TimerViewModelBase
- {
- //int port = 502;
- public ICommand ClearLogCommand { get; set; }
- public ICommand EnableCommand { get; set; }
- public ICommand DisableCommand { get; set; }
- public string Title
- {
- get { return "CometRF Simulator"; }
- }
- public ObservableCollection<TransactionLogItem> TransactionLogItems { get; set; }
- private CometRFSocketServer _cometRFServer;
- public CometRFSimulatorViewModel(string name,string port) : base(name)
- {
- _cometRFServer = new CometRFSocketServer(int.Parse(port));
- ClearLogCommand = new DelegateCommand<string>(ClearLog);
- EnableCommand = new DelegateCommand<string>(Enable);
- DisableCommand = new DelegateCommand<string>(Disable);
- TransactionLogItems = new ObservableCollection<TransactionLogItem>();
- _cometRFServer.MessageOut += _simulator_MessageOut;
- _cometRFServer.MessageIn += _simulator_MessageIn;
- }
- private void Disable(string obj)
- {
-
- }
- private void Enable(string obj)
- {
-
- }
- private void ClearLog(string obj)
- {
- TransactionLogItems.Clear();
- }
- private void _simulator_MessageIn(string obj)
- {
- Application.Current.Dispatcher.Invoke(new Action(() =>
- {
- TransactionLogItems.Add(new TransactionLogItem() { Incoming = obj, OccurTime = DateTime.Now.ToString("HH:mm:ss.fff") });
- }));
- }
- private void _simulator_MessageOut(string obj)
- {
- Application.Current.Dispatcher.Invoke(new Action(() =>
- {
- TransactionLogItems.Add(new TransactionLogItem() { Outgoing = obj, OccurTime = DateTime.Now.ToString("HH:mm:ss.fff") });
- }));
- }
- protected override void Poll()
- {
- Application.Current.Dispatcher.Invoke(new Action(() =>
- {
- InvokeAllPropertyChanged();
- }));
- }
- }
- }
|