示例#1
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public DeviceSlice(DateTime timestamp, int tagCount, int dataLength)
 {
     Timestamp            = timestamp;
     DeviceTags           = new DeviceTag[tagCount];
     CnlData              = new CnlData[dataLength];
     DeviceNum            = 0;
     ArchiveMask          = Data.Models.ArchiveMask.Default;
     Descr                = "";
     DataSentCallback     = null;
     FailedToSendCallback = null;
 }
示例#2
0
 /// <summary>
 /// Gets or sets the data for the device tag at the specified code.
 /// </summary>
 public CnlData this[string tagCode]
 {
     get
     {
         DeviceTag deviceTag = deviceTags[tagCode];
         return(GetCnlData(deviceTag.Index, 0));
     }
     set
     {
         DeviceTag deviceTag = deviceTags[tagCode];
         SetCnlData(deviceTag.Index, 0, value);
     }
 }
示例#3
0
        /// <summary>
        /// Sets the date and time value and status of the tag.
        /// </summary>
        public void SetDateTime(int tagIndex, DateTime dateTime, int stat)
        {
            DeviceTag deviceTag = deviceTags[tagIndex];

            if (deviceTag.DataType == TagDataType.Int64)
            {
                SetInt64(tagIndex, dateTime.ToUniversalTime().Ticks, stat);
            }
            else if (deviceTag.DataType == TagDataType.Double)
            {
                Set(tagIndex, dateTime.ToUniversalTime().ToOADate(), stat);
            }
        }
示例#4
0
 /// <summary>
 /// Gets the data for the device tag at the specified index.
 /// </summary>
 private CnlData GetCnlData(int tagIndex, int offset)
 {
     if (rawData == null)
     {
         return(CnlData.Empty);
     }
     else
     {
         lock (curDataLock)
         {
             DeviceTag deviceTag = deviceTags[tagIndex];
             return(rawData[deviceTag.DataIndex + offset]);
         }
     }
 }
示例#5
0
        /// <summary>
        /// Sets the data for the device tag at the specified index.
        /// </summary>
        private void SetCnlData(int tagIndex, int offset, CnlData value)
        {
            if (rawData != null)
            {
                lock (curDataLock)
                {
                    DeviceTag deviceTag = deviceTags[tagIndex];

                    if (rawData[deviceTag.DataIndex + offset] != value)
                    {
                        modifiedFlags[tagIndex] = true;
                    }

                    rawData[deviceTag.DataIndex + offset] = value;
                }
            }
        }
示例#6
0
        /// <summary>
        /// Gets the date and time value of the tag.
        /// </summary>
        public DateTime GetDateTime(int tagIndex)
        {
            CnlData cnlData = this[tagIndex];

            if (cnlData.IsDefined)
            {
                DeviceTag deviceTag = deviceTags[tagIndex];

                if (deviceTag.DataType == TagDataType.Int64)
                {
                    return(new DateTime(BitConverter.DoubleToInt64Bits(cnlData.Val), DateTimeKind.Utc));
                }
                else if (deviceTag.DataType == TagDataType.Double)
                {
                    return(DateTime.FromOADate(cnlData.Val));
                }
            }

            return(DateTime.MinValue);
        }
示例#7
0
        /// <summary>
        /// Sets the specified tag to undefined.
        /// </summary>
        public void Invalidate(int tagIndex)
        {
            lock (curDataLock)
            {
                DeviceTag deviceTag = deviceTags[tagIndex];
                int       idx       = deviceTag.DataIndex;
                int       len       = deviceTag.DataLength;
                bool      modified  = false;

                for (int i = 0; i < len; i++)
                {
                    if (rawData[idx] != CnlData.Empty)
                    {
                        rawData[idx] = CnlData.Empty;
                        modified     = true;
                    }

                    idx++;
                }

                modifiedFlags[tagIndex] = modified;
            }
        }
示例#8
0
        /// <summary>
        /// Sets the specified tag to undefined.
        /// </summary>
        public void Invalidate(string tagCode)
        {
            DeviceTag deviceTag = deviceTags[tagCode];

            Invalidate(deviceTag.Index);
        }
