MelsecQnA3EBinaryMessage.cs 2.0 KB

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