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

IceMakerMachine.cs 3.0 KiB

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