public void WriteUDTString(string tagName, string value)
        {
            lock (mSyncLock) {
                Logix.Tag lengthTag = new Logix.Tag(tagName + ".LEN");
                Logix.Tag dataTag = new Logix.Tag(tagName + ".DATA[0]");
                System.Text.UTF7Encoding utf = new System.Text.UTF7Encoding();

                // * set the DataType properties
                lengthTag.DataType = Logix.Tag.ATOMIC.DINT;
                dataTag.DataType = Logix.Tag.ATOMIC.SINT;

                lengthTag.Value = value.Length;
                dataTag.Length = value.Length;
                dataTag.Value = utf.GetBytes(value);

                WriteTag(lengthTag);
                WriteTag(dataTag);
            }
        }
        public bool AddTag(Tag tag)
        {
            if (mTagDict.ContainsKey(tag.Name)) return false;

            Logix.Tag ltag = null;
            switch (tag.DataType) {
                case DataType.Bool:
                    ltag = new Logix.Tag(mPLC, tag.Name, Logix.Tag.ATOMIC.BOOL);
                    break;
                case DataType.Byte:
                    ltag = new Logix.Tag(mPLC, tag.Name, Logix.Tag.ATOMIC.SINT);
                    break;
                case DataType.Int16:
                    ltag = new Logix.Tag(mPLC, tag.Name, Logix.Tag.ATOMIC.INT);
                    break;
                case DataType.Int32:
                    ltag = new Logix.Tag(mPLC, tag.Name, Logix.Tag.ATOMIC.DINT);
                    break;
                case DataType.Real32:
                    ltag = new Logix.Tag(mPLC, tag.Name, Logix.Tag.ATOMIC.REAL);
                    break;
                case DataType.String:
                    ltag = new Logix.Tag(mPLC, tag.Name, Logix.Tag.ATOMIC.STRING);
                    break;
            }
            if (tag.ManualRead == false) {
                if ((tag.Direction & TagDirection.Output) == TagDirection.Output) {
                    tag.TagChanged += new TagEventHandler(OnTagChanged);
                }
                if ((tag.Direction & TagDirection.Input) == TagDirection.Input) {
                    AddTagToGroup(ltag, tag.UpdateTime);
                }
            }
            mTagDict.Add(tag.Name, tag);
            mLTagDict.Add(tag.Name, ltag);
            if(ltag.Value != null) tag.Value = ltag.Value; //Initialize Tag Value

            return true;
        }
        public string ReadUDTString(string tagName)
        {
            lock (mSyncLock) {
                System.Text.UTF7Encoding utf = new System.Text.UTF7Encoding();

                Logix.Tag lengthTag = new Logix.Tag(tagName + ".LEN");
                Logix.Tag dataTag = new Logix.Tag(tagName + ".DATA[0]");

                ReadTag(lengthTag);

                dataTag.Length = (int)lengthTag.Value;
                ReadTag(dataTag);

                if (dataTag.Value is sbyte) {
                    return Convert.ToChar(dataTag.Value).ToString();
                } else if (dataTag.Value is System.Array) {
                    byte[] b = (byte[])dataTag.Value;
                    return utf.GetString(b, 0, dataTag.Length);
                } else {
                    throw new LogixTagException("Invalid tag type.", dataTag, 0);
                }
            }
        }
 public LogixTagException(string msg, Logix.Tag tag, int errorCode)
     : base(msg)
 {
     this.ErrorCode = errorCode;
     this.Tag = tag;
 }