/// <summary>
 /// 构造TLV结构
 /// </summary>
 /// <param name="_tag">标签</param>
 /// <param name="_format">类型</param>
 /// <param name="_len">长度</param>
 /// <param name="_tag_buf">值</param>
 public TagStruct(TagName _tag, TagFormat _format, uint _len, string _tag_buf)
 {
     tag     = _tag;
     format  = _format;
     len     = _len;
     tag_buf = _tag_buf;
 }
Пример #2
0
 /// <summary>
 /// Converts the array element value received from the OPC server to a double.
 /// </summary>
 private double ConvertArrayElem(object val, out TagFormat tagFormat)
 {
     try
     {
         if (val is string strVal)
         {
             // string arrays not supported
             tagFormat = TagFormat.FloatNumber;
             return(0.0);
         }
         else if (val is DateTime dtVal)
         {
             tagFormat = TagFormat.DateTime;
             return(dtVal.ToOADate());
         }
         else
         {
             tagFormat = TagFormat.FloatNumber;
             return(Convert.ToDouble(val));
         }
     }
     catch (Exception ex)
     {
         Log.WriteInfo(ex.BuildErrorMessage(Locale.IsRussian ?
                                            "Ошибка при конвертировании элемента массива" :
                                            "Error converting array element"));
         tagFormat = TagFormat.FloatNumber;
         return(0.0);
     }
 }
        public static string GetFormatString(string value, TagFormat format, string specialFormat)
        {
            switch (format)
            {
            case TagFormat.U:
                return(value.Trim().ToUpper());

            case TagFormat.CC:
                return(value);

            case TagFormat.PN:
                return(PersonHelper.NameFix(value));

            case TagFormat.PA:
                return(PersonHelper.AddressFix(value));

            case TagFormat.T1:
                return(TimeFormater.GetFormat_T1(value));

            case TagFormat.T2:
                return(TimeFormater.GetFormat_T2(value));

            case TagFormat.T3:
                return(TimeFormater.GetFormat_T3(value));

            case TagFormat.TX:
                return(TimeFormater.GetFormat_TX(value, specialFormat));

            default:
                return(value);
            }
        }
 public TagStruct(TagName _tag, TagFormat _format, uint _len, byte[] _tag_buf)
 {
     tag          = _tag;
     format       = _format;
     len          = _len;
     this.tag_buf = new byte[len];
     tag_buf      = _tag_buf;
 }
Пример #5
0
 /// <summary>
 /// 构造TLV结构
 /// </summary>
 /// <param name="tag">标签</param>
 /// <param name="len">长度</param>
 /// <param name="val">值</param>
 public TLV_Structure(TagName tag, TagFormat format, uint len, byte[] val)
 {
     this.m_Tag          = tag;
     this.m_TagFormat    = format;
     this.m_uiValueLen   = len;
     this.m_bValueBuffer = new byte[this.m_uiValueLen];
     this.init(len, val);
 }
Пример #6
0
    private TagFormat GetCurrentTagFormat(string word)
    {
        TagFormat t    = new TagFormat();
        int       step = 0;

        for (int i = 0; i < word.Length; i++)
        {
            char ch = word[i];

            if (ch == '$' && step == 0 && AutomataManager.automataType == AutomataType.DPDA)
            {
                t.input = ch;
                step++;
                continue;
            }

            if (step < 2 && ch == '□' && AutomataManager.automataType == AutomataType.Turing)
            {
                if (step == 0)
                {
                    t.input = ch;
                }
                if (step == 1)
                {
                    t.machine = ch;
                }
                step++;
                continue;
            }

            if (!char.IsLetterOrDigit(ch))
            {
                continue;
            }

            if (step == 0)
            {
                t.input = ch;
            }

            if (step == 1)
            {
                t.machine = ch;
            }

            if (step > 1)
            {
                t.machineCommand += ch;
            }

            step++;
        }
        return(t);
    }
Пример #7
0
 private static void PushToStack(Stack <char> _stack, TagFormat t)
 {
     for (int j = t.machineCommand.Length - 1; j >= 0; j--)
     {
         if (t.machineCommand[j] == 'λ')
         {
             break;
         }
         _stack.Push(t.machineCommand[j]);
     }
 }
        public void AddTagKey(TagName tag, TagFormat style, uint len, byte[] val)
        {
            int i = 0;

            for (i = 0; i < structLen; i++)
            {
                if (null == m_tagList[i])
                {
                    break;
                }
            }
            m_tagList[i] = new TagStruct(tag, style, len, val);
        }
