InovanceTcp.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using HandyControl.Controls;
  2. using HslCommunication;
  3. using HslCommunication.Profinet.Inovance;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace LogoForceTestApp.Modules.MainModule
  10. {
  11. public class InovanceTcp//汇川H5U
  12. {
  13. public InovanceTcpNet tcpNet;
  14. public bool Connection(string ip, int port)
  15. {
  16. tcpNet = new InovanceTcpNet(ip, port, 1);//ip,端口,站号
  17. OperateResult connect = tcpNet.ConnectServer();
  18. if (connect.IsSuccess)
  19. {
  20. //连接成功
  21. return true;
  22. }
  23. else
  24. {
  25. return false;
  26. }
  27. }
  28. public void ConnectionClose()
  29. {
  30. tcpNet.ConnectClose();
  31. }
  32. public void WriteDate<T>(string address, T t)
  33. {
  34. dynamic temp = t;
  35. OperateResult result = tcpNet.Write(address, temp);//WriteDate("D200",10);WriteDate("W5.0",true);
  36. }
  37. public bool[] Read(string add,ushort lenght=1)
  38. {
  39. bool[] obj = tcpNet.ReadBool(add, lenght).Content;
  40. return obj;
  41. }
  42. public int ReadInteger(string add)
  43. {
  44. var obj = tcpNet.ReadInt32(add).Content;
  45. return obj;
  46. }
  47. }
  48. }