终端一体化运控平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

75 行
2.1 KiB

  1. using BPASmartClient.Model;
  2. using System;
  3. using System.Collections.Concurrent;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace BPASmartClient.Peripheral
  10. {
  11. /// <summary>
  12. /// 外设基类
  13. /// </summary>
  14. public abstract class BasePeripheral : IPeripheral
  15. {
  16. /// <summary>
  17. /// 是否已连接
  18. /// </summary>
  19. public bool IsConnected { get; set; }
  20. /// <summary>
  21. /// 是否工作正常
  22. /// </summary>
  23. public bool IsWork { get; set; }
  24. /// <summary>
  25. /// 归属设备Id
  26. /// </summary>
  27. public int DeviceId { get; set; }
  28. public CommunicationPar communicationPar { get; set; } = new CommunicationPar();
  29. public ConcurrentDictionary<string, object> status { get; set; } = new ConcurrentDictionary<string, object>();
  30. public ObservableCollection<Variable> variables { get; set; } = new ObservableCollection<Variable>();
  31. /// <summary>q
  32. /// 外设状态集合
  33. /// </summary>
  34. //protected ConcurrentDictionary<string, object> status = new ConcurrentDictionary<string, object>();
  35. /// <summary>
  36. /// 初始化外设状态
  37. /// </summary>
  38. protected abstract void InitStatus();
  39. public object? GetStatus(string statusName)
  40. {
  41. if (status.ContainsKey(statusName))
  42. return status[statusName];
  43. return null;
  44. }
  45. public void SetStatus(string statusName, object value)
  46. {
  47. if (status.ContainsKey(statusName))
  48. status[statusName] = value;
  49. else
  50. status.TryAdd(statusName, value);
  51. }
  52. public abstract void Start();
  53. public abstract void Stop();
  54. public abstract void Init();
  55. //public abstract void ReadData(string address);
  56. public abstract void WriteData(string address, object value);
  57. public ConcurrentDictionary<string, object> GetAllStatus()
  58. {
  59. return status;
  60. }
  61. }
  62. }