|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using BPASmartClient.Peripheral;
- using System;
- using BPASmartClient.Modbus;
- using BPASmartClient.Helper;
- using System.Threading;
- using BPASmartClient.Model.̲ζħ;
- using BPASmartClient.EventBus;
- using static BPASmartClient.EventBus.EventBus;
-
- namespace BPASmartClient.MilkTeaCube
- {
- public class MilkTeaCubeMachine: BasePeripheral
- {
- public ModbusTcp modbus =new ModbusTcp();
- public override void Init()
- {
- modbus.ModbusTcpConnect(communicationPar.IPAddress);
- EventBus.EventBus.GetInstance().Subscribe<MilkTea_MakeMilkTeaEvent>(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;
- }
- });
- ThreadManage.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()
- {
- }
- }
- }
|