Exemplo n.º 1
0
        public static string SerializeValue(BacnetValue value, BacnetApplicationTags type)
        {
            switch (type)
            {
            case BacnetApplicationTags.BACNET_APPLICATION_TAG_NULL:
                return(value.ToString());                        // Modif FC

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_REAL:
                return(((float)value.Value).ToString(CultureInfo.InvariantCulture));

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_DOUBLE:
                return(((double)value.Value).ToString(CultureInfo.InvariantCulture));

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_OCTET_STRING:
                return(Convert.ToBase64String((byte[])value.Value));

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_CONTEXT_SPECIFIC_DECODED:
            {
                return(value.Value is byte[]? Convert.ToBase64String((byte[])value.Value)
                                                        : string.Join(";", ((BacnetValue[])value.Value)
                                                                      .Select(v => SerializeValue(v, v.Tag))));
            }

            default:
                return(value.Value.ToString());
            }
        }
Exemplo n.º 2
0
        public static string SerializeValue(BacnetValue value, BacnetApplicationTags type)
        {
            switch (type)
            {
            case BacnetApplicationTags.BACNET_APPLICATION_TAG_NULL:
                return(value.ToString());    // Modif FC

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_REAL:
                return(((float)value.Value).ToString(System.Globalization.CultureInfo.InvariantCulture));

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_DOUBLE:
                return(((double)value.Value).ToString(System.Globalization.CultureInfo.InvariantCulture));

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_OCTET_STRING:
                return(Convert.ToBase64String((byte[])value.Value));

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_CONTEXT_SPECIFIC_DECODED:
            {
                if (value.Value is byte[])
                {
                    return(Convert.ToBase64String((byte[])value.Value));
                }
                else
                {
                    string        ret = "";
                    BacnetValue[] arr = (BacnetValue[])value.Value;
                    foreach (BacnetValue v in arr)
                    {
                        ret += ";" + SerializeValue(v, v.Tag);
                    }
                    return(ret.Length > 0 ? ret.Substring(1) : "");
                }
            }

            default:
                return(value.Value.ToString());
            }
        }