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

67 lines
2.2 KiB

  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.Icemoker
  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("GetDeviceStatus", iceMakerHelper.GetDeviceStatus());
  25. }
  26. Thread.Sleep(500);
  27. }
  28. Thread.Sleep(1000);
  29. }), $"设备[{DeviceId}]制冰机读取线程", true);
  30. EventBus.EventBus.GetInstance().Subscribe<StartMakeIce>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  31. {
  32. if (@event == null) return;
  33. iceMakerHelper.StartCook();
  34. });
  35. EventBus.EventBus.GetInstance().Subscribe<StopMakeIce>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  36. {
  37. if (@event == null) return;
  38. iceMakerHelper.EndCook();
  39. });
  40. EventBus.EventBus.GetInstance().Subscribe<SetIceNumber>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  41. {
  42. if (@event == null) return;
  43. var parm = @event as SetIceNumber;
  44. iceMakerHelper.IceValue(Convert.ToByte(parm?.Value));
  45. });
  46. }
  47. public override void Start()
  48. {
  49. }
  50. public override void Stop()
  51. {
  52. }
  53. public override void WriteData(string address, object value)
  54. {
  55. }
  56. protected override void InitStatus()
  57. {
  58. }
  59. }
  60. }