private void TranslateInput()
        {
            string str = "";

            m_excp = new Exception("Choose a BAR");
            if ((uint)cmboBar.SelectedIndex == 0xffffffff)
            {
                throw m_excp;
            }
            m_dwBar = (DWORD)cmboBar.SelectedIndex;

            m_excp = new Exception("Choose the Transfer Mode");
            uint uiModeIndex = (uint)cmboMode.SelectedIndex;

            if (uiModeIndex == 0xffffffff)
            {
                throw m_excp;
            }
            m_mode = (uiModeIndex == 0)? WDC_ADDR_MODE.WDC_MODE_8:
                     (uiModeIndex == 1)? WDC_ADDR_MODE.WDC_MODE_16:
                     (uiModeIndex == 2)? WDC_ADDR_MODE.WDC_MODE_32:
                     WDC_ADDR_MODE.WDC_MODE_64;

            m_excp = new Exception("Choose the Transfer Type");
            if ((uint)cmboTransType.SelectedIndex == 0xffffffff)
            {
                throw m_excp;
            }
            m_type = (cmboTransType.SelectedIndex == 0)?
                     TRANSFER_TYPE.BLOCK : TRANSFER_TYPE.NONBLOCK;

            if (txtNumBytes.Enabled == true)
            {
                m_excp = new Exception("Please enter the number of bytes. " +
                                       "Entered value should be a hex number." +
                                       Environment.NewLine + " (Maximum value: 0x" +
                                       m_device.AddrDesc[m_dwBar].dwBytes.ToString("X") + ")");
                m_dwBytes = Convert.ToUInt32(txtNumBytes.Text, 16);
                if (m_dwBytes > m_device.AddrDesc[m_dwBar].dwBytes)
                {
                    throw m_excp;
                }
            }
            else
            {
                m_dwBytes = (DWORD)((m_mode == WDC_ADDR_MODE.WDC_MODE_8) ? 1 :
                                    ((m_mode == WDC_ADDR_MODE.WDC_MODE_16) ? 2 :
                                     ((m_mode == WDC_ADDR_MODE.WDC_MODE_32) ? 4 : 8)));
            }

            if (chkBoxInc.Enabled == true)
            {
                m_bAutoInc = chkBoxInc.Checked;
            }

            m_excp = new Exception("Please enter the offset. " +
                                   "Entered value should be a hex number");
            m_dwOffset = (DWORD)Convert.ToInt32(txtOffset.Text, 16);

            if (m_direction == RW.WRITE && txtInput.Text == "")
            {
                m_excp = new Exception("You must enter the data to write. " +
                                       "data should be hex");
                throw m_excp;
            }

            m_excp = new Exception("The data you've entered is invalid. please "
                                   + "try again (hex)");

            switch (m_mode)
            {
            case WDC_ADDR_MODE.WDC_MODE_8:
            {
                m_bData = new byte[m_dwBytes];

                if (m_direction == RW.WRITE)
                {
                    str = txtInput.Text;
                    for (int i = 0, j = 0; i < str.Length && j < m_dwBytes; j++)
                    {
                        while (str[i] == ' ')
                        {
                            ++i;
                        }
                        m_bData[j] = Convert.ToByte(str.Substring(i, 2), 16);
                        i         += 2;
                    }
                }
                break;
            }

            case WDC_ADDR_MODE.WDC_MODE_16:
            {
                m_wData = new WORD[m_dwBytes / 2];

                if (m_direction == RW.WRITE)
                {
                    str = txtInput.Text;
                    for (int i = 0, j = 0; i < str.Length && j < m_dwBytes / 2; j++)
                    {
                        while (str[i] == ' ')
                        {
                            ++i;
                        }
                        m_wData[j] = Convert.ToUInt16(str.Substring(i, 4), 16);
                        i         += 4;
                    }
                }
                break;
            }

            case WDC_ADDR_MODE.WDC_MODE_32:
            {
                m_u32Data = new UINT32[m_dwBytes / 4];

                if (m_direction == RW.WRITE)
                {
                    str = txtInput.Text;
                    for (int i = 0, j = 0; i < str.Length && j < m_dwBytes / 4; j++)
                    {
                        while (str[i] == ' ')
                        {
                            ++i;
                        }
                        m_u32Data[j] = Convert.ToUInt32(str.Substring(i, 8),
                                                        16);
                        i += 8;
                    }
                }
                break;
            }

            case WDC_ADDR_MODE.WDC_MODE_64:
            {
                m_u64Data = new UINT64[m_dwBytes / 8];

                if (m_direction == RW.WRITE)
                {
                    str = txtInput.Text;
                    for (int i = 0, j = 0; i < str.Length && j < m_dwBytes / 8; j++)
                    {
                        while (str[i] == ' ')
                        {
                            ++i;
                        }
                        m_u64Data[j] = Convert.ToUInt64(str.Substring(i, 2),
                                                        16);
                        i += 16;
                    }
                }
                break;
            }
            }
        }
