예제 #1
0
        /// <summary>+
        /// 对读写区域的字符串进行处理
        /// </summary>
        /// <returns></returns>
        public bool ProcessFunc()
        {
            string[] tmp;
            int      x, y;

            m_listArea = new List <adr_area>();

            try
            {
                string[] astr = m_sArea[m_nFunc].Split(',');
                foreach (string s in astr)
                {
                    tmp = s.Split('-');
                    if (tmp.Length > 2)
                    {
                        MessageBox.Show("Parameter Error! (" + s + ")");
                        return(false);;
                    }
                    else if (tmp.Length == 1)
                    {
                        x = Int32.Parse(tmp[0]);
                        adr_area adr1 = new adr_area();
                        adr1.start_adr = (ushort)x;
                        adr1.end_adr   = (ushort)x;
                        m_listArea.Add(adr1);
                    }
                    else if (tmp.Length == 2)
                    {
                        x = Int32.Parse(tmp[0]);
                        y = Int32.Parse(tmp[1]);
                        if (Math.Abs(x - y) > 120)
                        {
                            MessageBox.Show("Parameter Error! (" + s + ")");
                            return(false);;
                        }
                        adr_area adr1 = new adr_area();
                        if (x < y)
                        {
                            adr1.start_adr = (ushort)x;
                            adr1.end_adr   = (ushort)y;
                        }
                        else
                        {
                            adr1.start_adr = (ushort)y;
                            adr1.end_adr   = (ushort)x;
                        }
                        m_listArea.Add(adr1);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Parameter Error! (" + ex.Message + ")");
                return(false);
            }

            m_listArea.Sort();
            OragnizeArea();
            return(true);
        }
예제 #2
0
        /// <summary>
        /// 组织存储区域
        /// </summary>
        private void OragnizeArea()
        {
            ushort   start_area;
            ushort   end_area;
            int      flag;
            adr_area node;
            adr_area t = new adr_area();

            m_scanArea = new List <adr_area>();


            for (int index = 0; index < m_listArea.Count; index++)
            {
                t.start_adr = m_listArea[index].start_adr;
                t.end_adr   = m_listArea[index].end_adr;

                flag = 0;
                for (int i = 0; i < m_scanArea.Count; i++)
                {
                    start_area = m_scanArea[i].start_adr;
                    end_area   = m_scanArea[i].end_adr;

                    //调整当前的起始指针,避免重复
                    if (t.start_adr > start_area && t.start_adr < end_area && t.end_adr >= end_area)
                    {
                        t.start_adr = end_area;
                    }

                    //调整当前的结束指针,避免重复
                    if (t.end_adr < end_area && t.end_adr > start_area && t.start_adr <= start_area)
                    {
                        t.end_adr = start_area;
                    }

                    //情况1  当前包含在里面
                    if (t.start_adr >= start_area && t.end_adr <= end_area)
                    {
                        flag = 1;
                        m_listArea[index].index = i;
                        break;
                    }
                    //情况2 起始地址小,结束地址已包含,总和小于120
                    if (t.start_adr <= start_area && t.end_adr <= end_area && end_area - t.start_adr <= 120)
                    {
                        flag = 1;
                        m_listArea[index].index = i;
                        m_scanArea[i].start_adr = t.start_adr;
                        break;
                    }

                    //情况3 起始地址小,结束地址大,总和小于120
                    if (t.start_adr <= start_area && t.end_adr > end_area && t.end_adr - t.start_adr <= 120)
                    {
                        flag = 1;
                        m_listArea[index].index = i;
                        m_scanArea[i].start_adr = t.start_adr;
                        m_scanArea[i].end_adr   = t.end_adr;
                        break;
                    }

                    //情况4 起始地址包含,结束地址大,总和小于120
                    if (t.start_adr > start_area && t.end_adr > end_area && t.end_adr - start_area <= 120)
                    {
                        flag = 1;
                        m_listArea[index].index = i;
                        m_scanArea[i].end_adr   = t.end_adr;
                        break;
                    }
                }

                //未发现匹配的
                if (flag == 0)
                {
                    node = new adr_area(t.start_adr, t.end_adr);
                    m_listArea[index].index = m_scanArea.Count;
                    m_scanArea.Add(node);
                }
            }

            //申请内存
            m_sValue  = new short[m_scanArea.Count][];
            m_bValue  = new bool[m_scanArea.Count][];
            m_nRWFlag = new int[m_scanArea.Count][];

            for (int i = 0; i < m_scanArea.Count; i++)
            {
                m_sValue[i]  = new short[m_scanArea[i].length];
                m_bValue[i]  = new bool[m_scanArea[i].length];
                m_nRWFlag[i] = new int[m_scanArea[i].length];
            }

            for (int i = 0; i < m_listArea.Count; i++)
            {
                for (int j = m_listArea[i].start_adr; j <= m_listArea[i].end_adr; j++)
                {
                    m_nRWFlag[m_listArea[i].index][j - m_scanArea[m_listArea[i].index].start_adr] = 1;
                }
            }
        }