终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

82 rivejä
2.4 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. public ConcurrentDictionary<string, Variable> tempVar { get; set; } = new();
  32. /// <summary>q
  33. /// 外设状态集合
  34. /// </summary>
  35. //protected ConcurrentDictionary<string, object> status = new ConcurrentDictionary<string, object>();
  36. /// <summary>
  37. /// 初始化外设状态
  38. /// </summary>
  39. protected abstract void InitStatus();
  40. public object? GetStatus(string statusName)
  41. {
  42. if (status.ContainsKey(statusName))
  43. return status[statusName];
  44. return null;
  45. }
  46. public void SetStatus(string statusName, object value)
  47. {
  48. if (status.ContainsKey(statusName))
  49. status[statusName] = value;
  50. else
  51. status.TryAdd(statusName, value);
  52. }
  53. public abstract void Start();
  54. public abstract void Stop();
  55. public abstract void Init();
  56. //public abstract void ReadData(string address);
  57. public abstract void WriteData(string address, object value);
  58. //public abstract void AddVarInfo(string add, int len);
  59. public ConcurrentDictionary<string, object> GetAllStatus()
  60. {
  61. return status;
  62. }
  63. public ConcurrentDictionary<string, Variable> GetVariable()
  64. {
  65. return tempVar;
  66. }
  67. }
  68. }