ParamsRequest.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using PlcSiemens.O;
  2. using PlcSiemens.Protocol.Common;
  3. namespace PlcSiemens.Protocol
  4. {
  5. /// <summary>
  6. /// 请求数据包参数
  7. /// </summary>
  8. public class ParamsRequest
  9. {
  10. public byte[] Head { get; set; }// 0x00 0x01 0x12
  11. public byte PLen { get; set; } // par len 0x04
  12. public byte Uk { get; set; } // unknown
  13. public byte Tg { get; set; } // type and group (4 bits type and 4 bits group)
  14. public byte SubFun { get; set; } // subfunction
  15. public byte Seq { get; set; } // sequence
  16. public ushort Rsvd { get; set; }//Next所需的参数
  17. public ushort ErrNo { get; set; }//Next所需的参数
  18. public bool First = true;
  19. public ushort PacketLength
  20. {
  21. get { return First ? (ushort)0x08 : (ushort)0x0C; }
  22. }
  23. public ParamsRequest()
  24. {
  25. Head = new byte[3];
  26. }
  27. public virtual void GetByteBuffer(ByteBuffer buffer)
  28. {
  29. buffer.Push(Head);
  30. buffer.Push(PLen);
  31. buffer.Push(Uk);
  32. buffer.Push(Tg);
  33. buffer.Push(SubFun);
  34. buffer.Push(Seq);
  35. if (First) return;
  36. buffer.Push(Rsvd);
  37. buffer.Push(ErrNo);
  38. }
  39. public void Build(bool first, byte seq, GrType grType, PduFuncType pduFuncType)
  40. {
  41. First = first;
  42. Head = new byte[] { 0x00, 0x01, 0x12 };
  43. PLen = first ? (byte)0x04 : (byte)0x08;
  44. Uk = 0x11;//用处未知 有时会有0x11
  45. Tg = (byte)grType;
  46. SubFun = (byte)pduFuncType;
  47. Seq = seq;
  48. if (first) return;
  49. Rsvd = 0x0000;
  50. ErrNo = 0x0000;
  51. }
  52. }
  53. }