OpenDMAForm.cs
上传用户:huajielb
上传日期:2022-07-29
资源大小:626k
文件大小:12k
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using DWORD = System.UInt32;
- using WORD = System.UInt16;
- using BOOL = System.Boolean;
- using Jungo.wdapi_dotnet;
- using Jungo.plx_lib;
- namespace Jungo.PLX_Sample
- {
- public class OpenDMAForm : System.Windows.Forms.Form
- {
- private Exception m_excp;
- private uint m_u32LocalAddr;
- private RW m_direction;
- private ALLOCATION_TYPE m_wAllocType;
- private DWORD m_dwBytes;
- private BOOL m_bAutoInc;
- private System.Windows.Forms.ComboBox cmboAllocType;
- private System.Windows.Forms.TextBox txtLocalAddr;
- private System.Windows.Forms.TextBox txtBuffSize;
- private System.Windows.Forms.Label lblDmaOpen;
- private System.Windows.Forms.ComboBox cmboAction;
- private System.Windows.Forms.Label lblAllocType;
- private System.Windows.Forms.Label label3;
- private System.Windows.Forms.Label label4;
- private System.Windows.Forms.Label label5;
- private System.Windows.Forms.Button btSubmit;
- private System.Windows.Forms.Button btCancel;
- private System.Windows.Forms.GroupBox groupBox1;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.CheckBox chkBoxInc;
- private System.ComponentModel.Container components = null;
- public OpenDMAForm(PLX_DMA_CHANNEL channel)
- {
- InitializeComponent();
- lblDmaOpen.Text = (channel == 0)?
- "Open DMA - Channel 0":
- "Open DMA - Channel 1";
- cmboAllocType.Items.AddRange(new object[]{"Scatter Gather",
- "Contigious"});
- cmboAction.Items.AddRange(new object[]{"Read", "Write"});
- cmboAllocType.SelectedIndex = 0;
- cmboAction.SelectedIndex = 1;
- chkBoxInc.Checked = true;
- }
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows Form Designer generated code
- private void InitializeComponent()
- {
- this.cmboAllocType = new System.Windows.Forms.ComboBox();
- this.txtLocalAddr = new System.Windows.Forms.TextBox();
- this.txtBuffSize = new System.Windows.Forms.TextBox();
- this.lblDmaOpen = new System.Windows.Forms.Label();
- this.cmboAction = new System.Windows.Forms.ComboBox();
- this.lblAllocType = new System.Windows.Forms.Label();
- this.label3 = new System.Windows.Forms.Label();
- this.label4 = new System.Windows.Forms.Label();
- this.label5 = new System.Windows.Forms.Label();
- this.btSubmit = new System.Windows.Forms.Button();
- this.btCancel = new System.Windows.Forms.Button();
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.label1 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.chkBoxInc = new System.Windows.Forms.CheckBox();
- this.SuspendLayout();
- //
- // cmboAllocType
- //
- this.cmboAllocType.Location = new System.Drawing.Point(29, 52);
- this.cmboAllocType.Name = "cmboAllocType";
- this.cmboAllocType.Size = new System.Drawing.Size(145, 20);
- this.cmboAllocType.TabIndex = 0;
- this.cmboAllocType.Text = "------- -------";
- //
- // txtLocalAddr
- //
- this.txtLocalAddr.Location = new System.Drawing.Point(48, 155);
- this.txtLocalAddr.Name = "txtLocalAddr";
- this.txtLocalAddr.Size = new System.Drawing.Size(120, 21);
- this.txtLocalAddr.TabIndex = 3;
- //
- // txtBuffSize
- //
- this.txtBuffSize.Location = new System.Drawing.Point(48, 207);
- this.txtBuffSize.Name = "txtBuffSize";
- this.txtBuffSize.Size = new System.Drawing.Size(120, 21);
- this.txtBuffSize.TabIndex = 4;
- //
- // lblDmaOpen
- //
- this.lblDmaOpen.Location = new System.Drawing.Point(67, 9);
- this.lblDmaOpen.Name = "lblDmaOpen";
- this.lblDmaOpen.Size = new System.Drawing.Size(154, 24);
- this.lblDmaOpen.TabIndex = 5;
- this.lblDmaOpen.Text = "Open DMA - Channel 0";
- //
- // cmboAction
- //
- this.cmboAction.ItemHeight = 12;
- this.cmboAction.Location = new System.Drawing.Point(29, 103);
- this.cmboAction.Name = "cmboAction";
- this.cmboAction.Size = new System.Drawing.Size(145, 20);
- this.cmboAction.TabIndex = 2;
- this.cmboAction.Text = "------ ------";
- //
- // lblAllocType
- //
- this.lblAllocType.Location = new System.Drawing.Point(29, 34);
- this.lblAllocType.Name = "lblAllocType";
- this.lblAllocType.Size = new System.Drawing.Size(153, 18);
- this.lblAllocType.TabIndex = 6;
- this.lblAllocType.Text = "Allocation type";
- //
- // label3
- //
- this.label3.Location = new System.Drawing.Point(29, 86);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(134, 17);
- this.label3.TabIndex = 8;
- this.label3.Text = "Read/Write";
- //
- // label4
- //
- this.label4.Location = new System.Drawing.Point(29, 138);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(163, 17);
- this.label4.TabIndex = 9;
- this.label4.Text = "DMA local Address (hex)";
- //
- // label5
- //
- this.label5.Location = new System.Drawing.Point(29, 190);
- this.label5.Name = "label5";
- this.label5.Size = new System.Drawing.Size(173, 17);
- this.label5.TabIndex = 10;
- this.label5.Text = "DMA buffer size (hex)";
- //
- // btSubmit
- //
- this.btSubmit.Location = new System.Drawing.Point(221, 60);
- this.btSubmit.Name = "btSubmit";
- this.btSubmit.Size = new System.Drawing.Size(90, 25);
- this.btSubmit.TabIndex = 11;
- this.btSubmit.Text = "Submit";
- this.btSubmit.Click += new System.EventHandler(this.btSubmit_Click);
- //
- // btCancel
- //
- this.btCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
- this.btCancel.Location = new System.Drawing.Point(221, 103);
- this.btCancel.Name = "btCancel";
- this.btCancel.Size = new System.Drawing.Size(90, 25);
- this.btCancel.TabIndex = 12;
- this.btCancel.Text = "Cancel";
- //
- // groupBox1
- //
- this.groupBox1.Location = new System.Drawing.Point(202, 43);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(134, 95);
- this.groupBox1.TabIndex = 13;
- this.groupBox1.TabStop = false;
- //
- // label1
- //
- this.label1.Location = new System.Drawing.Point(29, 155);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(19, 25);
- this.label1.TabIndex = 14;
- this.label1.Text = "0x";
- //
- // label2
- //
- this.label2.Location = new System.Drawing.Point(29, 207);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(19, 25);
- this.label2.TabIndex = 15;
- this.label2.Text = "0x";
- //
- // chkBoxInc
- //
- this.chkBoxInc.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.chkBoxInc.Location = new System.Drawing.Point(211, 172);
- this.chkBoxInc.Name = "chkBoxInc";
- this.chkBoxInc.Size = new System.Drawing.Size(125, 26);
- this.chkBoxInc.TabIndex = 16;
- this.chkBoxInc.Text = "AutoIncrement Address";
- //
- // OpenDMAForm
- //
- this.AcceptButton = this.btSubmit;
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.CancelButton = this.btCancel;
- this.ClientSize = new System.Drawing.Size(358, 267);
- this.Controls.Add(this.chkBoxInc);
- this.Controls.Add(this.label2);
- this.Controls.Add(this.label1);
- this.Controls.Add(this.btCancel);
- this.Controls.Add(this.btSubmit);
- this.Controls.Add(this.label5);
- this.Controls.Add(this.label4);
- this.Controls.Add(this.label3);
- this.Controls.Add(this.lblAllocType);
- this.Controls.Add(this.lblDmaOpen);
- this.Controls.Add(this.txtBuffSize);
- this.Controls.Add(this.txtLocalAddr);
- this.Controls.Add(this.cmboAction);
- this.Controls.Add(this.cmboAllocType);
- this.Controls.Add(this.groupBox1);
- this.Name = "OpenDMAForm";
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "OpenDMA_Form";
- this.Load += new System.EventHandler(this.OpenDMAForm_Load);
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- #endregion
- public bool GetInput(ref uint u32LocalAddr, ref RW direction,
- ref ALLOCATION_TYPE wAllocType, ref DWORD dwBytes, ref BOOL
- bAutoInc)
- {
- DialogResult result = DialogResult.Retry;
- while((result = ShowDialog()) == DialogResult.Retry);
- if (result != DialogResult.OK)
- return false;
- u32LocalAddr = m_u32LocalAddr;
- direction = m_direction;
- wAllocType = m_wAllocType;
- dwBytes = m_dwBytes;
- bAutoInc = m_bAutoInc;
- return true;
- }
- private void btSubmit_Click(object sender, System.EventArgs e)
- {
- DialogResult = DialogResult.OK;
- try
- {
- TranslateInput();
- }
- catch
- {
- MessageBox.Show(m_excp.Message ,"Input Entry Error",
- MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- DialogResult = DialogResult.Retry;
- }
- }
- private void TranslateInput()
- {
- m_excp = new Exception("Select Allocation Type");
- if((uint)cmboAllocType.SelectedIndex == 0xffffffff)
- throw m_excp;
- m_wAllocType = (cmboAllocType.SelectedIndex == 0)?
- ALLOCATION_TYPE.SG: ALLOCATION_TYPE.CONTIG;
- m_excp = new Exception("Select DMA direction");
- if((uint)cmboAction.SelectedIndex == 0xffffffff)
- throw m_excp;
- m_direction = (cmboAction.SelectedIndex == 0)?
- RW.READ : RW.WRITE;
- m_excp = new Exception("Enter local DMA address. " +
- "Entered value should be a hex number");
- m_u32LocalAddr = (DWORD)Convert.ToInt32(txtLocalAddr.Text,16);
- m_excp = new Exception("Enter the DMA buffer's size in bytes. " +
- "Entered value should be a hex number");
- m_dwBytes = (DWORD)Convert.ToInt32(txtBuffSize.Text,16);
-
- m_bAutoInc = chkBoxInc.Checked;
- }
- private void OpenDMAForm_Load(object sender, EventArgs e)
- {
-
- }
- }
- }