| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 | 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<string, T> GetIOData<T>(string type)        {            //get only value by keys            Dictionary<string, T> da = new Dictionary<string, T>();            if (type == "PLC1.DIList")            {                var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.DIList");                if (diList != null)                {                    List<NotifiableIoItem> di = (List<NotifiableIoItem>)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<NotifiableIoItem> item = (List<NotifiableIoItem>)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<NotifiableIoItem> di = (List<NotifiableIoItem>)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<NotifiableIoItem> item = (List<NotifiableIoItem>)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<IOItem<T>> InitIOData<T>(string type)        {            //get the whole informations            ObservableCollection<IOItem<T>> da = new ObservableCollection<IOItem<T>>();            if (type == "PLC1.DIList")            {                var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.DIList");                if (diList != null)                {                    List<NotifiableIoItem> di = (List<NotifiableIoItem>)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<T>()                            {                                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<NotifiableIoItem> item = (List<NotifiableIoItem>)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<T>()                            {                                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<NotifiableIoItem> item = (List<NotifiableIoItem>)diList;                    for (int i = 0; i < item.Count; i++)                    {                        if (item[i].Provider != Provider)                            continue;                             da.Add(new IOItem<T>()                            {                                Index = item[i].Index,                                Name = item[i].Name,                                Value = (T)(object)item[i].ShortValue,                                Address = item[i].Address                            });                     }                }            }            return da;        }        public ObservableCollection<AOItem> InitIOData(string type)        {            //get the whole informations            ObservableCollection<AOItem> da = new ObservableCollection<AOItem>();            if (type == "PLC1.AOList")            {                var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.AOList");                if (diList != null)                {                    List<NotifiableIoItem> item = (List<NotifiableIoItem>)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)        {        }    }}
 |