コード例 #1
0
        public void ReadItems(MemoryStream reader)
        {
            //if developer did not define item of this message
            if (m_Items.Count == 0)
            {
                byte[]     formatCodeByte = new byte[1];
                SecsItem   item;
                FormatCode fc;
                byte       lenghtByteLong;

                while (reader.Position < reader.Length)
                {
                    reader.Read(formatCodeByte, 0, formatCodeByte.Length);

                    //move back to format code position because *1
                    reader.Position -= formatCodeByte.Length;

                    fc   = FormatCodeHelper.GetFormatCode(formatCodeByte[0], out lenghtByteLong);
                    item = SecsItemFactory.Create("DV" + m_Items.Count.ToString(), fc);
                    //*1 this function is read format code also
                    item.Read(reader);

                    AddItem(item);
                }
            }
            //if developer already defined item of this message
            else if (m_Items.Count > 0)
            {
                foreach (SecsItem item in m_Items)
                {
                    item.Read(reader);
                }
            }
        }
コード例 #2
0
        public SecsItem CreateItem(string itemName)
        {
            SecsItem ret = null;

            if (m_DataItemDictionary.ContainsKey(itemName))
            {
                SecsDataItem def = m_DataItemDictionary[itemName];
                ret = SecsItemFactory.Create(def.Name, def.Format);
            }
            else
            {
                throw new Exception("No item defination for item name :=" + itemName);
            }
            return(ret);
        }
コード例 #3
0
        protected override void ReadValue(System.IO.MemoryStream reader, uint itemToRead)
        {
            List <SecsItem> elements = this.Value;

            if (elements.Count == 0) //not fixed item list
            {
                long readItemCount = 0;

                byte[] formatCodeByte = new byte[1];
                byte   lenghtByteLong = 0;

                FormatCode fc;
                SecsItem   item = null;

                while (readItemCount < itemToRead)
                {
                    reader.Read(formatCodeByte, 0, formatCodeByte.Length);

                    //move back to format code position
                    reader.Position -= formatCodeByte.Length;

                    fc   = FormatCodeHelper.GetFormatCode(formatCodeByte[0], out lenghtByteLong);
                    item = SecsItemFactory.Create("DV" + elements.Count.ToString(), fc);
                    item.Read(reader);
                    elements.Add(item);
                    readItemCount += 1;
                } //while (readItemCount < itemToRead)
            }
            else if (itemToRead == elements.Count) //fixed item list
            {
                //class defination error
                foreach (SecsItem item in elements)
                {
                    item.Read(reader);
                }
            }
            else
            {
                //invalid define
                throw new Exception("Defined item count is not equal to item to read");
            }
        }