PlcViewModelBase.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System.Collections.ObjectModel;
  2. using Aitex.Core.UI.MVVM;
  3. using FurnaceSimulator.Instances;
  4. using MECF.Framework.Common.IOCore;
  5. using System.Windows.Controls.Primitives;
  6. using System.Windows;
  7. using System.Windows.Data;
  8. using System;
  9. namespace FurnaceSimulator.Views
  10. {
  11. public class IoButton : ToggleButton
  12. {
  13. public static readonly DependencyProperty ONProperty;
  14. static IoButton()
  15. {
  16. ONProperty = DependencyProperty.Register("ON", typeof(bool), typeof(IoButton));
  17. }
  18. public bool ON
  19. {
  20. get { return (bool)GetValue(ONProperty); }
  21. set { SetValue(ONProperty, value); }
  22. }
  23. }
  24. public class BoolBackgroundConverter : IValueConverter
  25. {
  26. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  27. {
  28. bool? ret = (bool?)value;
  29. return ret.HasValue && ret.Value ? "LightBlue" : "Transparent";
  30. }
  31. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  32. {
  33. return null;
  34. }
  35. }
  36. public class IoViewModel : TimerViewModelBase
  37. {
  38. public SimulatorPlc Plc { get; set; }
  39. public ObservableCollection<NotifiableIoItem> DIs { get; set; }
  40. public ObservableCollection<NotifiableIoItem> DOs { get; set; }
  41. public ObservableCollection<NotifiableIoItem> AIs { get; set; }
  42. public ObservableCollection<NotifiableIoItem> AOs { get; set; }
  43. public IoViewModel(int port, string source, string ioMapPathFile, string module) : base(nameof(IoViewModel))
  44. {
  45. Plc = new SimulatorPlc(port, source, ioMapPathFile, module);
  46. DIs = Plc.DiItemList;
  47. DOs = Plc.DoItemList;
  48. AIs = Plc.AiItemList;
  49. AOs = Plc.AoItemList;
  50. }
  51. protected override void Poll()
  52. {
  53. }
  54. }
  55. }