InovanceTcp.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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;
  9. using System.Threading.Tasks;
  10. namespace LogoForceTestApp.Modules.MainModule
  11. {
  12. public class InovanceTcp//汇川H5U
  13. {
  14. public InovanceTcpNet tcpNet;
  15. public bool Connection(string ip, int port)
  16. {
  17. tcpNet = new InovanceTcpNet(ip, port, 1);//ip,端口,站号
  18. //tcpNet.Station = 1;
  19. //tcpNet.AddressStartWithZero = true;
  20. //tcpNet.IsStringReverse = false;
  21. tcpNet.Series = HslCommunication.Profinet.Inovance.InovanceSeries.H5U;
  22. //tcpNet.DataFormat = HslCommunication.Core.DataFormat.CDAB;
  23. //tcpNet.Series = InovanceSeries.H5U;
  24. OperateResult connect = tcpNet.ConnectServer();
  25. if (connect.IsSuccess)
  26. {
  27. //连接成功
  28. return true;
  29. }
  30. else
  31. {
  32. return false;
  33. }
  34. }
  35. public void ConnectionClose()
  36. {
  37. tcpNet.ConnectClose();
  38. }
  39. public void WriteDate<T>(string address, T t)
  40. {
  41. dynamic temp = t;
  42. OperateResult result = tcpNet.Write(address, temp);//WriteDate("D200",10);WriteDate("W5.0",true);
  43. Thread.Sleep(500);
  44. }
  45. public bool[] Read(string add,ushort lenght=1)
  46. {
  47. bool[] obj = tcpNet.ReadBool(add, lenght).Content;
  48. return obj;
  49. }
  50. public bool ReadBool(string add)
  51. {
  52. var obj = tcpNet.ReadBool(add).Content;
  53. return obj;
  54. }
  55. public int ReadInt(string add)//short
  56. {
  57. var obj = tcpNet.ReadInt16(add).Content;
  58. return obj;
  59. }
  60. //public int ReadInt(string add)
  61. //{
  62. // var obj = tcpNet.ReadInt32(add).Content;
  63. // return obj;
  64. //}
  65. public void WriteInt(string add,int val)
  66. {
  67. tcpNet.Write(add, val);
  68. }
  69. public void WriteBool(string add, bool val)
  70. {
  71. tcpNet.Write(add, val);
  72. }
  73. }
  74. }