Пример #9
0
        /// <summary>
        /// Processes new data.
        /// </summary>
        private void ProcessDataChanges(SubscriptionTag subscriptionTag, NotificationMessage notificationMessage)
        {
            foreach (MonitoredItemNotification change in notificationMessage.GetDataChanges(false))
            {
                if (subscriptionTag.Subscription.FindItemByClientHandle(change.ClientHandle) is
                    MonitoredItem monitoredItem)
                {
                    if (subscriptionTag.ItemsByNodeID.TryGetValue(monitoredItem.StartNodeId.ToString(),
                                                                  out ItemTag itemTag))
                    {
                        Log.WriteLine("{0} {1} = {2} ({3})", CommPhrases.ReceiveNotation,
                                      monitoredItem.DisplayName, change.Value, change.Value.StatusCode);

                        int tagIndex  = itemTag.DeviceTag.Index;
                        int tagStatus = StatusCode.IsGood(change.Value.StatusCode) ?
                                        CnlStatusID.Defined : CnlStatusID.Undefined;

                        if (itemTag.ItemConfig.IsArray && change.Value.Value is Array arrVal)
                        {
                            int       arrLen    = Math.Min(itemTag.ItemConfig.DataLength, arrVal.Length);
                            double[]  arr       = new double[arrLen];
                            TagFormat tagFormat = TagFormat.FloatNumber;

                            for (int i = 0; i < arrLen; i++)
                            {
                                arr[i] = ConvertArrayElem(arrVal.GetValue(i), out TagFormat format);
                                if (i == 0)
                                {
                                    tagFormat = format;
                                }
                            }

                            DeviceData.SetDoubleArray(tagIndex, arr, tagStatus);
                            DeviceTags[tagIndex].Format = tagFormat;
                        }
                        else
                        {
                            SetTagData(tagIndex, change.Value.Value, tagStatus);
                        }
                    }
                    else
                    {
                        Log.WriteLine(Locale.IsRussian ?
                                      "Ошибка: тег \"{0}\" не найден" :
                                      "Error: tag \"{0}\" not found", monitoredItem.StartNodeId);
                    }
                }
            }
        }
Пример #10
0
            private static GeneratedSegment ParseTextRange(TextRange range, TagFormat tagFormat)
            {
                try {
                    switch (tagFormat)
                    {
                    case TagFormat.Json:
                        return(ParseJson(range));

                    case TagFormat.Xml:
                        return(ParseXml(range));
                    }
                }
                catch (Exception ex) {
                    Debug.DebugHere(ex);
                    throw;
                }
                return(null);
            }
Пример #11
0
        /// <summary>
        /// 格式化数据类型
        /// </summary>
        /// <param name="format">数据类型</param>
        /// <returns></returns>
        private string FormatString(TagFormat format)
        {
            string sDest = null;

            switch (format)
            {
            case TagFormat.TLV_INTEGER:
                sDest = toInteger().ToString();
                break;

            case TagFormat.TLV_DATE:
                sDest = (toDate() == new DateTime())?"Date Paser Error":toDate().ToString("yyyy-MM-dd");
                break;

            case TagFormat.TLV_TIME:
                sDest = (toTime() == new DateTime())?"Time Paser Error":toTime().ToString("hh:mm:ss");
                break;

            case TagFormat.TLV_TIMESTAMP:
                sDest = (toTimeStamp() == new DateTime())?"DateTime Paser Error":toTimeStamp().ToString("yyyy-MM-dd hh:mm:ss");
                break;

            case TagFormat.TLV_STRING:
                sDest = toString();
                break;

            case TagFormat.TLV_MONEY:
                sDest = toMoney().ToString("C");
                break;

            case TagFormat.TLV_NUMBER:
                sDest = toNumber().ToString();
                break;

            case TagFormat.TLV_EXTEND:
                sDest = (toExtend() == null)?"(NULL)":"(" + toExtend().ToString() + ")";
                break;

            default:
                sDest = "ERROR:Not find TagFormat to format value";
                break;
            }
            return(sDest);
        }
Пример #12
0
    public List <TagFormat> GetTags(char inputChar)
    {
        var tags = new List <TagFormat>();

        foreach (var c in _connections)
        {
            if (c.Key[0] == inputChar) // first part of string is input character
            {
                string    s = c.Key;
                TagFormat t = new TagFormat();
                t.input          = s[0];
                t.machine        = s[1];
                t.machineCommand = s.Substring(2);
                tags.Add(t);
            }
        }
        if (tags.Count == 0)
        {
            return(null);
        }
        return(tags);
    }
