MelsecQnA3EBinaryMessage.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace HslCommunication.Core.IMessage
  6. {
  7. /// <summary>
  8. /// 三菱的Qna兼容3E帧协议解析规则
  9. /// </summary>
  10. public class MelsecQnA3EBinaryMessage : INetMessage
  11. {
  12. /// <summary>
  13. /// 消息头的指令长度
  14. /// </summary>
  15. public int ProtocolHeadBytesLength
  16. {
  17. get
  18. {
  19. return 9;
  20. }
  21. }
  22. /// <summary>
  23. /// 从当前的头子节文件中提取出接下来需要接收的数据长度
  24. /// </summary>
  25. /// <returns>返回接下来的数据内容长度</returns>
  26. public int GetContentLengthByHeadBytes()
  27. {
  28. return BitConverter.ToUInt16( HeadBytes, 7 );
  29. }
  30. /// <summary>
  31. /// 检查头子节的合法性
  32. /// </summary>
  33. /// <param name="token">特殊的令牌,有些特殊消息的验证</param>
  34. /// <returns></returns>
  35. public bool CheckHeadBytesLegal( byte[] token )
  36. {
  37. if (HeadBytes[0] == 0xD0 && HeadBytes[1] == 0x00)
  38. {
  39. return true;
  40. }
  41. else
  42. {
  43. return false;
  44. }
  45. }
  46. /// <summary>
  47. /// 获取头子节里的消息标识
  48. /// </summary>
  49. /// <returns></returns>
  50. public int GetHeadBytesIdentity()
  51. {
  52. return 0;
  53. }
  54. /// <summary>
  55. /// 消息头字节
  56. /// </summary>
  57. public byte[] HeadBytes { get; set; }
  58. /// <summary>
  59. /// 消息内容字节
  60. /// </summary>
  61. public byte[] ContentBytes { get; set; }
  62. /// <summary>
  63. /// 发送的字节信息
  64. /// </summary>
  65. public byte[] SendBytes { get; set; }
  66. }
  67. }