Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 

89 rindas
3.5 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using HBLConsole.Service;
  7. using HBLConsole.Model;
  8. using System.Threading;
  9. using HBLConsole.GVL;
  10. namespace HBLConsole.Communication
  11. {
  12. public class ConnectHelper
  13. {
  14. private volatile static ConnectHelper _Instance;
  15. public static ConnectHelper GetInstance => _Instance ?? (_Instance = new ConnectHelper());
  16. private ConnectHelper() { }
  17. public void Init()
  18. {
  19. Json<CommunicationPar>.Read();
  20. foreach (var item in Json<CommunicationPar>.Data.communicationSets)
  21. {
  22. //if (item.ClientDeviceType == GVL.GeneralConfig.DeviceType.ToString())
  23. //{
  24. if (item.IsActive)
  25. {
  26. switch (item.deviceType)
  27. {
  28. case EDeviceType.Siemens:
  29. break;
  30. case EDeviceType.ModbusRtu:
  31. if (item.Device is SerialDeviceBase rtu)
  32. {
  33. //咖啡机主控程序
  34. //private CoffeeMachine coffeeMachine;
  35. ////冰淇淋主控程序
  36. //private IceCreamMachine iceCreamMachine;
  37. }
  38. break;
  39. case EDeviceType.ModbusTcp:
  40. if (item.Device is ModbusTcp modbus)
  41. {
  42. ModbusTcpHelper.GetInstance.ModbusTcpConnect(modbus.IP, modbus.PortNum);
  43. }
  44. break;
  45. case EDeviceType.SerialPort:
  46. break;
  47. case EDeviceType.Lebai:
  48. if (item.Device is ModbusTcp tcp)
  49. {
  50. LebaiHelper.GetInstance.Connect(tcp.IP);
  51. //开启机器人重连检测线程
  52. ThreadManage.GetInstance.StartLong(() => { LebaiHelper.GetInstance.Reconnect(tcp.IP); Task.Delay(5000); }, "机器人重连检测");
  53. }
  54. break;
  55. case EDeviceType.JAKA:
  56. if (item.Device is ModbusTcp jaka)
  57. {
  58. JaKaHelper.GetInstance.Connect(jaka.IP);
  59. }
  60. break;
  61. case EDeviceType.MCU:
  62. if (item.Device is SerialDeviceBase ser)
  63. {
  64. MCUSerialHelper.GetInstance.Open(ser.ComSerialPort, int.Parse(ser.BaudRate));
  65. }
  66. break;
  67. case EDeviceType.Juicer:
  68. if (item.Device is SerialDeviceBase Juicer)
  69. {
  70. JuicerHelper.GetInstance.Open(Juicer.ComSerialPort, int.Parse(Juicer.BaudRate));
  71. }
  72. break;
  73. default:
  74. break;
  75. }
  76. //}
  77. }
  78. }
  79. ActionManage.GetInstance.Send($"{GVL.GeneralConfig.DeviceType.ToString()}/ConnectOk");
  80. }
  81. }
  82. }