终端一体化运控平台
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.
 
 
 

83 line
2.9 KiB

  1. using BPA.Helper;
  2. using BPASmartClient.Model;
  3. using BPASmartClient.Peripheral;
  4. using BPASmartClient.SerialPort;
  5. using static BPA.Helper.EventBus;
  6. namespace BPASmartClient.IceMaker
  7. {
  8. public class IceMakerMachine : BasePeripheral
  9. {
  10. IceMakerHelper iceMakerHelper = new IceMakerHelper();
  11. public override void Init()
  12. {
  13. iceMakerHelper.Open(communicationPar.SerialPort, communicationPar.BaudRate);
  14. TaskManage.GetInstance.StartLong(new Action(() =>
  15. {
  16. IsConnected = iceMakerHelper.IsOpen;
  17. if (!IsConnected) IsWork = false;
  18. while (IsConnected)
  19. {
  20. IsWork = true;
  21. if (status != null)
  22. {
  23. SetStatus("MakeIceDeviceStatus", iceMakerHelper.GetDeviceStatus());
  24. SetStatus("MakeIceConnected", IsConnected);
  25. }
  26. Thread.Sleep(500);
  27. }
  28. Thread.Sleep(1000);
  29. }), $"设备[{DeviceId}]制冰机读取线程", true);
  30. EventBus.GetInstance().Subscribe<StartMakeIce>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  31. {
  32. if (@event == null) return;
  33. iceMakerHelper.StartCook();
  34. });
  35. EventBus.GetInstance().Subscribe<StopMakeIce>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  36. {
  37. if (@event == null) return;
  38. iceMakerHelper.EndCook();
  39. });
  40. EventBus.GetInstance().Subscribe<PumpMakeIce>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  41. {
  42. if (@event == null) return;
  43. iceMakerHelper.pump();
  44. });
  45. EventBus.GetInstance().Subscribe<StandbyMakeIce>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  46. {
  47. if (@event == null) return;
  48. iceMakerHelper.Standby();
  49. });
  50. EventBus.GetInstance().Subscribe<PowerOnMakeIce>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  51. {
  52. if (@event == null) return;
  53. iceMakerHelper.PowerOn();
  54. });
  55. EventBus.GetInstance().Subscribe<SetIceNumber>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  56. {
  57. if (@event == null) return;
  58. var parm = @event as SetIceNumber;
  59. iceMakerHelper.IceValue(Convert.ToByte(parm?.Value));
  60. });
  61. }
  62. public override void Start()
  63. {
  64. }
  65. public override void Stop()
  66. {
  67. }
  68. public override void WriteData(string address, object value)
  69. {
  70. }
  71. protected override void InitStatus()
  72. {
  73. }
  74. }
  75. }