终端一体化运控平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

GlobalVarMonitorViewModel.cs 2.4 KiB

vor 1 Jahr
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. }