|
- 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);
- 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);
- 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);
- break;
- case "ParameterSet":
- modbus.Write("LB14", false);
- Thread.Sleep(500);
- modbus.Write("LW1002", par.MilkTeaKind[0]);
- modbus.Write("LW1006", par.MilkTeaKind[1]);
- modbus.Write("LW1008", par.MilkTeaKind[2]);
- modbus.Write("LW1010", par.MilkTeaKind[3]);
- modbus.Write("LW1012", par.MilkTeaKind[4]);
- modbus.Write("LW1014", par.MilkTeaKind[5]);
- modbus.Write("LW1016", par.MilkTeaKind[6]);
- modbus.Write("LW1018", par.MilkTeaKind[7]);
- modbus.Write("LW1020", par.MilkTeaKind[8]);
- modbus.Write("LW1022", par.MilkTeaKind[9]);
- modbus.Write("LW1024", par.MilkTeaKind[10]);
- modbus.Write("LW1026", par.MilkTeaKind[11]);
-
- break;
- case "StartSignReset":
- modbus.Write("LB14", false);
- break;
- default:
- break;
- }
- });
- }
- public override void Start()
- {
- }
-
- public override void Stop()
- {
- }
-
- public override void WriteData(string address, object value)
- {
-
- }
-
- protected override void InitStatus()
- {
- }
- }
- }
|