using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using HBLConsole.Service; using HBLConsole.Model; using System.Threading; using HBLConsole.GVL; namespace HBLConsole.Communication { public class ConnectHelper { private volatile static ConnectHelper _Instance; public static ConnectHelper GetInstance => _Instance ?? (_Instance = new ConnectHelper()); private ConnectHelper() { } public void Init() { Json.Read(); foreach (var item in Json.Data.communicationSets) { //if (item.ClientDeviceType == GVL.GeneralConfig.DeviceType.ToString()) //{ if (item.IsActive) { switch (item.deviceType) { case EDeviceType.Siemens: break; case EDeviceType.ModbusRtu: if (item.Device is SerialDeviceBase rtu) { //咖啡机主控程序 //private CoffeeMachine coffeeMachine; ////冰淇淋主控程序 //private IceCreamMachine iceCreamMachine; } break; case EDeviceType.ModbusTcp: if (item.Device is ModbusTcp modbus) { ModbusTcpHelper.GetInstance.ModbusTcpConnect(modbus.IP, modbus.PortNum); } break; case EDeviceType.SerialPort: break; case EDeviceType.Lebai: if (item.Device is ModbusTcp tcp) { LebaiHelper.GetInstance.Connect(tcp.IP); //开启机器人重连检测线程 ThreadManage.GetInstance.StartLong(() => { LebaiHelper.GetInstance.Reconnect(tcp.IP); Task.Delay(5000); }, "机器人重连检测"); } break; case EDeviceType.JAKA: if (item.Device is ModbusTcp jaka) { JaKaHelper.GetInstance.Connect(jaka.IP); } break; case EDeviceType.MCU: if (item.Device is SerialDeviceBase ser) { MCUSerialHelper.GetInstance.Open(ser.ComSerialPort, int.Parse(ser.BaudRate)); } break; case EDeviceType.Juicer: if (item.Device is SerialDeviceBase Juicer) { JuicerHelper.GetInstance.Open(Juicer.ComSerialPort, int.Parse(Juicer.BaudRate)); } break; default: break; } //} } } ActionManage.GetInstance.Send($"{GVL.GeneralConfig.DeviceType.ToString()}/ConnectOk"); } } }