|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- 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<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;
- }
- });
- 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()
- {
- }
- }
- }
|