示例#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
        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");
            }
        }