Ejemplo n.º 1
0
        public static ItemData <object> ReadValueEx(this IReaderWriter reader, DeviceAddress address)
        {
            switch (address.VarType)
            {
            case DataType.BOOL:
                var bit = reader.ReadBit(address);
                return(new ItemData <object>(bit.Value, bit.TimeStamp, bit.Quality));

            case DataType.BYTE:
                var bt = reader.ReadByte(address);
                return(new ItemData <object>(bt.Value, bt.TimeStamp, bt.Quality));

            case DataType.WORD:
            case DataType.SHORT:
                var sh = reader.ReadInt16(address);
                return(new ItemData <object>(sh.Value, sh.TimeStamp, sh.Quality));

            case DataType.TIME:
            case DataType.INT:
                var it = reader.ReadInt32(address);
                return(new ItemData <object>(it.Value, it.TimeStamp, it.Quality));

            case DataType.FLOAT:
                var fl = reader.ReadFloat(address);
                return(new ItemData <object>(fl.Value, fl.TimeStamp, fl.Quality));

            case DataType.STR:
                var str = reader.ReadString(address, address.DataSize);
                return(new ItemData <object>(str.Value, str.TimeStamp, str.Quality));
            }
            return(new ItemData <object>(null, 0, QUALITIES.QUALITY_BAD));
        }