DataBlockInfoDataRequest.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using PlcSiemens.O;
  2. using PlcSiemens.Protocol.Common;
  3. namespace PlcSiemens.Protocol.ListBlocks
  4. {
  5. public class DataBlockInfoDataRequest
  6. {
  7. public byte Ret { get; set; }
  8. public byte Size { get; set; }
  9. public ushort DataLen { get; set; }
  10. public byte BlkPrfx { get; set; } // always 0x30
  11. public byte BlkType { get; set; }
  12. public byte[] AsciiBlk { get; set; } // BlockNum in ascii
  13. public byte A { get; set; }
  14. public ushort PacketLength
  15. { get { return (ushort)(7 + AsciiBlk.Length); } }
  16. public void Build(BlockType blockType, ushort db)
  17. {
  18. Ret = 0xFF;
  19. Size = (byte)TsType.TsResOctet;
  20. DataLen = 0x0008;
  21. BlkPrfx = 0x30;
  22. BlkType = (byte)blockType;
  23. AsciiBlk = new byte[5];
  24. AsciiBlk[0] = (byte)((db / 10000) + 0x30);
  25. db = (ushort)(db % 10000);
  26. AsciiBlk[1] = (byte)((db / 1000) + 0x30);
  27. db = (ushort)(db % 1000);
  28. AsciiBlk[2] = (byte)((db / 100) + 0x30);
  29. db = (ushort)(db % 100);
  30. AsciiBlk[3] = (byte)((db / 10) + 0x30);
  31. db = (ushort)(db % 10);
  32. AsciiBlk[4] = (byte)((db / 1) + 0x30);
  33. A = 0x41;
  34. }
  35. public void GetByteBuffer(ByteBuffer buffer)
  36. {
  37. buffer.Push(Ret);
  38. buffer.Push(Size);
  39. buffer.Push(DataLen);
  40. buffer.Push(BlkPrfx);
  41. buffer.Push(BlkType);
  42. buffer.Push(AsciiBlk);
  43. buffer.Push(A);
  44. }
  45. }
  46. }