using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.IOCore; using OpenSEMI.ClientBase.IO; using OpenSEMI.ClientBase.ServiceProvider; namespace VirgoUI.Client.Models.Common.IO { public class IO2Provider : IProvider { private static IO2Provider _Instance = null; public static IO2Provider Instance { get { if (_Instance == null) { _Instance = new IO2Provider(); _Instance.Create(); } return _Instance; } } private const string Provider = "System.io2"; public void Create() { } public Dictionary GetIOData(string type) { //get only value by keys Dictionary da = new Dictionary(); if (type == "PLC1.DIList") { var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.DIList"); if (diList != null) { List di = (List)diList; for (int i = 0; i < di.Count; i++) { if (di[i].Provider != Provider) continue; bool value = true; if (value is T) { da[di[i].Name] = (T)(object)di[i].BoolValue; } } } } if (type == "PLC1.DOList") { var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.DOList"); if (diList != null) { List item = (List)diList; for (int i = 0; i < item.Count; i++) { if (item[i].Provider != Provider) continue; bool value = true; if (value is T) { da[item[i].Name] = (T)(object)item[i].BoolValue; } } } } if (type == "PLC1.AIList") { var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.AIList"); if (diList != null) { List di = (List)diList; for (int i = 0; i < di.Count; i++) { if (di[i].Provider != Provider) continue; da[di[i].Name] = (T)(object)di[i].ShortValue; } } } if (type == "PLC1.AOList") { var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.AOList"); if (diList != null) { List item = (List)diList; for (int i = 0; i < item.Count; i++) { if (item[i].Provider != Provider) continue; da[item[i].Name] = (T)(object)item[i].ShortValue; } } } return da; } public ObservableCollection> InitIOData(string type) { //get the whole informations ObservableCollection> da = new ObservableCollection>(); if (type == "PLC1.DIList") { var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.DIList"); if (diList != null) { List di = (List)diList; for (int i = 0; i < di.Count; i++) { if (di[i].Provider != Provider) continue; bool value = true; if (value is T) { da.Add(new IOItem() { Index = di[i].Index, Name = di[i].Name, Value = (T)(object)di[i].BoolValue, Address = di[i].Address }); } } } } if (type == "PLC1.DOList") { var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.DOList"); if (diList != null) { List item = (List)diList; for (int i = 0; i < item.Count; i++) { if (item[i].Provider != Provider) continue; bool value = true; if (value is T) { da.Add(new IOItem() { Index = item[i].Index, Name = item[i].Name, Value = (T)(object)item[i].BoolValue, Address = item[i].Address }); } } } } if (type == "PLC1.AIList") { var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.AIList"); if (diList != null) { List item = (List)diList; for (int i = 0; i < item.Count; i++) { if (item[i].Provider != Provider) continue; da.Add(new IOItem() { Index = item[i].Index, Name = item[i].Name, Value = (T)(object)item[i].ShortValue, Address = item[i].Address }); } } } return da; } public ObservableCollection InitIOData(string type) { //get the whole informations ObservableCollection da = new ObservableCollection(); if (type == "PLC1.AOList") { var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.AOList"); if (diList != null) { List item = (List)diList; for (int i = 0; i < item.Count; i++) { if (item[i].Provider != Provider) continue; //bool value = true; //if (value is T) { da.Add(new AOItem() { Index = item[i].Index, Name = item[i].Name, Value = item[i].ShortValue, Address = item[i].Address }); } } } } return da; } public void SetAO(string name, float value) { } public void SetDO(string name, bool value) { } } }