public static bool GetValue(byte type, ref byte[] buffer, ref int offset, out object value) { value = null; switch (type) { case BOOLEAN_TYPE: { if (buffer.Length >= offset + sizeof(bool)) { bool tempVal = Convert.ToBoolean(buffer[offset]); value = tempVal; offset += sizeof(bool); } } break; case CHAR_STRING_TYPE: { if (buffer.Length >= offset + sizeof(byte)) { int length = Convert.ToInt32(buffer[offset]); if (length != 0 && buffer.Length >= (offset + (length + 1) * sizeof(byte))) { offset += sizeof(byte); String tempVal = Encoding.UTF8.GetString(buffer, offset, length); value = tempVal; offset += (length + 1) * sizeof(byte); } } } break; case INT8_TYPE: { if (buffer.Length >= offset + sizeof(sbyte)) { sbyte tempVal = (sbyte)buffer[offset]; value = tempVal; offset += sizeof(sbyte); } } break; case ENUMERATION_8_BIT_TYPE: // expected fall through case BITMAP_8_BIT_TYPE: // expected fall through case UINT8_TYPE: { if (buffer.Length >= offset + sizeof(byte)) { byte tempVal = buffer[offset]; value = tempVal; offset += sizeof(byte); } } break; case INT16_TYPE: { if (buffer.Length >= offset + sizeof(Int16)) { value = AdapterHelper.Int16FromZigBeeFrame(buffer, offset); offset += sizeof(Int16); } } break; case ENUMERATION_16_BIT_TYPE: // expected fall through case BITMAP_16_BIT_TYPE: // expected fall through case UINT16_TYPE: { if (buffer.Length >= offset + sizeof(UInt16)) { value = AdapterHelper.UInt16FromZigBeeFrame(buffer, offset); offset += sizeof(UInt16); } } break; case INT32_TYPE: { if (buffer.Length >= offset + sizeof(Int32)) { value = AdapterHelper.Int32FromZigBeeFrame(buffer, offset); offset += sizeof(Int32); } } break; case UINT32_TYPE: { if (buffer.Length >= offset + sizeof(UInt32)) { value = AdapterHelper.UInt32FromZigBeeFrame(buffer, offset); offset += sizeof(UInt32); } } break; case IEEE_ADDRESS_TYPE: { if (buffer.Length >= offset + sizeof(UInt64)) { value = AdapterHelper.UInt64FromZigBeeFrame(buffer, offset); offset += sizeof(UInt64); } } break; } if (value != null) { return(true); } else { return(false); } }