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

93 lines
3.3 KiB

  1. using BPASmartClient.Peripheral;
  2. using System;
  3. using BPASmartClient.Modbus;
  4. using BPASmartClient.Helper;
  5. using System.Threading;
  6. using BPASmartClient.Model.奶茶味魔方;
  7. using BPASmartClient.EventBus;
  8. using static BPASmartClient.EventBus.EventBus;
  9. namespace BPASmartClient.MilkTeaCube
  10. {
  11. public class MilkTeaCubeMachine: BasePeripheral
  12. {
  13. public ModbusTcp modbus =new ModbusTcp();
  14. public override void Init()
  15. {
  16. modbus.ModbusTcpConnect(communicationPar.IPAddress);
  17. EventBus.EventBus.GetInstance().Subscribe<MilkTea_MakeMilkTeaEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  18. {
  19. if (@event == null) return;
  20. var par = @event as MilkTea_MakeMilkTeaEvent;
  21. switch (par?.TagName)
  22. {
  23. case "Start":
  24. modbus.Write("LB14", true);
  25. Thread.Sleep(200);
  26. modbus.Write("LB14", false);
  27. break;
  28. case "ParameterSet":
  29. modbus.Write("LB14", false);
  30. Thread.Sleep(500);
  31. modbus.Write("LW1001", par.MilkTeaKind[0]);
  32. modbus.Write("LW1003", par.MilkTeaKind[1]);
  33. modbus.Write("LW1004", par.MilkTeaKind[2]);
  34. modbus.Write("LW1005", par.MilkTeaKind[3]);
  35. modbus.Write("LW1006", par.MilkTeaKind[4]);
  36. modbus.Write("LW1007", par.MilkTeaKind[5]);
  37. modbus.Write("LW1008", par.MilkTeaKind[6]);
  38. modbus.Write("LW1009", par.MilkTeaKind[7]);
  39. modbus.Write("LW1010", par.MilkTeaKind[8]);
  40. modbus.Write("LW1011", par.MilkTeaKind[9]);
  41. modbus.Write("LW1012", par.MilkTeaKind[10]);
  42. modbus.Write("LW1013", par.MilkTeaKind[11]);
  43. break;
  44. case "StartSignReset":
  45. modbus.Write("LB14", false);
  46. break;
  47. default:
  48. break;
  49. }
  50. });
  51. ThreadManage.GetInstance().StartLong(new Action(() =>
  52. {
  53. IsConnected = modbus.Connected;
  54. if (!IsConnected) IsWork = false;
  55. if (IsConnected)
  56. {
  57. IsWork = true;
  58. if (status != null)
  59. {
  60. var a = modbus.Read("LB0");
  61. var b = modbus.Read("LB13");
  62. if (a is bool[] a1 && b is bool[] b1)
  63. {
  64. SetStatus("Get_MilkTeaCubeStatus", a1[0]);
  65. SetStatus("Get_MilkTeaCubeDosingStatus", b1[0]);
  66. }
  67. }
  68. Thread.Sleep(500);
  69. }
  70. Thread.Sleep(1000);
  71. }), $"奶茶味魔方设备连接", true);
  72. }
  73. public override void Start()
  74. {
  75. }
  76. public override void Stop()
  77. {
  78. }
  79. public override void WriteData(string address, object value)
  80. {
  81. }
  82. protected override void InitStatus()
  83. {
  84. }
  85. }
  86. }