DevicePlcS7.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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.S1200, ip) { ConnectTimeOut = 5000 };
  29. SiemensS7Net.ConnectionId = Guid.NewGuid().ToString();
  30. return SiemensS7Net;
  31. }
  32. }
  33. }