DataBlockInfoDataRequest.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Core.Communication.Transport;
  2. using PLC.Siemens.Protocol.Common;
  3. namespace PLC.Siemens.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 { get { return (ushort)(7 + AsciiBlk.Length); } }
  15. public void Build(BlockType blockType, ushort db)
  16. {
  17. Ret = 0xFF;
  18. Size = (byte)TsType.TsResOctet;
  19. DataLen = 0x0008;
  20. BlkPrfx = 0x30;
  21. BlkType = (byte)blockType;
  22. AsciiBlk = new byte[5];
  23. AsciiBlk[0] = (byte)((db / 10000) + 0x30);
  24. db = (ushort)(db % 10000);
  25. AsciiBlk[1] = (byte)((db / 1000) + 0x30);
  26. db = (ushort)(db % 1000);
  27. AsciiBlk[2] = (byte)((db / 100) + 0x30);
  28. db = (ushort)(db % 100);
  29. AsciiBlk[3] = (byte)((db / 10) + 0x30);
  30. db = (ushort)(db % 10);
  31. AsciiBlk[4] = (byte)((db / 1) + 0x30);
  32. A = 0x41;
  33. }
  34. public void GetByteBuffer(ByteBuffer buffer)
  35. {
  36. buffer.Push(Ret);
  37. buffer.Push(Size);
  38. buffer.Push(DataLen);
  39. buffer.Push(BlkPrfx);
  40. buffer.Push(BlkType);
  41. buffer.Push(AsciiBlk);
  42. buffer.Push(A);
  43. }
  44. }
  45. }