终端一体化运控平台
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

92 wiersze
3.3 KiB

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