1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Collections.ObjectModel;
- using System.Threading;
- using System.Windows;
- using System.Windows.Threading;
- using OpenSEMI.ClientBase;
- using OpenSEMI.ClientBase.IO;
- namespace VirgoUI.Client.Models.Common.IO
- {
- public class IO2ViewModel : BaseModel
- {
- protected override void OnInitialize()
- {
- base.OnInitialize();
- //init I/O get the whole I/O info
- this.AIs = IO2Provider.Instance.InitIOData<short>("PLC1.AIList");
- this.AOs = IO2Provider.Instance.InitIOData("PLC1.AOList");
- this.DIs = IO2Provider.Instance.InitIOData<bool>("PLC1.DIList");
- this.DOs = IO2Provider.Instance.InitIOData<bool>("PLC1.DOList");
- }
- protected override void OnActivate()
- {
- base.OnActivate();
- BaseApp.Instance.UIHandler.Register("IO2View", GetIOs);
- }
- protected override void OnDeactivate(bool close)
- {
- base.OnDeactivate(close);
- BaseApp.Instance.UIHandler.UnRegister("IO2View");
- }
- public void SetDO(IOItem<bool> _do)
- {
- IO2Provider.Instance.SetDO(_do.Name, !_do.Value);
- }
- public void SetAO(AOItem _ao)
- {
- IO2Provider.Instance.SetAO(_ao.Name, _ao.Value);
- }
- public void GetIOs()
- {
- //get I/O value and update UI
- Dictionary<string, short> _ai = IO2Provider.Instance.GetIOData<short>("PLC1.AIList");
- Dictionary<string, short> _ao = IO2Provider.Instance.GetIOData<short>("PLC1.AOList");
- Dictionary<string, bool> _di = IO2Provider.Instance.GetIOData<bool>("PLC1.DIList");
- Dictionary<string, bool> _do = IO2Provider.Instance.GetIOData<bool>("PLC1.DOList");
- foreach (IOItem<short> item in AIs)
- {
- if (_ai.ContainsKey(item.Name))
- item.Value = _ai[item.Name];
- }
- foreach (IOItem<short> item in AOs)
- {
- if (_ao.ContainsKey(item.Name))
- item.Value = _ao[item.Name];
- }
- foreach (IOItem<bool> item in DIs)
- {
- if (_di.ContainsKey(item.Name))
- item.Value = _di[item.Name];
- }
- foreach (IOItem<bool> item in DOs)
- {
- if (_do.ContainsKey(item.Name))
- item.Value = _do[item.Name];
- }
- }
- public ObservableCollection<IOItem<short>> AIs { get; private set; }
- public ObservableCollection<AOItem> AOs { get; private set; }
- public ObservableCollection<IOItem<bool>> DIs { get; private set; }
- public ObservableCollection<IOItem<bool>> DOs { get; private set; }
- }
- }
|