123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Windows;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.IOCore;
- using MECF.Framework.Common.OperationCenter;
- using OpenSEMI.ClientBase;
- using OpenSEMI.ClientBase.IO;
- namespace VirgoUI.Client.Models.PMs
- {
- public class AOItem32 : IOItem<float>
- {
- public static readonly DependencyProperty NewValueProperty = DependencyProperty.Register(nameof(NewValue), typeof(float), typeof(AOItem32), new PropertyMetadata((object)(float)0));
- public static readonly DependencyProperty TextSavedProperty = DependencyProperty.Register(nameof(TextSaved), typeof(bool), typeof(AOItem32), new PropertyMetadata((object)true));
- public float NewValue
- {
- get
- {
- return (float)this.GetValue( NewValueProperty);
- }
- set
- {
- this.SetValue( NewValueProperty, (object)value);
- }
- }
- public bool TextSaved
- {
- get
- {
- return (bool)this.GetValue( TextSavedProperty);
- }
- set
- {
- this.SetValue( TextSavedProperty, (object)value);
- }
- }
- }
- public class PmIoViewModel : BaseModel, ISupportMultipleSystem
- {
- private int MenuPermission;
- private bool _TwoColumnMode;
- public bool TwoColumnMode
- {
- get { return _TwoColumnMode; }
- set { _TwoColumnMode = value; NotifyOfPropertyChange("TwoColumnMode"); }
- }
- public string SystemName { get; set; }
- public ObservableCollection<IOItem<float>> AIs { get; private set; }
- public ObservableCollection<AOItem32> AOs { get; private set; }
- public ObservableCollection<IOItem<bool>> DIs { get; private set; }
- public ObservableCollection<IOItem<bool>> DOs { get; private set; }
- private Dictionary<string, IOItem<bool>> _diMap = new Dictionary<string, IOItem<bool>>();
- private Dictionary<string, IOItem<bool>> _doMap = new Dictionary<string, IOItem<bool>>();
- private Dictionary<string, IOItem<float>> _aiMap = new Dictionary<string, IOItem<float>>();
- private Dictionary<string, AOItem32> _aoMap = new Dictionary<string, AOItem32>();
- protected override void OnInitialize()
- {
- base.OnInitialize();
- TwoColumnMode = true;
- MenuPermission = ClientApp.Instance.GetPermission($"IO{SystemName}");
- BuildIoSchema();
- }
- protected override void OnActivate()
- {
- base.OnActivate();
- BaseApp.Instance.UIHandler.Register(SystemName + "IOView", GetIOs);
- }
- protected override void OnDeactivate(bool close)
- {
- base.OnDeactivate(close);
- BaseApp.Instance.UIHandler.UnRegister(SystemName + "IOView");
- }
- public void SetAO(AOItem32 aoItem)
- {
- if (MenuPermission != 3) return;
- InvokeClient.Instance.Service.DoOperation("System.SetAoValue32", aoItem.Name, aoItem.NewValue);
- }
- public void SetDO(IOItem<bool> doItem)
- {
- InvokeClient.Instance.Service.DoOperation("System.SetDoValue", doItem.Name, !doItem.Value);
- }
- public void BuildIoSchema()
- {
- if (DIs == null)
- {
- var itemList = QueryDataClient.Instance.Service.GetData($"{SystemName}.PLC.DIItemList");
- if (itemList != null)
- {
- DIs = new ObservableCollection<IOItem<bool>>();
- foreach (var item in (List<NotifiableIoItem>)itemList)
- {
- var io = new IOItem<bool>()
- {
- Index = item.Index,
- Name = item.Name,
- Value = item.BoolValue,
- Address = item.Address
- };
- DIs.Add(io);
- _diMap.Add($"IO.{item.Name}", io);
- }
- }
- NotifyOfPropertyChange(nameof(DIs));
- }
- if (DOs == null)
- {
- var itemList = QueryDataClient.Instance.Service.GetData($"{SystemName}.PLC.DOItemList");
- if (itemList != null)
- {
- DOs = new ObservableCollection<IOItem<bool>>();
- foreach (var item in (List<NotifiableIoItem>)itemList)
- {
- var io = new IOItem<bool>()
- {
- Index = item.Index,
- Name = item.Name,
- Value = item.BoolValue,
- Address = item.Address
- };
- DOs.Add(io);
- _doMap.Add($"IO.{item.Name}", io);
- }
- }
- NotifyOfPropertyChange(nameof(DOs));
- }
- if (AIs == null)
- {
- var itemList = QueryDataClient.Instance.Service.GetData($"{SystemName}.PLC.AIItemList");
- if (itemList != null)
- {
- AIs = new ObservableCollection<IOItem<float>>();
- foreach (var item in (List<NotifiableIoItem>)itemList)
- {
- var io = new IOItem<float>()
- {
- Index = item.Index,
- Name = item.Name,
- Value = item.ShortValue,
- Address = item.Address
- };
- AIs.Add(io);
- _aiMap.Add($"IO32.{item.Name}", io);
- }
- }
- NotifyOfPropertyChange(nameof(AIs));
- }
- if (AOs == null)
- {
- var itemList = QueryDataClient.Instance.Service.GetData($"{SystemName}.PLC.AOItemList");
- if (itemList != null)
- {
- AOs = new ObservableCollection<AOItem32>();
- foreach (var item in (List<NotifiableIoItem>)itemList)
- {
- var io = new AOItem32()
- {
- Index = item.Index,
- Name = item.Name,
- Value = item.ShortValue,
- Address = item.Address
- };
- AOs.Add(io);
- _aoMap.Add($"IO32.{item.Name}", io);
- }
- }
- NotifyOfPropertyChange(nameof(AOs));
- }
- }
- public void GetIOs()
- {
- var diValues = QueryDataClient.Instance.Service.PollData(_diMap.Keys);
- foreach (var item in _diMap)
- {
- if (diValues.ContainsKey(item.Key))
- _diMap[item.Key].Value = (bool)diValues[item.Key];
- }
- var doValues = QueryDataClient.Instance.Service.PollData(_doMap.Keys);
- foreach (var item in _doMap)
- {
- if (doValues.ContainsKey(item.Key))
- _doMap[item.Key].Value = (bool)doValues[item.Key];
- }
- var aiValues = QueryDataClient.Instance.Service.PollData(_aiMap.Keys);
- foreach (var item in _aiMap)
- {
- if (aiValues.ContainsKey(item.Key))
- _aiMap[item.Key].Value = (float)aiValues[item.Key];
- }
- var aoValues = QueryDataClient.Instance.Service.PollData(_aoMap.Keys);
- foreach (var item in _aoMap)
- {
- if (aoValues.ContainsKey(item.Key))
- _aoMap[item.Key].Value = (float)aoValues[item.Key];
- }
- }
- }
- }
|