OpenDMAForm.cs
上传用户:huajielb
上传日期:2022-07-29
资源大小:626k
文件大小:11k
源码类别:

驱动编程

开发平台:

Visual C++

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using DWORD = System.UInt32;
  7. using WORD = System.UInt16;
  8. using BOOL = System.Boolean;
  9. using Jungo.wdapi_dotnet;
  10. using Jungo.plx_lib;
  11. namespace Jungo.PLX_Sample
  12. {
  13.     public class OpenDMAForm : System.Windows.Forms.Form
  14.     {
  15.         private Exception m_excp;
  16.         private uint m_u32LocalAddr;
  17.         private RW m_direction;
  18.         private ALLOCATION_TYPE m_wAllocType;
  19.         private DWORD m_dwBytes;
  20.         private BOOL m_bAutoInc;
  21.         private System.Windows.Forms.ComboBox cmboAllocType;
  22.         private System.Windows.Forms.TextBox txtLocalAddr;
  23.         private System.Windows.Forms.TextBox txtBuffSize;
  24.         private System.Windows.Forms.Label lblDmaOpen;
  25.         private System.Windows.Forms.ComboBox cmboAction;
  26.         private System.Windows.Forms.Label lblAllocType;
  27.         private System.Windows.Forms.Label label3;
  28.         private System.Windows.Forms.Label label4;
  29.         private System.Windows.Forms.Label label5;
  30.         private System.Windows.Forms.Button btSubmit;
  31.         private System.Windows.Forms.Button btCancel;
  32.         private System.Windows.Forms.GroupBox groupBox1;
  33.         private System.Windows.Forms.Label label1;
  34.         private System.Windows.Forms.Label label2;
  35.         private System.Windows.Forms.CheckBox chkBoxInc;
  36.         private System.ComponentModel.Container components = null;
  37.         public OpenDMAForm(PLX_DMA_CHANNEL channel)
  38.         {
  39.             InitializeComponent();
  40.             lblDmaOpen.Text = (channel == 0)? 
  41.                 "Open DMA - Channel 0":
  42.                 "Open DMA - Channel 1";
  43.             cmboAllocType.Items.AddRange(new object[]{"Scatter Gather", 
  44.                 "Contigious"});
  45.             cmboAction.Items.AddRange(new object[]{"Read", "Write"});
  46.         }
  47.         protected override void Dispose( bool disposing )
  48.         {
  49.             if( disposing )
  50.             {
  51.                 if(components != null)
  52.                 {
  53.                     components.Dispose();
  54.                 }
  55.             }
  56.             base.Dispose( disposing );
  57.         }
  58. #region Windows Form Designer generated code
  59.         private void InitializeComponent()
  60.         {
  61.             this.cmboAllocType = new System.Windows.Forms.ComboBox();
  62.             this.txtLocalAddr = new System.Windows.Forms.TextBox();
  63.             this.txtBuffSize = new System.Windows.Forms.TextBox();
  64.             this.lblDmaOpen = new System.Windows.Forms.Label();
  65.             this.cmboAction = new System.Windows.Forms.ComboBox();
  66.             this.lblAllocType = new System.Windows.Forms.Label();
  67.             this.label3 = new System.Windows.Forms.Label();
  68.             this.label4 = new System.Windows.Forms.Label();
  69.             this.label5 = new System.Windows.Forms.Label();
  70.             this.btSubmit = new System.Windows.Forms.Button();
  71.             this.btCancel = new System.Windows.Forms.Button();
  72.             this.groupBox1 = new System.Windows.Forms.GroupBox();
  73.             this.label1 = new System.Windows.Forms.Label();
  74.             this.label2 = new System.Windows.Forms.Label();
  75.             this.chkBoxInc = new System.Windows.Forms.CheckBox();
  76.             this.SuspendLayout();
  77.             // cmboAllocType
  78.             this.cmboAllocType.Location = new System.Drawing.Point(24, 48);
  79.             this.cmboAllocType.Name = "cmboAllocType";
  80.             this.cmboAllocType.Size = new System.Drawing.Size(121, 21);
  81.             this.cmboAllocType.TabIndex = 0;
  82.             this.cmboAllocType.Text = "-------  -------";
  83.             // txtLocalAddr
  84.             this.txtLocalAddr.Location = new System.Drawing.Point(40, 144);
  85.             this.txtLocalAddr.Name = "txtLocalAddr";
  86.             this.txtLocalAddr.TabIndex = 3;
  87.             this.txtLocalAddr.Text = "";
  88.             // txtBuffSize
  89.             this.txtBuffSize.Location = new System.Drawing.Point(40, 192);
  90.             this.txtBuffSize.Name = "txtBuffSize";
  91.             this.txtBuffSize.TabIndex = 4;
  92.             this.txtBuffSize.Text = "";
  93.             // lblDmaOpen
  94.             this.lblDmaOpen.Location = new System.Drawing.Point(56, 8);
  95.             this.lblDmaOpen.Name = "lblDmaOpen";
  96.             this.lblDmaOpen.Size = new System.Drawing.Size(128, 23);
  97.             this.lblDmaOpen.TabIndex = 5;
  98.             this.lblDmaOpen.Text = "Open DMA - Channel 0";
  99.             // cmboAction
  100.             this.cmboAction.ItemHeight = 13;
  101.             this.cmboAction.Location = new System.Drawing.Point(24, 96);
  102.             this.cmboAction.Name = "cmboAction";
  103.             this.cmboAction.Size = new System.Drawing.Size(121, 21);
  104.             this.cmboAction.TabIndex = 2;
  105.             this.cmboAction.Text = "------ ------";
  106.             // lblAllocType
  107.             this.lblAllocType.Location = new System.Drawing.Point(24, 32);
  108.             this.lblAllocType.Name = "lblAllocType";
  109.             this.lblAllocType.Size = new System.Drawing.Size(128, 16);
  110.             this.lblAllocType.TabIndex = 6;
  111.             this.lblAllocType.Text = "Allocation type";
  112.             // label3
  113.             this.label3.Location = new System.Drawing.Point(24, 80);
  114.             this.label3.Name = "label3";
  115.             this.label3.Size = new System.Drawing.Size(112, 16);
  116.             this.label3.TabIndex = 8;
  117.             this.label3.Text = "Read/Write";
  118.             // label4
  119.             this.label4.Location = new System.Drawing.Point(24, 128);
  120.             this.label4.Name = "label4";
  121.             this.label4.Size = new System.Drawing.Size(136, 16);
  122.             this.label4.TabIndex = 9;
  123.             this.label4.Text = "DMA local Address (hex)";
  124.             // label5
  125.             this.label5.Location = new System.Drawing.Point(24, 176);
  126.             this.label5.Name = "label5";
  127.             this.label5.Size = new System.Drawing.Size(144, 16);
  128.             this.label5.TabIndex = 10;
  129.             this.label5.Text = "DMA buffer size (hex)";
  130.             // btSubmit
  131.             this.btSubmit.Location = new System.Drawing.Point(184, 56);
  132.             this.btSubmit.Name = "btSubmit";
  133.             this.btSubmit.TabIndex = 11;
  134.             this.btSubmit.Text = "Submit";
  135.             this.btSubmit.Click += new System.EventHandler(this.btSubmit_Click);
  136.             // btCancel
  137.             this.btCancel.DialogResult = 
  138.                 System.Windows.Forms.DialogResult.Cancel;
  139.             this.btCancel.Location = new System.Drawing.Point(184, 96);
  140.             this.btCancel.Name = "btCancel";
  141.             this.btCancel.TabIndex = 12;
  142.             this.btCancel.Text = "Cancel";
  143.             // groupBox1
  144.             this.groupBox1.Location = new System.Drawing.Point(168, 40);
  145.             this.groupBox1.Name = "groupBox1";
  146.             this.groupBox1.Size = new System.Drawing.Size(112, 88);
  147.             this.groupBox1.TabIndex = 13;
  148.             this.groupBox1.TabStop = false;
  149.             // label1
  150.             this.label1.Location = new System.Drawing.Point(24, 144);
  151.             this.label1.Name = "label1";
  152.             this.label1.Size = new System.Drawing.Size(16, 23);
  153.             this.label1.TabIndex = 14;
  154.             this.label1.Text = "0x";
  155.             // label2
  156.             this.label2.Location = new System.Drawing.Point(24, 192);
  157.             this.label2.Name = "label2";
  158.             this.label2.Size = new System.Drawing.Size(16, 23);
  159.             this.label2.TabIndex = 15;
  160.             this.label2.Text = "0x";
  161.             // chkBoxInc
  162.             this.chkBoxInc.Font = 
  163.                 new System.Drawing.Font("Microsoft Sans Serif", 8.25F,
  164.                     System.Drawing.FontStyle.Regular, 
  165.                     System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  166.             this.chkBoxInc.Location = new System.Drawing.Point(176, 160);
  167.             this.chkBoxInc.Name = "chkBoxInc";
  168.             this.chkBoxInc.TabIndex = 16;
  169.             this.chkBoxInc.Text = "AutoIncrement Address";
  170.             // OpenDMAForm
  171.             this.AcceptButton = this.btSubmit;
  172.             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  173.             this.CancelButton = this.btCancel;
  174.             this.ClientSize = new System.Drawing.Size(296, 229);
  175.             this.Controls.Add(this.chkBoxInc);
  176.             this.Controls.Add(this.label2);
  177.             this.Controls.Add(this.label1);
  178.             this.Controls.Add(this.btCancel);
  179.             this.Controls.Add(this.btSubmit);
  180.             this.Controls.Add(this.label5);
  181.             this.Controls.Add(this.label4);
  182.             this.Controls.Add(this.label3);
  183.             this.Controls.Add(this.lblAllocType);
  184.             this.Controls.Add(this.lblDmaOpen);
  185.             this.Controls.Add(this.txtBuffSize);
  186.             this.Controls.Add(this.txtLocalAddr);
  187.             this.Controls.Add(this.cmboAction);
  188.             this.Controls.Add(this.cmboAllocType);
  189.             this.Controls.Add(this.groupBox1);
  190.             this.Name = "OpenDMAForm";
  191.             this.StartPosition = 
  192.                 System.Windows.Forms.FormStartPosition.CenterScreen;
  193.             this.Text = "OpenDMA_Form";
  194.             this.ResumeLayout(false);
  195.         }
  196. #endregion
  197.         public bool GetInput(ref uint u32LocalAddr, ref RW direction, 
  198.             ref ALLOCATION_TYPE wAllocType, ref DWORD dwBytes, ref BOOL 
  199.             bAutoInc)                        
  200.         {
  201.             DialogResult result = DialogResult.Retry;
  202.             while((result = ShowDialog()) == DialogResult.Retry);
  203.             if (result != DialogResult.OK)
  204.                 return false;
  205.             u32LocalAddr = m_u32LocalAddr;
  206.             direction = m_direction;
  207.             wAllocType = m_wAllocType;
  208.             dwBytes = m_dwBytes;
  209.             bAutoInc = m_bAutoInc;
  210.             return true; 
  211.         }
  212.         private void btSubmit_Click(object sender, System.EventArgs e)
  213.         {
  214.             DialogResult = DialogResult.OK;
  215.             try
  216.             {
  217.                 TranslateInput();
  218.             }
  219.             catch 
  220.             {
  221.                 MessageBox.Show(m_excp.Message ,"Input Entry Error",
  222.                     MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  223.                 DialogResult = DialogResult.Retry;
  224.             }            
  225.         }
  226.         private void TranslateInput()
  227.         {
  228.             m_excp = new Exception("Select Allocation Type");
  229.             if((uint)cmboAllocType.SelectedIndex == 0xffffffff)
  230.                 throw m_excp;
  231.             m_wAllocType = (cmboAllocType.SelectedIndex == 0)?
  232.                 ALLOCATION_TYPE.SG: ALLOCATION_TYPE.CONTIG;
  233.             m_excp = new Exception("Select DMA direction");
  234.             if((uint)cmboAction.SelectedIndex == 0xffffffff)
  235.                 throw m_excp;
  236.             m_direction = (cmboAction.SelectedIndex == 0)?
  237.                 RW.READ : RW.WRITE;
  238.             m_excp = new Exception("Enter local DMA address. " + 
  239.                 "Entered value should be a hex number");
  240.             m_u32LocalAddr = (DWORD)Convert.ToInt32(txtLocalAddr.Text,16);
  241.             m_excp = new Exception("Enter the DMA buffer's size in bytes. " +
  242.                 "Entered value should be a hex number");
  243.             m_dwBytes = (DWORD)Convert.ToInt32(txtBuffSize.Text,16);
  244.             m_bAutoInc = chkBoxInc.Checked;
  245.         }                
  246.     }
  247. }