Ejemplo n.º 2
0
        private void TranslateInput()
        {
            string str = "";

            m_excp = new Exception("请选择一个BAR空间");          //异常显示 没有选择  当没有选择的时候是
            if ((uint)cmboBar.SelectedIndex == 0xffffffff) //如果没有选择一个bar 就抛出一个错误 通过判断是不是-1来判断
            {
                throw m_excp;                              //抛出异常
            }
            m_dwBar = (DWORD)cmboBar.SelectedIndex;        //读出选择的项目

            m_excp = new Exception("请选择传输位宽");
            uint uiModeIndex = (uint)cmboMode.SelectedIndex;

            if (uiModeIndex == 0xffffffff)
            {
                throw m_excp;//抛出异常
            }
            m_mode = (uiModeIndex == 0)? WDC_ADDR_MODE.WDC_MODE_8:
                     (uiModeIndex == 1)? WDC_ADDR_MODE.WDC_MODE_16:
                     (uiModeIndex == 2)? WDC_ADDR_MODE.WDC_MODE_32:
                     WDC_ADDR_MODE.WDC_MODE_64;                 //模式选择 进行判断

            m_excp = new Exception("Choose the Transfer Type"); //传输类型 block nonblock两种
            if ((uint)cmboTransType.SelectedIndex == 0xffffffff)
            {
                throw m_excp;
            }
            m_type = (cmboTransType.SelectedIndex == 0)?
                     TRANSFER_TYPE.BLOCK : TRANSFER_TYPE.NONBLOCK;//判断是block 还是nonblock类型的

            /*m_dwBytes用来表明数据的个数 不管数据是8bit 或者是16还是32 64bit 对于nonblock类型 适中为一位 对于block类型可以是大于一的个数 但是m_dwBytes是以
             * byte计数的 不同的模式会进行一定转换   猜测 可能block可以连续的写数据 不是一个一个的写
             */

            if (txtNumBytes.Enabled == true)//当enabled之后 如果为ture 则可以输入数据 false不能输入数据
            {
                m_excp = new Exception("Please enter the number of bytes. " +
                                       "Entered value should be a hex number." +
                                       Environment.NewLine + " (Maximum value: 0x" +
                                       m_device.AddrDesc[m_dwBar].dwBytes.ToString("X") + ")"); //最大的空间
                m_dwBytes = Convert.ToUInt32(txtNumBytes.Text, 16);                             //将16进制转换为32位无符号整数
                if (m_dwBytes > m_device.AddrDesc[m_dwBar].dwBytes)                             //判断是否超出范围    dwBytes:The address space's size (in bytes)
                {
                    throw m_excp;
                }
            }
            else
            {
                m_dwBytes = (DWORD)((m_mode == WDC_ADDR_MODE.WDC_MODE_8) ? 1 :
                                    ((m_mode == WDC_ADDR_MODE.WDC_MODE_16) ? 2 :
                                     ((m_mode == WDC_ADDR_MODE.WDC_MODE_32) ? 4 : 8)));
            }

            if (chkBoxInc.Enabled == true)      //钩号框  检查判断框是否选中
            {
                m_bAutoInc = chkBoxInc.Checked; //自动增长
            }
            m_excp = new Exception("Please enter the offset. " +
                                   "Entered value should be a hex number");
            m_dwOffset = (DWORD)Convert.ToInt32(txtOffset.Text, 16);//offset 框数据  如果没有输入数据 就会触发异常
            //m_direction用来表示是写事件还是读事件
            if (m_direction == RW.WRITE && txtInput.Text == "")
            {//如果是写事件但是没有输入数据 抛出异常
                m_excp = new Exception("You must enter the data to write. " +
                                       "data should be hex");
                throw m_excp;
            }

            m_excp = new Exception("The data you've entered is invalid. please "
                                   + "try again (hex)");

            switch (m_mode)//m_bData  m_wData  m_u32Data 类型不一样
            {
            case WDC_ADDR_MODE.WDC_MODE_8:
            {
                m_bData = new byte[m_dwBytes];

                if (m_direction == RW.WRITE)
                {
                    str = txtInput.Text;    //读入数据??
                    for (int i = 0, j = 0; i < str.Length && j < m_dwBytes; j++)
                    {
                        while (str[i] == ' ')
                        {
                            ++i;                                              //用来跳过空格
                        }
                        m_bData[j] = Convert.ToByte(str.Substring(i, 2), 16); //数据长度由mode决定  8bit则数组长度为1 元为byte 16bit则数组长度为1 元为32位
                        i         += 2;
                    }
                }
                break;
            }

            case WDC_ADDR_MODE.WDC_MODE_16:
            {
                m_wData = new WORD[m_dwBytes / 2];

                if (m_direction == RW.WRITE)
                {
                    str = txtInput.Text;
                    for (int i = 0, j = 0; i < str.Length && j < m_dwBytes / 2; j++)
                    {
                        while (str[i] == ' ')
                        {
                            ++i;
                        }
                        m_wData[j] = Convert.ToUInt16(str.Substring(i, 4), 16);  //substring返回一个从startIndex开始,长度为length的子字符串。
                        i         += 4;
                    }
                }
                break;
            }

            case WDC_ADDR_MODE.WDC_MODE_32://所有分支循环一次 组装成不同位数的值
            {
                m_u32Data = new UINT32[m_dwBytes / 4];

                if (m_direction == RW.WRITE)
                {
                    str = txtInput.Text;
                    for (int i = 0, j = 0; i < str.Length && j < m_dwBytes / 4; j++)
                    {
                        while (str[i] == ' ')
                        {
                            ++i;
                        }
                        m_u32Data[j] = Convert.ToUInt32(str.Substring(i, 8),
                                                        16);
                        i += 8;
                    }
                }
                break;
            }

            case WDC_ADDR_MODE.WDC_MODE_64:
            {
                m_u64Data = new UINT64[m_dwBytes / 8];

                if (m_direction == RW.WRITE)
                {
                    str = txtInput.Text;
                    for (int i = 0, j = 0; i < str.Length && j < m_dwBytes / 8; j++)
                    {
                        while (str[i] == ' ')
                        {
                            ++i;
                        }
                        m_u64Data[j] = Convert.ToUInt64(str.Substring(i, 2),
                                                        16);
                        i += 16;
                    }
                }
                break;
            }
            }
        }