Пример #13
0
 public Manager(TagFormat tagFormat)
 {
     _tagFormat = tagFormat;
 }
        /// <summary>
        /// Analiza el <paramref name="text"/> indicado, y lo clasifica según si contiene o no tags.
        /// </summary>
        /// <param name="text">El texto de entrada.</param>
        /// <param name="format">El formato de Tag que deseas que analice dentro del texto.</param>
        /// <returns></returns>
        private static IDialogueText AnalyseTaggedText(string text, TagFormat format)
        {
            IDialogueText resultDialogueText = null;

            string textBeingAnalyzed = text;
            int    currentIndex      = 0;

            // Mientras quede texto por analizar
            while (textBeingAnalyzed.Length > 0)
            {
                int nextIndex      = currentIndex;
                int indexOfTagInit = 0;

                try
                {
                    // Extraes siguiente tag que haya
                    TagOption tag = format.Extract(textBeingAnalyzed, out indexOfTagInit, out int _, out string remainingTextAfterStart);

                    if (tag != null) // Aún hay tags en el texto
                    {
                        nextIndex = (text.Length - textBeingAnalyzed.Length + indexOfTagInit) + tag.Text().Length;

                        if (indexOfTagInit > 0) // Si hay tag inicial, si no hay es porque no existe inicio porque se ha quitado en iteraciones anteriores
                        {
                            // Coger el texto antes de que empiece el tag y añadirlo a resultDialogueText
                            string textBeforeTag = textBeingAnalyzed.Substring(0, indexOfTagInit);
                            if (resultDialogueText == null)
                            {
                                // El texto original es un ComplexDialogueText
                                resultDialogueText = new ComplexDialogueText(textBeforeTag);
                            }
                            else
                            {
                                // Añadir el texto al ComplexDialogueText
                                resultDialogueText.AddText(textBeforeTag);
                            }
                        }

                        if (tag.Position == TagOptionPosition.Start) // si el tag es del principio
                        {
                            string    textSearchingForEnd   = remainingTextAfterStart;
                            string    taggedText            = null;
                            string    remainingTextAfterEnd = null;
                            TagOption endTag = null;
                            while (taggedText == null && textSearchingForEnd.Length > 0) // Mientras haya texto
                            {
                                // Extraer el siguiente tag, que deberia ser el tag de cierre
                                endTag = format.Extract(textSearchingForEnd, out int indexOfEndTagInit, out int _, out remainingTextAfterEnd);
                                if (endTag != null)                     // Si el endTag se ha encontrado
                                {
                                    if (TagOption.Matches(tag, endTag)) // Si es el endTag del tag actual (soporte para nested tags)
                                    {
                                        taggedText        = remainingTextAfterStart.Substring(0, remainingTextAfterStart.Length - remainingTextAfterEnd.Length - endTag.Text().Length);
                                        textBeingAnalyzed = remainingTextAfterEnd;
                                    }
                                    else
                                    {
                                        // Actualizar texto para encontrar el endTag del tag actual
                                        textSearchingForEnd = remainingTextAfterEnd;
                                    }
                                }
                            }

                            if (taggedText == null) // Si no se ha encontrado tag de cierre para el tag actual
                            {
                                throw new TagException.StartTagWithoutEndException(tag, indexOfTagInit);
                            }
                            else
                            {
                                // Crear DialogueTaggedText a partir de este tag, porque ya sabemos cuando termina
                                // Llamada recursiva a AnalyzeText para encontrar el texto interior (y soportar posibles tags nesteados)
                                DialogueTaggedText dialogueTaggedText = new DialogueTaggedText(new TagType(tag, endTag), AnalyseTaggedText(taggedText, format));
                                if (resultDialogueText == null)
                                {
                                    if (remainingTextAfterEnd != null && remainingTextAfterEnd.Length > 0) // Si hay más texto luego
                                    {
                                        // El texto original es un ComplexDialogueText
                                        resultDialogueText = new ComplexDialogueText(dialogueTaggedText);
                                    }
                                    else // No existe más texto luego
                                    {
                                        // El texto original es un DialogueTaggedText
                                        resultDialogueText = dialogueTaggedText;
                                    }
                                }
                                else
                                {
                                    // Añadir el texto al ComplexDialogueText
                                    resultDialogueText.AddText(dialogueTaggedText);
                                }
                            }
                        }
                        else
                        {
                            throw new TagException.EndTagBeforeStartException(tag, currentIndex);
                        }
                    }
                    else // No se ha encontrado ningun tag más
                    {
                        if (resultDialogueText == null)
                        {
                            // El texto original es un DialogueText
                            resultDialogueText = new DialogueText(textBeingAnalyzed);
                        }
                        else
                        {
                            // Añadir el texto al ComplexDialogueText
                            resultDialogueText.AddText(textBeingAnalyzed);
                        }

                        return(resultDialogueText);
                    }
                }
                catch (ParsingException)
                {
                    nextIndex = (text.Length - textBeingAnalyzed.Length + indexOfTagInit) + 1;

                    // Go to the next portion of the text (Skip the exception source)
                    textBeingAnalyzed = textBeingAnalyzed.Substring(nextIndex);
                    currentIndex      = nextIndex;
                }
            }

            return(resultDialogueText);
        }
