终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

77 line
2.4 KiB

  1. using BPA.Helper;
  2. using BPASmartClient.JXJFoodBigStation.Model;
  3. using BPASmartClient.JXJFoodBigStation.Model.HK_PLC;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.ComponentModel;
  8. using System.Linq;
  9. using System.Reflection;
  10. using System.Text;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. namespace BPASmartClient.JXJFoodBigStation.ViewModel
  14. {
  15. public class GlobalVarMonitorViewModel : NotifyBase
  16. {
  17. public static ObservableCollection<PlcVarMonitor> PlcInfo { get; set; } = new ObservableCollection<PlcVarMonitor>();
  18. public GlobalVarMonitorViewModel() {
  19. Type type = typeof(GVL_BigStation);
  20. PropertyInfo[] properties = type.GetProperties();
  21. if (PlcInfo.Count == 0)
  22. {
  23. foreach (PropertyInfo mi in properties)
  24. {
  25. PropertyInfo a = type.GetProperty(mi.Name);
  26. object ab = a.GetValue(null);
  27. var num = GVL_BigStation.HKPlc_Read;
  28. var res = a.GetCustomAttribute<PlcCommAttribute>();
  29. string describe = "";
  30. if (res != null)
  31. {
  32. describe = res.Describe;
  33. PlcInfo.Add(new PlcVarMonitor()
  34. {
  35. SerialNum = PlcInfo.Count + 1,
  36. Variable = mi.Name,
  37. Type = mi.PropertyType.Name,
  38. Describe = describe,
  39. NowValue = ab.ToString(),
  40. });
  41. }
  42. else
  43. {
  44. describe = "";
  45. }
  46. }
  47. }
  48. TaskManage.GetInstance.StartLong(new Action(() =>
  49. {
  50. foreach (PropertyInfo mi in properties)
  51. {
  52. PropertyInfo a = type.GetProperty(mi.Name);
  53. object ab = a.GetValue(null);
  54. int index = Array.FindIndex(PlcInfo.ToArray(), p => p.Variable == mi.Name);
  55. if (index != -1)
  56. {
  57. PlcInfo.ElementAt(index).NowValue = ab.ToString();
  58. }
  59. }
  60. Thread.Sleep(100);
  61. }), "Global变量读取", true);
  62. }
  63. }
  64. }