MelsecQnA3EBinaryMessage.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace TFT_MelsecMcNet
  5. {
  6. /// <summary>
  7. /// 三菱的Qna兼容3E帧协议解析规则
  8. /// </summary>
  9. public class MelsecQnA3EBinaryMessage : INetMessage
  10. {
  11. /// <summary>
  12. /// 消息头的指令长度
  13. /// </summary>
  14. public int ProtocolHeadBytesLength
  15. {
  16. get
  17. {
  18. return 9;
  19. }
  20. }
  21. /// <summary>
  22. /// 从当前的头子节文件中提取出接下来需要接收的数据长度
  23. /// </summary>
  24. /// <returns>返回接下来的数据内容长度</returns>
  25. public int GetContentLengthByHeadBytes()
  26. {
  27. return BitConverter.ToUInt16(HeadBytes, 7);
  28. }
  29. /// <summary>
  30. /// 检查头子节的合法性
  31. /// </summary>
  32. /// <param name="token">特殊的令牌,有些特殊消息的验证</param>
  33. /// <returns>是否成功的结果</returns>
  34. public bool CheckHeadBytesLegal(byte[] token)
  35. {
  36. if (HeadBytes == null) return false;
  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. }