|
- using BPA.Helper;
- using BPASmartClient.JXJFoodBigStation.Model;
- using BPASmartClient.JXJFoodBigStation.Model.HK_PLC;
-
-
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
-
- namespace BPASmartClient.JXJFoodBigStation.ViewModel
- {
- public class GlobalVarMonitorViewModel : NotifyBase
- {
-
- public static ObservableCollection<PlcVarMonitor> PlcInfo { get; set; } = new ObservableCollection<PlcVarMonitor>();
-
-
- public GlobalVarMonitorViewModel()
- {
- Type type = typeof(GVL_BigStation);
- PropertyInfo[] properties = type.GetProperties();
-
- if (PlcInfo.Count == 0)
- {
- foreach (PropertyInfo mi in properties)
- {
- PropertyInfo a = type.GetProperty(mi.Name);
- object ab = a.GetValue(null);
-
- var num = GVL_BigStation.HKPlc_Read;
- var res = a.GetCustomAttribute<PlcCommAttribute>();
- string describe = "";
- if (res != null)
- {
- describe = res.Describe;
- PlcInfo.Add(new PlcVarMonitor()
- {
- SerialNum = PlcInfo.Count + 1,
- Variable = mi.Name,
- Type = mi.PropertyType.Name,
- Describe = describe,
- NowValue = ab.ToString(),
- });
- }
- else
- {
- describe = "";
- }
- }
- }
-
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- foreach (PropertyInfo mi in properties)
- {
- PropertyInfo a = type.GetProperty(mi.Name);
- object ab = a.GetValue(null);
- int index = Array.FindIndex(PlcInfo.ToArray(), p => p.Variable == mi.Name);
- if (index != -1)
- {
- PlcInfo.ElementAt(index).NowValue = ab.ToString();
- }
- }
- Thread.Sleep(100);
- }), "Global变量读取", true);
-
-
- }
- }
-
- }
|