ReadItemResponse.cs 912 B

12345678910111213141516171819202122232425262728
  1. using PlcSiemens.O;
  2. using PlcSiemens.Protocol.Common;
  3. namespace PlcSiemens.Protocol.ReadData
  4. {
  5. public class ReadItemResponse
  6. {
  7. public byte ReturnCode { get; set; }
  8. public byte TransportSize { get; set; }
  9. public ushort DataLength { get; set; }
  10. public byte[] Data { get; set; }
  11. public void Build(ByteBuffer buffer)
  12. {
  13. ReturnCode = buffer.PopByte();
  14. TransportSize = buffer.PopByte();
  15. DataLength = buffer.PopUshort();
  16. if (TransportSize != (byte)TsType.TsResOctet && TransportSize != (byte)TsType.TsResReal &&
  17. TransportSize != (byte)TsType.TsResBit)
  18. DataLength = (ushort)(DataLength >> 3);
  19. Data = buffer.PopBytes(DataLength);
  20. //如果读取数量为奇数则取出一条填充字节
  21. if (Data.Length % 2 != 0)
  22. buffer.PopByte();
  23. }
  24. }
  25. }