123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- 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<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 aiList = QueryDataClient.Instance.Service.GetData($"{Provider}.AIList");
- if (aiList != null)
- {
- List<NotifiableIoItem> ai = (List<NotifiableIoItem>)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<NotifiableIoItem> item = (List<NotifiableIoItem>)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<IOItem<T>> InitIOData<T>(string type)
- {
- //get the whole information
- 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 aiList = QueryDataClient.Instance.Service.GetData($"{Provider}.AIList");
- if (aiList != null)
- {
- List<NotifiableIoItem> ai = (List<NotifiableIoItem>)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<T>()
- {
- Index = ai[i].Index,
- Name = ai[i].Name,
- Value = (T)(object)ai[i].ShortValue,
- Address = ai[i].Address
- });
- }
- }
- }
- }
- return da;
- }
- public ObservableCollection<AOItem> InitIOData(string type)
- {
- //get the whole information
- ObservableCollection<AOItem> da = new ObservableCollection<AOItem>();
- if (type == "PLC1.AOList")
- {
- var aoList = QueryDataClient.Instance.Service.GetData($"{Provider}.AOList");
- if (aoList != null)
- {
- List<NotifiableIoItem> item = (List<NotifiableIoItem>)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)
- {
- }
- }
- }
|