Пример #15
0
 public TagOption(string option, TagFormat format, TagOptionPosition position = TagOptionPosition.start)
 {
     Option   = option;
     Format   = format;
     Position = position;
 }
Пример #16
0
        /// <summary>
        /// Analiza el <paramref name="text"/> indicado, y lo clasifica según si contiene o no tags.
        /// <para>Opcionalmente, puedes añadir un <paramref name="logger"/> para que te reporte las excepciones internas que se puedan producir (mediante <see cref="ParsingException"/>).</para>
        /// </summary>
        /// <param name="text">El texto de entrada.</param>
        /// <param name="logger">Función que te reporte las excepciones internas que se puedan producir.</param>
        /// <param name="format">El formato de Tag que deseas que analice dentro del texto.</param>
        /// <returns></returns>
        public static IDialogueText AnalyzeText(string text, TagFormat format, Action <ParsingException> logger = null)
        {
            IDialogueText resultDialogueText = null;

            string textBeingAnalyzed = text;

            while (textBeingAnalyzed != null && textBeingAnalyzed.Length > 0)
            {
                int indexOfTagInit = 0;
                try
                {
                    TagOption tag = format.Extract(textBeingAnalyzed, out indexOfTagInit, out int _, out string remainingTextAfterStart);
                    if (tag != null)
                    {
                        if (indexOfTagInit > 0)
                        {
                            string textBeforeTag = textBeingAnalyzed.Substring(0, indexOfTagInit);
                            if (resultDialogueText == null)
                            {
                                resultDialogueText = new ComplexDialogueText(textBeforeTag);
                            }
                            else
                            {
                                resultDialogueText.AddText(textBeforeTag);
                            }
                        }

                        if (tag.Position == TagOptionPosition.start)
                        {
                            string    textSearchingForEnd = remainingTextAfterStart;
                            string    taggedText = null, remainingTextAfterEnd = null;
                            TagOption endTag = null;
                            while (taggedText == null && textSearchingForEnd != null && textSearchingForEnd.Length > 0)
                            {
                                endTag = format.Extract(textSearchingForEnd, out int indexOfEndTagInit, out int _, out remainingTextAfterEnd);
                                if (endTag != null)
                                {
                                    if (TagOption.Matches(tag, endTag))
                                    {
                                        taggedText        = remainingTextAfterStart.Substring(0, remainingTextAfterStart.Length - remainingTextAfterEnd.Length - endTag.Text.Length);
                                        textBeingAnalyzed = remainingTextAfterEnd; // This tag has been found correctly, go to the next portion of the text
                                        break;
                                    }
                                }
                                textSearchingForEnd = remainingTextAfterEnd;
                            }

                            if (taggedText == null)
                            {
                                throw new TagException.StartTagWithoutEndException(tag, index: text.Length - textBeingAnalyzed.Length + indexOfTagInit);
                            }
                            else
                            {
                                DialogueTaggedText dialogueTaggedText = new DialogueTaggedText(new Tag(tag, endTag), AnalyzeText(taggedText, format, logger));
                                if (resultDialogueText == null)
                                {
                                    if (remainingTextAfterEnd != null && remainingTextAfterEnd.Length > 0)
                                    {
                                        resultDialogueText = new ComplexDialogueText(dialogueTaggedText);
                                    }
                                    else
                                    {
                                        resultDialogueText = dialogueTaggedText;
                                    }
                                }
                                else
                                {
                                    resultDialogueText.AddDialogueText(dialogueTaggedText);
                                }
                            }
                        }
                        else
                        {
                            throw new TagException.EndTagBeforeStartException(tag, index: text.Length - textBeingAnalyzed.Length + indexOfTagInit);
                        }
                    }
                    else
                    {
                        if (resultDialogueText == null)
                        {
                            return(new DialogueText(textBeingAnalyzed));
                        }
                        else
                        {
                            resultDialogueText.AddText(textBeingAnalyzed);
                            return(resultDialogueText);
                        }
                    }
                }
                catch (ParsingException ex)
                {
                    // Log the exception
                    logger?.Invoke(ex);

                    int nextIndex = indexOfTagInit + 1;

                    // Add the start of the tag as raw text

                    if (resultDialogueText == null)
                    {
                        resultDialogueText = new ComplexDialogueText(textBeingAnalyzed.Substring(0, nextIndex));
                    }
                    else
                    {
                        resultDialogueText.AddText(textBeingAnalyzed[indexOfTagInit].ToString());
                    }

                    // Go to the next portion of the text (Skip the exception source)
                    textBeingAnalyzed = nextIndex < textBeingAnalyzed.Length ? textBeingAnalyzed.Substring(nextIndex) : null;
                }
            }

            return(resultDialogueText);
        }
 public Manager(T renderer, TagFormat tagFormat)
 {
     _tagFormat     = tagFormat;
     _renderer      = renderer;
     _propertyToXml = XmlAttributeAttribute.GetPropertyToXmlAttributeTranslation(_renderer.OptionAttributeType);
 }
