private IEnumerable <T> ReadChannelData <T>(BinaryReader binReader, DATChannelDataTypes channelDataType, int bitSize, long startPosition, long valueCount) { binReader.BaseStream.Position = (bitSize / 8) * (long)(startPosition - 1); for (int i = 0; i < valueCount; i++) { switch (channelDataType) { case DATChannelDataTypes.INT16: yield return((T)Convert.ChangeType(binReader.ReadInt16(), typeof(T))); break; case DATChannelDataTypes.INT32: yield return((T)Convert.ChangeType(binReader.ReadInt32(), typeof(T))); break; case DATChannelDataTypes.REAL32: yield return((T)Convert.ChangeType(binReader.ReadSingle(), typeof(T))); break; case DATChannelDataTypes.REAL64: yield return((T)Convert.ChangeType(binReader.ReadDouble(), typeof(T))); break; default: throw new NotImplementedException(); } } }
/// <summary> /// returns the matching channel content type. /// returns <see cref="CommonChannelDataTypes.DIAdemFileSpecific"/> if no DIAdem common type is stored in this channel /// </summary> /// <param name="dataTypes">type to be mapped</param> /// <returns></returns> public static CommonChannelDataTypes ToCommonChannelDataType(this DATChannelDataTypes dataTypes) { switch (dataTypes) { case DATChannelDataTypes.INT16: return(CommonChannelDataTypes.Int16); case DATChannelDataTypes.INT32: return(CommonChannelDataTypes.Int32); case DATChannelDataTypes.REAL32: return(CommonChannelDataTypes.Single); case DATChannelDataTypes.REAL64: return(CommonChannelDataTypes.Double); case DATChannelDataTypes.WORD32: return(CommonChannelDataTypes.String); case DATChannelDataTypes.WORD16: return(CommonChannelDataTypes.String); default: return(CommonChannelDataTypes.DIAdemFileSpecific); } }
public static int GetBitSize(this DATChannelDataTypes dataType) { switch (dataType) { case DATChannelDataTypes.ASCII: return(8); case DATChannelDataTypes.INT16: return(16); case DATChannelDataTypes.INT32: return(32); case DATChannelDataTypes.MSREAL32: return(32); case DATChannelDataTypes.REAL32: return(32); case DATChannelDataTypes.REAL48: return(48); case DATChannelDataTypes.REAL64: return(64); case DATChannelDataTypes.TWOC12: return(12); case DATChannelDataTypes.TWOC16: return(16); case DATChannelDataTypes.WORD8: return(8); case DATChannelDataTypes.WORD16: return(16); case DATChannelDataTypes.WORD32: return(32); default: throw new NotImplementedException($"{nameof(DATChannelDataTypes)}-Enum Value {dataType} not supported."); } }