DataBlockInfoDataResponse.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Text;
  3. using PLC.Siemens.Protocol.Common;
  4. using ByteBuffer = Core.Communication.Transport.ByteBuffer;
  5. namespace PLC.Siemens.Protocol.ListBlocks
  6. {
  7. public class DataBlockInfoDataResponse
  8. {
  9. public byte Ret { get; set; }
  10. public byte Size { get; set; }
  11. public ushort Length { get; set; }
  12. public byte CstB { get; set; }
  13. public BlockType BlkType { get; set; }
  14. public ushort CstW1 { get; set; }
  15. public ushort CstW2 { get; set; }
  16. public ushort CstPp { get; set; }
  17. public byte Unknown1 { get; set; }
  18. public byte BlkFlags { get; set; }
  19. public BlockLangType BlkLang { get; set; }
  20. public SubBlockType SubBlkType { get; set; }
  21. public ushort BlkNumber { get; set; }
  22. public uint LenLoadMem { get; set; }
  23. public byte[] BlkSec { get; set; }//[4]
  24. //public uint CodeTimeMs { get; set; }
  25. //public ushort CodeTimeDy { get; set; }
  26. //public uint IntfTimeMs { get; set; }
  27. //public ushort IntfTimeDy { get; set; }
  28. public System.DateTime CodeDateTime { get; set; }
  29. public System.DateTime IntfDateTime { get; set; }
  30. public ushort SbbLen { get; set; }
  31. public ushort AddLen { get; set; }
  32. public ushort LocDataLen { get; set; }
  33. public ushort Mc7Len { get; set; }
  34. public string Author { get; set; }//[8]
  35. public string Family { get; set; }//[8]
  36. public string Header { get; set; }//[8]
  37. public byte Version { get; set; }
  38. public byte Unknown2 { get; set; }
  39. public ushort BlkChksum { get; set; }
  40. public byte[] Resvd1 { get; set; }//[4]
  41. public byte[] Resvd2 { get; set; }//[4]
  42. private BlockType GetBlockType(SubBlockType subBlockType)
  43. {
  44. switch (subBlockType)
  45. {
  46. case SubBlockType.OB: return BlockType.OB;
  47. case SubBlockType.DB: return BlockType.DB;
  48. case SubBlockType.SDB: return BlockType.SDB;
  49. case SubBlockType.FC: return BlockType.FC;
  50. case SubBlockType.SFC: return BlockType.SFC;
  51. case SubBlockType.FB: return BlockType.FB;
  52. case SubBlockType.SFB: return BlockType.SFB;
  53. default: return 0;
  54. };
  55. }
  56. public void Build(ByteBuffer buffer)
  57. {
  58. Ret = buffer.PopByte();
  59. Size = buffer.PopByte();
  60. Length = buffer.PopUshort();
  61. CstB = buffer.PopByte();
  62. BlkType = (BlockType)buffer.PopByte();
  63. CstW1 = buffer.PopUshort();
  64. CstW2 = buffer.PopUshort();
  65. CstPp = buffer.PopUshort();
  66. Unknown1 = buffer.PopByte();
  67. BlkFlags = buffer.PopByte();
  68. BlkLang = (BlockLangType)buffer.PopByte();
  69. SubBlkType = (SubBlockType)buffer.PopByte();
  70. BlkType = GetBlockType(SubBlkType);//根据SunblockType
  71. BlkNumber = buffer.PopUshort();
  72. LenLoadMem = buffer.PopUint();
  73. BlkSec = buffer.PopBytes(4);// { get; set; }//[4]
  74. var codeTimeMs = buffer.PopUint();//毫秒时间
  75. var codeTimeDy = buffer.PopUshort();//天数 开始时间1984/1/1
  76. var intfTimeMs = buffer.PopUint();//毫秒时间
  77. var intfTimeDy = buffer.PopUshort();//天数 开始时间1984/1/1
  78. System.DateTime date = new System.DateTime(1984, 1, 1);
  79. CodeDateTime = date.AddDays(codeTimeDy).AddMilliseconds(codeTimeMs);
  80. IntfDateTime = date.AddDays(intfTimeDy).AddMilliseconds(intfTimeMs);
  81. SbbLen = buffer.PopUshort();
  82. AddLen = buffer.PopUshort();
  83. LocDataLen = buffer.PopUshort();
  84. Mc7Len = buffer.PopUshort();
  85. var author = buffer.PopBytes(8);//{ get; set; }//[8]
  86. var family = buffer.PopBytes(8);//{ get; set; }//[8]
  87. var header = buffer.PopBytes(8);//{ get; set; }//[8]
  88. Author = Encoding.UTF8.GetString(author).TrimEnd('\0');
  89. Family = Encoding.UTF8.GetString(family).TrimEnd('\0');
  90. Header = Encoding.UTF8.GetString(header).TrimEnd('\0');
  91. Version = buffer.PopByte();
  92. Unknown2 = buffer.PopByte();
  93. BlkChksum = buffer.PopUshort();
  94. Resvd1 = buffer.PopBytes(4);//{ get; set; }//[4]
  95. Resvd2 = buffer.PopBytes(4);// { get; set; }//[4]
  96. }
  97. /// <summary>Returns a string that represents the current object.</summary>
  98. /// <returns>A string that represents the current object.</returns>
  99. //public override string ToString()
  100. //{
  101. // return $"Block Type : {BlkType}\r\n" +
  102. // $"Block Number : {BlkNumber}\r\n" +
  103. // $"Block Lang : {BlkLang}\r\n" +
  104. // $"Block Flags : {Convert.ToString(BlkFlags, 2).PadLeft(8,'0')}\r\n" +
  105. // $"MC7 Size : {Mc7Len}\r\n" +
  106. // $"Load Size : {LenLoadMem}\r\n" +
  107. // $"Local Data : {LocDataLen}\r\n" +
  108. // $"SBB Length : {SbbLen}\r\n" +
  109. // $"CheckSum : {BlkChksum.ToString("X4")}\r\n" +
  110. // $"Version : {(Version/16.0).ToString("F1")}\r\n" +
  111. // $"Code Date : {CodeDateTime}\r\n" +
  112. // $"Intf.Date : {IntfDateTime}\r\n" +
  113. // $"Author : {Author}\r\n" +
  114. // $"Family : {Family}\r\n" +
  115. // $"Header : {Header}";
  116. //}
  117. }
  118. }