Пример #18
0
        /// <summary>
        /// 转换成byte
        /// </summary>
        /// <param name="tagformat">数据类型</param>
        /// <param name="val">值</param>
        /// <returns></returns>
        public static byte[] ValueToByteArray(TagFormat tagformat, object val)
        {
            switch (tagformat)
            {
            case TagFormat.TLV_DATE:
            {
                if (val.GetType() != typeof(System.DateTime))
                {
                    throw new TypeException(val.GetType().ToString(), typeof(System.DateTime).ToString());
                }
                int year  = ((DateTime)val).Year - 1900;
                int month = ((DateTime)val).Month;
                int day   = ((DateTime)val).Day;
                return(new byte[] {
                        (byte)year, (byte)month, (byte)day
                    });
            }

            case TagFormat.TLV_EXTEND:
            {
                if (val.GetType() != typeof(Packet_Body))
                {
                    throw new TypeException(val.GetType().ToString(), typeof(Packet_Body).ToString());
                }
                else if (((Packet_Body)val).m_Status != Common.Logic.Body_Status.MSG_STRUCT_OK)
                {
                    throw new ValueException(((Packet_Body)val).m_Status.ToString(), Body_Status.MSG_STRUCT_OK.ToString());
                }
                return(((Packet_Body)val).ToByteArray());
            }

            case TagFormat.TLV_INTEGER:
            {
                byte[]      ret  = null;
                System.Type type = val.GetType();
                if (type == typeof(ulong))
                {
                    ulong val_int = (ulong)val;
                    ret = new byte[] {
                        (byte)val_int, (byte)(val_int >> 8), (byte)(val_int >> 8 * 2),
                        (byte)(val_int >> 8 * 3), (byte)(val_int >> 8 * 4), (byte)(val_int >> 8 * 5),
                        (byte)(val_int >> 8 * 6), (byte)(val_int >> 8 * 7)
                    };
                }
                else if (type == typeof(long))
                {
                    ulong val_int = (ulong)((long)val);
                    ret = new byte[] {
                        (byte)val_int, (byte)(val_int >> 8), (byte)(val_int >> 8 * 2),
                        (byte)(val_int >> 8 * 3), (byte)(val_int >> 8 * 4), (byte)(val_int >> 8 * 5),
                        (byte)(val_int >> 8 * 6), (byte)(val_int >> 8 * 7)
                    };
                }
                else if (type == typeof(uint))
                {
                    uint val_int = (uint)val;
                    ret = new byte[] {
                        (byte)val_int, (byte)(val_int >> 8), (byte)(val_int >> 16), (byte)(val_int >> 24)
                    };
                }
                else if (type == typeof(int))
                {
                    uint val_int = (uint)((int)val);
                    ret = new byte[] {
                        (byte)val_int, (byte)(val_int >> 8), (byte)(val_int >> 16), (byte)(val_int >> 24)
                    };
                }
                else if (type == typeof(short))
                {
                    short val_int = (short)val;
                    ret = new byte[] {
                        (byte)val_int, (byte)(val_int >> 8)
                    };
                }
                else if (type == typeof(ushort))
                {
                    ushort val_int = (ushort)val;
                    ret = new byte[] {
                        (byte)val_int, (byte)(val_int >> 8)
                    };
                }
                else if (type == typeof(byte))
                {
                    byte val_int = (byte)val;
                    ret = new byte[] { (byte)val_int };
                }
                else if (type == typeof(sbyte))
                {
                    byte val_int = (byte)((sbyte)val);
                    ret = new byte[] { (byte)val_int };
                }
                else
                {
                    throw new TypeException(val.GetType().ToString(), "ulong,long,uint,int,byte,sbyte");
                }
                return(ret);
            }

            case TagFormat.TLV_MONEY:
            {
                if (val.GetType() != typeof(double))
                {
                    throw new TypeException(val.GetType().ToString(), typeof(double).ToString());
                }
                uint val_int = (uint)((double)val);
                uint val_dec = (uint)(((double)val - val_int) * 100);
                return(new byte[] {
                        (byte)(val_int >> 16), (byte)(val_int >> 8), (byte)val_int, (byte)val_dec
                    });
            }

            case TagFormat.TLV_NUMBER:
            {
                if (val.GetType() != typeof(string))
                {
                    throw new TypeException(val.GetType().ToString(), typeof(string).ToString());
                }
                string val_string = (string)val;
                if (!System.Text.RegularExpressions.Regex.IsMatch(val_string, @"^\d{11,12}$", System.Text.RegularExpressions.RegexOptions.Compiled))
                {
                    throw new ValueException(val_string, lg.Logic_TLV_Structure_NumLength);
                }
                byte[] ret = new byte[1 + (val_string.Length + 1) / 2];
                ret[0] = (byte)val_string.Length;
                for (int i = 0; i < val_string.Length; i++)
                {
                    if (i % 2 == 0)
                    {
                        ret[1 + i / 2] += (byte)(int.Parse(val_string.Substring(i, 1)) << 4);
                    }
                    else
                    {
                        ret[1 + i / 2] += (byte)(int.Parse(val_string.Substring(i, 1)));
                    }
                }
                return(ret);
            }

            case TagFormat.TLV_STRING:
            {
                if (val.GetType() != typeof(string))
                {
                    throw new TypeException(val.GetType().ToString(), typeof(string).ToString());
                }
                return(System.Text.Encoding.Default.GetBytes((string)val));
            }

            case TagFormat.TLV_TIME:
            {
                if (val.GetType() != typeof(System.DateTime))
                {
                    throw new TypeException(val.GetType().ToString(), typeof(System.DateTime).ToString());
                }
                int hour   = ((DateTime)val).Hour;
                int minute = ((DateTime)val).Minute;
                int second = ((DateTime)val).Second;
                return(new byte[] {
                        (byte)hour, (byte)minute, (byte)second
                    });
            }

            case TagFormat.TLV_UNICODE:
            {
                if (val.GetType() != typeof(string))
                {
                    throw new TypeException(val.GetType().ToString(), typeof(string).ToString());
                }
                return(System.Text.Encoding.Unicode.GetBytes((string)val));
            }

            case TagFormat.TLV_TIMESTAMP:
            {
                if (val.GetType() != typeof(System.DateTime))
                {
                    throw new TypeException(val.GetType().ToString(), typeof(System.DateTime).ToString());
                }
                int year   = ((DateTime)val).Year - 1900;
                int month  = ((DateTime)val).Month;
                int day    = ((DateTime)val).Day;
                int hour   = ((DateTime)val).Hour;
                int minute = ((DateTime)val).Minute;
                int second = ((DateTime)val).Second;
                return(new byte[] {
                        (byte)year, (byte)month, (byte)day, (byte)hour, (byte)minute, (byte)second
                    });
            }

            case TagFormat.TLV_BOOLEAN:
            {
                if (val.GetType() != typeof(bool))
                {
                    throw new TypeException(val.GetType().ToString(), typeof(bool).ToString());
                }
                bool val_int = (bool)val;
                return(new byte[] { Convert.ToByte(val_int) });
            }

            default:
                throw new ValueException(val.ToString(), lg.Logic_TLV_Structure_TagFormatType);
            }
        }