/// <summary> /// Gets the original data values by expanding /// sequences and applying scale and offset. /// </summary> /// <returns>A list of the original data values.</returns> private IList <object> GetOriginalValues() { IList <object> values = new List <object>(); VectorElement valuesVector = SeriesValues; StorageMethods storageMethods = Definition.StorageMethodID; bool incremented = (storageMethods & StorageMethods.Increment) != 0; dynamic start, count, increment; bool scaled = (storageMethods & StorageMethods.Scaled) != 0; dynamic offset = ((object)SeriesOffset != null) ? SeriesOffset.Get() : 0; dynamic scale = ((object)SeriesScale != null) ? SeriesScale.Get() : 1; dynamic value; if (!scaled) { offset = 0; scale = 1; } if (incremented) { start = valuesVector.Get(0); count = valuesVector.Get(1); increment = valuesVector.Get(2); for (int i = 0; i < count; i++) { values.Add((object)(start + (i * increment))); } } else { for (int i = 0; i < valuesVector.Size; i++) { values.Add(valuesVector.Get(i)); } } if (valuesVector.TypeOfValue != PhysicalType.Timestamp) { for (int i = 0; i < values.Count; i++) { value = values[i]; values[i] = offset + (value * scale); } ApplyTransducerRatio(values); } return(values); }
// Converts the value of the element to a string representation. public static string ValueAsString(this VectorElement element) { // The physical types Char1 and Char2 indicate the value is a string if (element.TypeOfValue == PhysicalType.Char1) { return(Encoding.ASCII.GetString(element.GetValues()).Trim((char)0)); } if (element.TypeOfValue == PhysicalType.Char2) { return(Encoding.Unicode.GetString(element.GetValues()).Trim((char)0)); } // Get the tag definition of the element being displayed Tag?tag = Tag.GetTag(element.TagOfElement); // Determine the format in which to display the values // based on the tag definition and the type of the value Func <int, string> formatter = element.TypeOfValue switch { PhysicalType.Complex8 => index => ((Complex)element.Get(index)).ToComplexNotation(), PhysicalType.Complex16 => index => ((Complex)element.Get(index)).ToComplexNotation(), PhysicalType.Timestamp => index => { string format = tag?.FormatString ?? "{0:yyyy-MM-dd HH:mm:ss.fffffff}"; object value = element.Get(index); return(string.Format(format, value)); }, _ => index => { string format = tag?.FormatString ?? "{0}"; object value = element.Get(index); return(string.Format(format, value)); } }; // Convert the values to their string representations IEnumerable <string> values = Enumerable .Range(0, element.Size) .Select(formatter); // Join the values in the collection // to a single, comma-separated string string join = string.Join(", ", values); // Wrap the string in curly braces and return return($"{{ {join} }}"); }
// Converts the value of the element to a string representation. public static string ValueAsString(this VectorElement element) { Tag tag; IEnumerable <string> values; string format; string join; // The physical types Char1 and Char2 indicate the value is a string if (element.TypeOfValue == PhysicalType.Char1) { return(Encoding.ASCII.GetString(element.GetValues()).Trim((char)0)); } if (element.TypeOfValue == PhysicalType.Char2) { return(Encoding.Unicode.GetString(element.GetValues()).Trim((char)0)); } // Get the tag definition of the element being displayed tag = Tag.GetTag(element.TagOfElement); // Determine the format in which to display the values // based on the tag definition and the type of the value if (element.TypeOfValue == PhysicalType.Timestamp) { format = tag.FormatString ?? "{0:yyyy-MM-dd HH:mm:ss.fffffff}"; } else { format = tag.FormatString ?? "{0}"; } // Convert the values to their string representations values = Enumerable.Range(0, element.Size) .Select(index => string.Format(format, element.Get(index))); // Join the values in the collection // to a single, comma-separated string join = string.Join(", ", values); // Wrap the string in curly braces and return return($"{{ {join} }}"); }
/// <summary> /// Gets the original data values by expanding /// sequences and applying scale and offset. /// </summary> /// <returns>A list of the original data values.</returns> private IList <object> GetOriginalValues() { IList <object> values = new List <object>(); VectorElement valuesVector = SeriesValues; StorageMethods storageMethods = Definition.StorageMethodID; bool incremented = (storageMethods & StorageMethods.Increment) != 0; bool scaled = (storageMethods & StorageMethods.Scaled) != 0; dynamic offset = SeriesOffset != null?SeriesOffset.Get() : 0; dynamic scale = SeriesScale != null?SeriesScale.Get() : 1; dynamic value; if (!scaled) { offset = 0; scale = 1; } if (incremented) { dynamic rateCount = valuesVector.Get(0); if (rateCount > 0) { dynamic zero = rateCount - rateCount; dynamic one = rateCount / rateCount; dynamic start = zero; for (int i = 0; i < rateCount; i++) { int countIndex = i * 2 + 1; int incrementIndex = i * 2 + 2; dynamic count = valuesVector.Get(countIndex); dynamic increment = valuesVector.Get(incrementIndex); for (dynamic j = zero; j < count; j += one) { values.Add((object)(start + j * increment)); } start = count * increment; } } } else { for (int i = 0; i < valuesVector.Size; i++) { values.Add(valuesVector.Get(i)); } } if (valuesVector.TypeOfValue != PhysicalType.Timestamp) { for (int i = 0; i < values.Count; i++) { value = values[i]; values[i] = offset + value * scale; } ApplyTransducerRatio(values); } return(values); }