ModBusState.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using HslCommunication.Core;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Net.Sockets;
  7. using System.Text;
  8. namespace HslCommunication.ModBus
  9. {
  10. /// <summary>
  11. /// ModBus的异步状态信息
  12. /// </summary>
  13. internal class ModBusState
  14. {
  15. #region Constructor
  16. /// <summary>
  17. /// 实例化一个对象
  18. /// </summary>
  19. public ModBusState( )
  20. {
  21. hybirdLock = new SimpleHybirdLock( );
  22. ConnectTime = DateTime.Now;
  23. HeadByte = new byte[6];
  24. }
  25. #endregion
  26. /// <summary>
  27. /// 连接的时间
  28. /// </summary>
  29. public DateTime ConnectTime { get; private set; }
  30. /// <summary>
  31. /// 远端的地址
  32. /// </summary>
  33. public IPEndPoint IpEndPoint { get; internal set; }
  34. /// <summary>
  35. /// 远端的Ip地址
  36. /// </summary>
  37. public string IpAddress { get; internal set; }
  38. /// <summary>
  39. /// 工作套接字
  40. /// </summary>
  41. public Socket WorkSocket = null;
  42. /// <summary>
  43. /// 消息头的缓存
  44. /// </summary>
  45. public byte[] HeadByte = new byte[6];
  46. /// <summary>
  47. /// 消息头的接收长度
  48. /// </summary>
  49. public int HeadByteReceivedLength = 0;
  50. /// <summary>
  51. /// 内容数据缓存
  52. /// </summary>
  53. public byte[] Content = null;
  54. /// <summary>
  55. /// 内容数据接收长度
  56. /// </summary>
  57. public int ContentReceivedLength = 0;
  58. /// <summary>
  59. /// 回发信息的同步锁
  60. /// </summary>
  61. internal SimpleHybirdLock hybirdLock;
  62. /// <summary>
  63. /// 清除原先的接收状态
  64. /// </summary>
  65. public void Clear( )
  66. {
  67. Array.Clear( HeadByte, 0, 6 );
  68. HeadByteReceivedLength = 0;
  69. Content = null;
  70. ContentReceivedLength = 0;
  71. }
  72. }
  73. }