DevicePlcS7.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using HslCommunication.Profinet.Siemens;
  2. using S7.Net;
  3. using System;
  4. namespace IMCS.CCS.DeviceProtocol
  5. {
  6. public class DevicePlcS7
  7. {
  8. public static Plc S7(string ip,string type)
  9. {
  10. Plc s7Plc = new Plc(CpuType.S71500, ip, 0, 1);
  11. if (type == "S7_1200")
  12. {
  13. s7Plc = new Plc(CpuType.S71200, ip, 0, 1);
  14. }
  15. else if (type == "S7_400")
  16. {
  17. s7Plc = new Plc(CpuType.S7400, ip, 0, 1);
  18. }
  19. else if (type == "S7_300")
  20. {
  21. s7Plc = new Plc(CpuType.S7300, ip, 0, 1);
  22. }
  23. s7Plc.Open();
  24. return s7Plc;
  25. }
  26. public static SiemensS7Net SiemensS7(string ip, int port = 102)
  27. {
  28. SiemensS7Net SiemensS7Net = new SiemensS7Net(SiemensPLCS.S1500, ip) {
  29. ConnectTimeOut = 10000
  30. };
  31. SiemensS7Net.ConnectionId = Guid.NewGuid().ToString();
  32. return SiemensS7Net;
  33. }
  34. }
  35. }