using BPASmartClient.Peripheral; using System; using BPASmartClient.Modbus; using BPA.Helper; using System.Threading; using BPASmartClient.Model.奶茶味魔方; using static BPA.Helper.EventBus; namespace BPASmartClient.MilkTeaCube { public class MilkTeaCubeMachine : BasePeripheral { public ModbusTcp modbus = new ModbusTcp(); public override void Init() { modbus.ModbusTcpConnect(communicationPar.IPAddress); EventBus.GetInstance.Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack) { if (@event == null) return; var par = @event as MilkTea_MakeMilkTeaEvent; switch (par?.TagName) { case "Start": modbus.Write("LB14", true); Thread.Sleep(200); modbus.Write("LB14", false); break; case "ParameterSet": modbus.Write("LB14", false); Thread.Sleep(500); modbus.Write("LW1001", par.MilkTeaKind[0]); modbus.Write("LW1003", par.MilkTeaKind[1]); modbus.Write("LW1004", par.MilkTeaKind[2]); modbus.Write("LW1005", par.MilkTeaKind[3]); modbus.Write("LW1006", par.MilkTeaKind[4]); modbus.Write("LW1007", par.MilkTeaKind[5]); modbus.Write("LW1008", par.MilkTeaKind[6]); modbus.Write("LW1009", par.MilkTeaKind[7]); modbus.Write("LW1010", par.MilkTeaKind[8]); modbus.Write("LW1011", par.MilkTeaKind[9]); modbus.Write("LW1012", par.MilkTeaKind[10]); modbus.Write("LW1013", par.MilkTeaKind[11]); break; case "StartSignReset": modbus.Write("LB14", false); break; default: break; } }); TaskManage.GetInstance.StartLong(new Action(() => { IsConnected = modbus.Connected; if (!IsConnected) IsWork = false; if (IsConnected) { IsWork = true; if (status != null) { var a = modbus.Read("LB0"); var b = modbus.Read("LB13"); if (a is bool[] a1 && b is bool[] b1) { SetStatus("Get_MilkTeaCubeStatus", a1[0]); SetStatus("Get_MilkTeaCubeDosingStatus", b1[0]); } } Thread.Sleep(500); } Thread.Sleep(1000); }), $"奶茶味魔方设备连接", true); } public override void Start() { } public override void Stop() { } public override void WriteData(string address, object value) { } protected override void InitStatus() { } } }