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

91 rivejä
3.2 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. ThreadManage.GetInstance().StartLong(new Action(() =>
  18. {
  19. IsConnected = modbus.Connected;
  20. if (!IsConnected) IsWork = false;
  21. if (IsConnected)
  22. {
  23. IsWork = true;
  24. if (status != null)
  25. {
  26. var a = modbus.Read("LB0");
  27. var b = modbus.Read("LB13");
  28. if (a is bool[] a1 && b is bool[] b1)
  29. {
  30. SetStatus("Get_MilkTeaCubeStatus", a1[0]);
  31. SetStatus("Get_MilkTeaCubeDosingStatus", b1[0]);
  32. }
  33. }
  34. Thread.Sleep(500);
  35. }
  36. Thread.Sleep(1000);
  37. }), $"奶茶味魔方设备连接", true);
  38. EventBus.EventBus.GetInstance().Subscribe<MilkTea_MakeMilkTeaEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  39. {
  40. if (@event == null) return;
  41. var par = @event as MilkTea_MakeMilkTeaEvent;
  42. switch (par?.TagName)
  43. {
  44. case "Start":
  45. modbus.Write("LB14",true);
  46. break;
  47. case "ParameterSet":
  48. modbus.Write("LB14", false);
  49. Thread.Sleep(500);
  50. modbus.Write("LW1002", par.MilkTeaKind[0]);
  51. modbus.Write("LW1006", par.MilkTeaKind[1]);
  52. modbus.Write("LW1008", par.MilkTeaKind[2]);
  53. modbus.Write("LW1010", par.MilkTeaKind[3]);
  54. modbus.Write("LW1012", par.MilkTeaKind[4]);
  55. modbus.Write("LW1014", par.MilkTeaKind[5]);
  56. modbus.Write("LW1016", par.MilkTeaKind[6]);
  57. modbus.Write("LW1018", par.MilkTeaKind[7]);
  58. modbus.Write("LW1020", par.MilkTeaKind[8]);
  59. modbus.Write("LW1022", par.MilkTeaKind[9]);
  60. modbus.Write("LW1024", par.MilkTeaKind[10]);
  61. modbus.Write("LW1026", par.MilkTeaKind[11]);
  62. break;
  63. case "StartSignReset":
  64. modbus.Write("LB14", false);
  65. break;
  66. default:
  67. break;
  68. }
  69. });
  70. }
  71. public override void Start()
  72. {
  73. }
  74. public override void Stop()
  75. {
  76. }
  77. public override void WriteData(string address, object value)
  78. {
  79. }
  80. protected override void InitStatus()
  81. {
  82. }
  83. }
  84. }