终端一体化运控平台
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

77 linhas
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. {
  20. Type type = typeof(GVL_BigStation);
  21. PropertyInfo[] properties = type.GetProperties();
  22. if (PlcInfo.Count == 0)
  23. {
  24. foreach (PropertyInfo mi in properties)
  25. {
  26. PropertyInfo a = type.GetProperty(mi.Name);
  27. object ab = a.GetValue(null);
  28. var num = GVL_BigStation.HKPlc_Read;
  29. var res = a.GetCustomAttribute<PlcCommAttribute>();
  30. string describe = "";
  31. if (res != null)
  32. {
  33. describe = res.Describe;
  34. PlcInfo.Add(new PlcVarMonitor()
  35. {
  36. SerialNum = PlcInfo.Count + 1,
  37. Variable = mi.Name,
  38. Type = mi.PropertyType.Name,
  39. Describe = describe,
  40. NowValue = ab.ToString(),
  41. });
  42. }
  43. else
  44. {
  45. describe = "";
  46. }
  47. }
  48. }
  49. ThreadManage.GetInstance().StartLong(new Action(() =>
  50. {
  51. foreach (PropertyInfo mi in properties)
  52. {
  53. PropertyInfo a = type.GetProperty(mi.Name);
  54. object ab = a.GetValue(null);
  55. int index = Array.FindIndex(PlcInfo.ToArray(), p => p.Variable == mi.Name);
  56. if (index != -1)
  57. {
  58. PlcInfo.ElementAt(index).NowValue = ab.ToString();
  59. }
  60. }
  61. Thread.Sleep(100);
  62. }), "Global变量读取", true);
  63. }
  64. }
  65. }