DevicePlcS7.cs 1018 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using S7.Net;
  2. using System;
  3. using HslCommunication.Profinet.Siemens;
  4. namespace WCS.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.S1200, ip) { ConnectTimeOut = 5000 };
  29. SiemensS7Net.ConnectionId = Guid.NewGuid().ToString();
  30. return SiemensS7Net;
  31. }
  32. }
  33. }