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 IO1Provider : IProvider { private static IO1Provider _Instance = null; public static IO1Provider Instance { get { if (_Instance == null) { _Instance = new IO1Provider(); _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 aiList = QueryDataClient.Instance.Service.GetData($"{Provider}.AIList"); if (aiList != null) { List ai = (List)aiList; for (int i = 0; i < ai.Count; i++) { if (ai[i].Provider != Provider) continue; short value = 0; if (value is T) { da[ai[i].Name] = (T)(object)ai[i].ShortValue; } } } } if (type == "PLC1.AOList") { var aoList = QueryDataClient.Instance.Service.GetData($"{Provider}.AOList"); if (aoList != null) { List item = (List)aoList; for (int i = 0; i < item.Count; i++) { if (item[i].Provider != Provider) continue; short value = 0; if (value is T) { da[item[i].Name] = (T)(object)item[i].ShortValue; } } } } return da; } public ObservableCollection> InitIOData(string type) { //get the whole information 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 aiList = QueryDataClient.Instance.Service.GetData($"{Provider}.AIList"); if (aiList != null) { List ai = (List)aiList; for (int i = 0; i < ai.Count; i++) { if (ai[i].Provider != Provider) continue; short value = 0; if (value is T) { da.Add(new IOItem() { Index = ai[i].Index, Name = ai[i].Name, Value = (T)(object)ai[i].ShortValue, Address = ai[i].Address }); } } } } return da; } public ObservableCollection InitIOData(string type) { //get the whole information ObservableCollection da = new ObservableCollection(); if (type == "PLC1.AOList") { var aoList = QueryDataClient.Instance.Service.GetData($"{Provider}.AOList"); if (aoList != null) { List item = (List)aoList; for (int i = 0; i < item.Count; i++) { if (item[i].Provider != Provider) continue; 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) { } } }