示例#9
0
        /// <summary>
        /// Sets the array of bytes and status starting from the specified tag.
        /// </summary>
        public void SetByteArray(string tagCode, byte[] vals, int stat)
        {
            DeviceTag deviceTag = deviceTags[tagCode];

            SetByteArray(deviceTag.Index, vals, stat);
        }
示例#10
0
        /// <summary>
        /// Gets the Unicode string value of the tag.
        /// </summary>
        public string GetUnicode(string tagCode)
        {
            DeviceTag deviceTag = deviceTags[tagCode];

            return(GetUnicode(deviceTag.Index));
        }
示例#11
0
        /// <summary>
        /// Gets the ASCII string value of the tag.
        /// </summary>
        public string GetAscii(string tagCode)
        {
            DeviceTag deviceTag = deviceTags[tagCode];

            return(GetAscii(deviceTag.Index));
        }
示例#12
0
        /// <summary>
        /// Gets the array of bytes.
        /// </summary>
        public byte[] GetByteArray(string tagCode)
        {
            DeviceTag deviceTag = deviceTags[tagCode];

            return(GetByteArray(deviceTag.Index));
        }
示例#13
0
        /// <summary>
        /// Gets the date and time value of the tag.
        /// </summary>
        public DateTime GetDateTime(string tagCode)
        {
            DeviceTag deviceTag = deviceTags[tagCode];

            return(GetDateTime(deviceTag.Index));
        }
示例#14
0
        /// <summary>
        /// Converts the current tag data with a numeric data type to a string value.
        /// </summary>
        private string FormatNumericData(DeviceTag deviceTag, CnlData cnlData)
        {
            if (cnlData.IsUndefined)
            {
                return(CommonPhrases.UndefinedSign);
            }

            const string DefaultFormat = "N3";

            try
            {
                TagFormat tagFormat = deviceTag.Format;

                if (tagFormat == null)
                {
                    return(deviceTag.DataType == TagDataType.Int64 ?
                           BitConverter.DoubleToInt64Bits(cnlData.Val).ToString() :
                           cnlData.Val.ToString(DefaultFormat));
                }
                else
                {
                    string FormatEnum(int val)
                    {
                        return(tagFormat.EnumValues != null && 0 <= val && val < tagFormat.EnumValues.Length
                            ? tagFormat.EnumValues[val]
                            : val.ToString());
                    }

                    bool FormatIsHex(string format)
                    {
                        return(format[0] == 'x' || format[0] == 'X');
                    }

                    if (deviceTag.DataType == TagDataType.Int64)
                    {
                        long longVal = BitConverter.DoubleToInt64Bits(cnlData.Val);

                        switch (tagFormat.FormatType)
                        {
                        case TagFormatType.Enum:
                            return(FormatEnum((int)longVal));

                        case TagFormatType.Date:
                            DateTime dt = new DateTime(longVal, DateTimeKind.Utc).ToLocalTime();
                            return(string.IsNullOrEmpty(tagFormat.Format)
                                    ? dt.ToLocalizedString()
                                    : dt.ToString(tagFormat.Format));

                        default:
                            if (string.IsNullOrEmpty(tagFormat.Format))
                            {
                                return(longVal.ToString());
                            }
                            else
                            {
                                string s = longVal.ToString(tagFormat.Format);
                                return(FormatIsHex(tagFormat.Format) ? s + 'h' : s);
                            }
                        }
                    }
                    else
                    {
                        double doubleVal = cnlData.Val;

                        switch (tagFormat.FormatType)
                        {
                        case TagFormatType.Enum:
                            return(FormatEnum((int)doubleVal));

                        case TagFormatType.Date:
                            DateTime dt = DateTime.FromOADate(doubleVal).ToLocalTime();
                            return(string.IsNullOrEmpty(tagFormat.Format)
                                    ? dt.ToLocalizedString()
                                    : dt.ToString(tagFormat.Format));

                        default:
                            return(string.IsNullOrEmpty(tagFormat.Format)
                                    ? doubleVal.ToString(DefaultFormat)
                                    : FormatIsHex(tagFormat.Format)
                                        ? ((int)doubleVal).ToString(tagFormat.Format) + 'h'
                                        : doubleVal.ToString(tagFormat.Format));
                        }
                    }
                }
            }
            catch
            {
                return(cnlData.Val.ToString(DefaultFormat));
            }
        }
