public static int GetWriteRequest(UnmanagedMemoryStream s, long memOffset, ref  Value value, ref WORD quality, ref FILETIME timeStamp)
        {
            if (GetRegisterWriteOffset(s, memOffset) == 0)
            {
                return TagData.SMRC_NO_DATA;
            }

            int nRC = GetWriteRequestData(s, memOffset + GetRegisterWriteOffset(s, memOffset), ref value, ref quality, ref timeStamp);
            SetDataRequestPending(s, memOffset + GetRegisterWriteOffset(s, memOffset), false);
            return (nRC);
        }
        public static int GetWriteRequestData(UnmanagedMemoryStream s, long memOffset, ref Value value, ref WORD quality, ref FILETIME timeStamp)
        {
            VALTYPE tType = GetDataValueType(s, memOffset);
            if (!Value.IsValidValueType(tType))
            {
                return (TagData.SMRC_BAD_VALTYPE);
            }

            quality = Register.GetDataQuality(s, memOffset);
            timeStamp = Register.GetDataTimestamp(s, memOffset + DATA_VALUE_OFFSET);
            GetDataValue(s, memOffset, ref value);
            return (TagData.SMRC_NO_ERROR);
        }
        public static void GetDataValue(UnmanagedMemoryStream s, long memOffset, ref Value value)
        {
            BinaryReader r = new BinaryReader(s);

            VALTYPE vType = value.GetValueType();
            if (((vType & Value.T_ARRAY) == Value.T_ARRAY) && ((vType & ~Value.T_ARRAY) != Value.T_STRING))//array, not string array
            {
                r.BaseStream.Seek(memOffset + DATA_VALUE_OFFSET + VALUE_EXTARRAY_OFFSET, SeekOrigin.Begin);
            }
            else if (vType == (Value.T_ARRAY | Value.T_STRING)) //string array
            {
                r.BaseStream.Seek(memOffset + DATA_VALUE_OFFSET + VALUE_EXTARRAY_OFFSET + STRINGARRAY_ABDATA_OFFSET, SeekOrigin.Begin);
            }
            else if (vType == Value.T_STRING) //string
            {
                r.BaseStream.Seek(memOffset + DATA_VALUE_OFFSET + VALUE_EXTARRAY_OFFSET, SeekOrigin.Begin);
            }
            else
            {
                r.BaseStream.Seek(memOffset + DATA_VALUE_OFFSET + VALUE_8BYTEVAL_OFFSET, SeekOrigin.Begin);
            }

            if (value.valueExtSize > 0)
            {
                r.Read(value.valueExtByteArray, 0, value.valueExtByteArray.Length);
            }
            else
            {
                r.Read(value.value8ByteArray, 0, value.value8ByteArray.Length);
            }
            value.SetValueFromArray();
        }
 public TagData(VALTYPE vType, WORD stringSize, int rows, int cols)
 {
     value = new Value(vType, stringSize, rows, cols);
     CID.GetFtNow(ref timeStamp);
 }
        public static int SetReadResponseData(UnmanagedMemoryStream s, long memOffset, Value value, bool error, DWORD errorCode, WORD quality, FILETIME timeStamp)
        {
            VALTYPE tType = GetDataValueType(s, memOffset);
            if (!Value.IsValidValueType(tType))
            {
                return (TagData.SMRC_BAD_VALTYPE);
            }
            if (error)
            {
                SetDataError(s, memOffset, errorCode, true);
            }
            else
            {
                SetDataError(s, memOffset, errorCode, false);
            }

            SetDataQuality(s, memOffset, quality);
            SetDataTimestamp(s, memOffset, timeStamp);
            SetDataValue(s, memOffset, value);

            return (TagData.SMRC_NO_ERROR);
        }
 public static void SetReadResponse(UnmanagedMemoryStream s, long memOffset, Value value, bool error, DWORD errorCode, WORD quality, FILETIME timeStamp)
 {
     if (GetRegisterReadOffset(s, memOffset) != 0)
     {
         SetReadResponseData(s, memOffset + GetRegisterReadOffset(s, memOffset), value, error, errorCode, quality, timeStamp);
     }
     SetDataResponsePending(s, memOffset + GetRegisterReadOffset(s, memOffset), true);
 }
        public static int SetDataValue(UnmanagedMemoryStream s, long memOffset, Value value)
        {
            BinaryWriter w = new BinaryWriter(s);

            VALTYPE vType = value.GetValueType();
            if (((vType & Value.T_ARRAY) == Value.T_ARRAY) && ((vType & ~Value.T_ARRAY) != Value.T_STRING))//array, not string array
            {
                w.BaseStream.Seek(memOffset + DATA_VALUE_OFFSET + VALUE_EXTARRAY_OFFSET, SeekOrigin.Begin);
            }
            else if (vType == (Value.T_ARRAY | Value.T_STRING)) //string array
            {
                w.BaseStream.Seek(memOffset + DATA_VALUE_OFFSET + VALUE_EXTARRAY_OFFSET + STRINGARRAY_ABDATA_OFFSET, SeekOrigin.Begin);
            }
            else if (vType == Value.T_STRING) //string
            {
                w.BaseStream.Seek(memOffset + DATA_VALUE_OFFSET + VALUE_EXTARRAY_OFFSET, SeekOrigin.Begin);
            }
            else
            {
                w.BaseStream.Seek(memOffset + DATA_VALUE_OFFSET + VALUE_8BYTEVAL_OFFSET, SeekOrigin.Begin);
            }
            byte[] aToWrite = value.GetArrayFromValue();
            w.Write(aToWrite);
            w.Flush();
            return (TagData.SMRC_NO_ERROR);
        }