public object GetDataFromDataBytes(byte[] bytes, ushort[,] prevFrame, int size, int startIndex) { var rv = new AdvStatusData(); if (size > 0) { byte tagValuesCount = bytes[startIndex]; startIndex++; for (int i = 0; i < tagValuesCount; i++) { int tagId = bytes[startIndex]; AdvTagDefinition tagDef = m_TagDefinitions[tagId]; if (tagDef.Type == AdvTagType.UInt8) { byte value = bytes[startIndex + 1]; rv.TagValues[tagDef] = value.ToString(); startIndex += 2; } else if (tagDef.Type == AdvTagType.UInt16) { byte b1 = bytes[startIndex + 1]; byte b2 = bytes[startIndex + 2]; ushort value = (ushort)((b2 << 8) + b1); rv.TagValues[tagDef] = value.ToString(); startIndex += 3; } else if (tagDef.Type == AdvTagType.UInt32) { byte b1 = bytes[startIndex + 1]; byte b2 = bytes[startIndex + 2]; byte b3 = bytes[startIndex + 3]; byte b4 = bytes[startIndex + 4]; uint value = (uint)((b4 << 24) + (b3 << 16) + (b2 << 8) + b1); rv.TagValues[tagDef] = value.ToString(); startIndex += 5; } else if (tagDef.Type == AdvTagType.Real) { byte b1 = bytes[startIndex + 1]; byte b2 = bytes[startIndex + 2]; byte b3 = bytes[startIndex + 3]; byte b4 = bytes[startIndex + 4]; uint value = (uint)((b4 << 24) + (b3 << 16) + (b2 << 8) + b1); IntToFloatStruct converter = new IntToFloatStruct(); converter.UInt32Value = value; float realValue = converter.RealValue; rv.TagValues[tagDef] = realValue.ToString(); startIndex += 5; } else if (tagDef.Type == AdvTagType.ULong64) { byte b1 = bytes[startIndex + 1]; byte b2 = bytes[startIndex + 2]; byte b3 = bytes[startIndex + 3]; byte b4 = bytes[startIndex + 4]; byte b5 = bytes[startIndex + 5]; byte b6 = bytes[startIndex + 6]; byte b7 = bytes[startIndex + 7]; byte b8 = bytes[startIndex + 8]; uint valLo = (uint)((b4 << 24) + (b3 << 16) + (b2 << 8) + b1); uint valHi = (uint)((b8 << 24) + (b7 << 16) + (b6 << 8) + b5); long value = (((long)valHi) << 32) + (long)valLo; rv.TagValues[tagDef] = value.ToString(); startIndex += 9; } else if (tagDef.Type == AdvTagType.AnsiString254) { byte len = bytes[startIndex + 1]; byte[] tagValuebytes = new byte[len]; Array.Copy(bytes, startIndex + 2, tagValuebytes, 0, len); rv.TagValues[tagDef] = Encoding.ASCII.GetString(tagValuebytes); startIndex += 2 + len; } else if (tagDef.Type == AdvTagType.List16AnsiString254) { StringBuilder bld = new StringBuilder(); byte count = bytes[startIndex + 1]; startIndex += 2; for (int j = 0; j < count; j++) { byte len = bytes[startIndex]; byte[] tagValuebytes = new byte[len]; Array.Copy(bytes, startIndex + 1, tagValuebytes, 0, len); bld.AppendLine(Encoding.ASCII.GetString(tagValuebytes)); startIndex += 1 + len; } rv.TagValues[tagDef] = bld.ToString(); } } } return(rv); }
public object GetDataFromDataBytes(byte[] bytes, ushort[,] prevFrame, int size, int startIndex) { var rv = new AdvStatusData(); if (size > 0) { byte tagValuesCount = bytes[startIndex]; startIndex++; for (int i = 0; i < tagValuesCount; i++) { int tagId = bytes[startIndex]; AdvTagDefinition tagDef = m_TagDefinitions[tagId]; if (tagDef.Type == AdvTagType.UInt8) { byte value = bytes[startIndex + 1]; rv.TagValues[tagDef] = value.ToString(); startIndex += 2; } else if (tagDef.Type == AdvTagType.UInt16) { byte b1 = bytes[startIndex + 1]; byte b2 = bytes[startIndex + 2]; ushort value = (ushort)((b2 << 8) + b1); rv.TagValues[tagDef] = value.ToString(); startIndex += 3; } else if (tagDef.Type == AdvTagType.UInt32) { byte b1 = bytes[startIndex + 1]; byte b2 = bytes[startIndex + 2]; byte b3 = bytes[startIndex + 3]; byte b4 = bytes[startIndex + 4]; uint value = (uint)((b4 << 24) + (b3 << 16) + (b2 << 8) + b1); rv.TagValues[tagDef] = value.ToString(); startIndex += 5; } else if (tagDef.Type == AdvTagType.Real) { byte b1 = bytes[startIndex + 1]; byte b2 = bytes[startIndex + 2]; byte b3 = bytes[startIndex + 3]; byte b4 = bytes[startIndex + 4]; uint value = (uint)((b4 << 24) + (b3 << 16) + (b2 << 8) + b1); IntToFloatStruct converter = new IntToFloatStruct(); converter.UInt32Value = value; float realValue = converter.RealValue; rv.TagValues[tagDef] = realValue.ToString(); startIndex += 5; } else if (tagDef.Type == AdvTagType.ULong64) { byte b1 = bytes[startIndex + 1]; byte b2 = bytes[startIndex + 2]; byte b3 = bytes[startIndex + 3]; byte b4 = bytes[startIndex + 4]; byte b5 = bytes[startIndex + 5]; byte b6 = bytes[startIndex + 6]; byte b7 = bytes[startIndex + 7]; byte b8 = bytes[startIndex + 8]; uint valLo = (uint)((b4 << 24) + (b3 << 16) + (b2 << 8) + b1); uint valHi = (uint)((b8 << 24) + (b7 << 16) + (b6 << 8) + b5); long value = (((long)valHi) << 32) + (long)valLo; rv.TagValues[tagDef] = value.ToString(); startIndex += 9; } else if (tagDef.Type == AdvTagType.AnsiString254) { byte len = bytes[startIndex + 1]; byte[] tagValuebytes = new byte[len]; Array.Copy(bytes, startIndex + 2, tagValuebytes, 0, len); rv.TagValues[tagDef] = Encoding.ASCII.GetString(tagValuebytes); startIndex += 2 + len; } else if (tagDef.Type == AdvTagType.List16AnsiString254) { StringBuilder bld = new StringBuilder(); byte count = bytes[startIndex + 1]; startIndex += 2; for (int j = 0; j < count; j++) { byte len = bytes[startIndex]; byte[] tagValuebytes = new byte[len]; Array.Copy(bytes, startIndex + 1, tagValuebytes, 0, len); bld.AppendLine(Encoding.ASCII.GetString(tagValuebytes)); startIndex += 1 + len; } rv.TagValues[tagDef] = bld.ToString(); } } } return rv; }