示例#15
0
        /// <summary>
        /// Sets the date and time value and status of the tag.
        /// </summary>
        public void SetDateTime(string tagCode, DateTime dateTime, int stat)
        {
            DeviceTag deviceTag = deviceTags[tagCode];

            SetDateTime(deviceTag.Index, dateTime, stat);
        }
示例#16
0
        /// <summary>
        /// Sets the Unicode string value and status of the tag.
        /// </summary>
        public void SetUnicode(string tagCode, string s, int stat)
        {
            DeviceTag deviceTag = deviceTags[tagCode];

            SetUnicode(deviceTag.Index, s, stat);
        }
示例#17
0
        /// <summary>
        /// Sets the specified tag range to undefined.
        /// </summary>
        public void Invalidate(string tagCode, int tagCount)
        {
            DeviceTag deviceTag = deviceTags[tagCode];

            Invalidate(deviceTag.Index, tagCount);
        }
示例#18
0
        /// <summary>
        /// Converts the current tag data with a numeric data type to a string value.
        /// </summary>
        private string FormatNumericData(DeviceTag deviceTag, CnlData cnlData)
        {
            if (cnlData.IsUndefined)
            {
                return(CommonPhrases.UndefinedSign);
            }

            const string DefaultFormat = "N3";

            try
            {
                TagFormat tagFormat = deviceTag.Format;

                if (tagFormat == null)
                {
                    return(deviceTag.DataType == TagDataType.Int64 ?
                           BitConverter.DoubleToInt64Bits(cnlData.Val).ToString() :
                           cnlData.Val.ToString(DefaultFormat));
                }
                else
                {
                    string FormatEnum(int val)
                    {
                        string[] enumValues = tagFormat.EnumValues;

                        if (enumValues == null)
                        {
                            return(val.ToString());
                        }
                        else if (val < 0)
                        {
                            return(enumValues[0]);
                        }
                        else if (val >= enumValues.Length)
                        {
                            return(enumValues[enumValues.Length - 1]);
                        }
                        else
                        {
                            return(enumValues[val]);
                        }
                    }

                    if (deviceTag.DataType == TagDataType.Int64)
                    {
                        long longVal = BitConverter.DoubleToInt64Bits(cnlData.Val);

                        switch (tagFormat.FormatType)
                        {
                        case TagFormatType.Enum:
                            return(FormatEnum((int)longVal));

                        case TagFormatType.Date:
                            DateTime dt = new DateTime(longVal, DateTimeKind.Utc).ToLocalTime();
                            return(string.IsNullOrEmpty(tagFormat.Format) ?
                                   dt.ToLocalizedString() : dt.ToString(tagFormat.Format));

                        default:
                            return(string.IsNullOrEmpty(tagFormat.Format) ?
                                   longVal.ToString() : longVal.ToString(tagFormat.Format));
                        }
                    }
                    else
                    {
                        double doubleVal = cnlData.Val;

                        switch (tagFormat.FormatType)
                        {
                        case TagFormatType.Enum:
                            return(FormatEnum((int)doubleVal));

                        case TagFormatType.Date:
                            DateTime dt = DateTime.FromOADate(doubleVal);
                            return(string.IsNullOrEmpty(tagFormat.Format) ?
                                   dt.ToLocalizedString() : dt.ToString(tagFormat.Format));

                        default:
                            return(string.IsNullOrEmpty(tagFormat.Format) ?
                                   doubleVal.ToString() : doubleVal.ToString(tagFormat.Format));
                        }
                    }
                }
            }
            catch
            {
                return(cnlData.Val.ToString(DefaultFormat));
            }
        }
示例#19
0
        /// <summary>
        /// Gets the array of floating point values.
        /// </summary>
        public double[] GetDoubleArray(string tagCode)
        {
            DeviceTag deviceTag = deviceTags[tagCode];

            return(GetDoubleArray(deviceTag.Index));
        }