You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

57 lines
1.9 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. namespace HBLConsole.Communication
  9. {
  10. public class ConnectHelper
  11. {
  12. private volatile static ConnectHelper _Instance;
  13. public static ConnectHelper GetInstance => _Instance ?? (_Instance = new ConnectHelper());
  14. private ConnectHelper() { }
  15. public void Init()
  16. {
  17. Json<CommunicationPar>.Read();
  18. foreach (var item in Json<CommunicationPar>.Data.communicationSets)
  19. {
  20. if (item.ClientDeviceType == GVL.GeneralConfig.DeviceType.ToString())
  21. {
  22. if (item.IsActive)
  23. {
  24. switch (item.deviceType)
  25. {
  26. case EDeviceType.Siemens:
  27. break;
  28. case EDeviceType.ModbusRtu:
  29. break;
  30. case EDeviceType.ModbusTcp:
  31. if (item.Device is ModbusTcp modbus)
  32. {
  33. ModbusTcpHelper.GetInstance.ModbusTcpConnect(modbus.IP, modbus.PortNum);
  34. }
  35. break;
  36. case EDeviceType.SerialPort:
  37. break;
  38. case EDeviceType.Lebai:
  39. if (item.Device is ModbusTcp tcp)
  40. {
  41. LebaiHelper.GetInstance.Connect(tcp.IP);
  42. }
  43. break;
  44. default:
  45. break;
  46. }
  47. }
  48. }
  49. }
  50. }
  51. }
  52. }