Exemple #1
0
        // 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} }}");
        }
Exemple #3
0
        // Converts the value of the element to a hexadecimal representation.
        public static string ValueAsHex(this VectorElement element)
        {
            byte[] values = element.GetValues();

            string hex = BitConverter
                         .ToString(values)
                         .Replace("-", "");

            return($"0x{hex}");
        }
 // Converts the value of the element to a hexadecimal representation.
 public static string ValueAsHex(this VectorElement element)
 {
     return("0x" + BitConverter.ToString(element.GetValues()).Replace("-", ""));
 }