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

驱动编程

开发平台:

Visual C++

  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Drawing;
  4. using System.Collections;
  5. using System.ComponentModel;
  6. using System.Windows.Forms;
  7. using Jungo.wdapi_dotnet;
  8. using Jungo.plx_lib;
  9. using wdc_err = Jungo.wdapi_dotnet.WD_ERROR_CODES;    
  10. using BOOL = System.Boolean;
  11. using BYTE = System.Byte;
  12. using WORD = System.UInt16;
  13. using DWORD = System.UInt32;
  14. using UINT32 = System.UInt32;
  15. using UINT64 = System.UInt64;
  16. namespace Jungo.PLX_Sample
  17. {
  18.     public class AddrSpaceTransferForm : System.Windows.Forms.Form
  19.     {
  20.         private Exception m_excp;
  21.         private PLX_Device m_device;
  22.         private bool m_bIsLocal;
  23.         private object[] m_obj;
  24.         private RW m_direction;
  25.         private DWORD m_dwBar;
  26.         private WDC_ADDR_MODE m_mode;
  27.         private DWORD m_dwBytes;
  28.         private TRANSFER_TYPE m_type;
  29.         private DWORD m_dwOffset;
  30.         private bool m_bAutoInc;
  31.         private byte[] m_bData;
  32.         private WORD[] m_wData;
  33.         private UINT32[] m_u32Data;
  34.         private UINT64[] m_u64Data;
  35.         private System.Windows.Forms.ComboBox cmboBar;
  36.         private System.Windows.Forms.ComboBox cmboMode;
  37.         private System.Windows.Forms.TextBox txtOffset;
  38.         private System.Windows.Forms.ComboBox cmboTransType;
  39.         private System.Windows.Forms.TextBox txtNumBytes;
  40.         private System.Windows.Forms.Label lblNumBytes;
  41.         private System.Windows.Forms.Label lblOffset;
  42.         private System.Windows.Forms.GroupBox groupBox1;
  43.         private System.Windows.Forms.Label lblBar;
  44.         private System.Windows.Forms.Label lblTransType;
  45.         private System.Windows.Forms.Label label3;
  46.         private System.Windows.Forms.TextBox txtData;
  47.         private System.Windows.Forms.Button btExit;
  48.         private System.Windows.Forms.GroupBox groupBox2;
  49.         private System.Windows.Forms.CheckBox chkBoxInc;
  50.         private System.Windows.Forms.Label label1;
  51.         private System.Windows.Forms.Label label2;
  52.         private System.Windows.Forms.TextBox txtInput;
  53.         private System.Windows.Forms.Button btWrite;
  54.         private System.Windows.Forms.Button btLog;
  55.         private System.Windows.Forms.Button btRead;
  56.         private System.Windows.Forms.Label label4;
  57.         private System.Windows.Forms.Label label5;
  58.         private System.ComponentModel.Container components = null;
  59.         public AddrSpaceTransferForm(PLX_Device dev, string[] sBars, 
  60.             bool bIsLocal)
  61.         {
  62.             InitializeComponent();
  63.             m_device = dev;
  64.             m_bIsLocal = bIsLocal;
  65.             for(int i=0; i<sBars.Length; ++i)
  66.             {
  67.                 cmboBar.Items.Add(sBars[i]);
  68.             }
  69.             this.Text = "Read/Write Address Space" + 
  70.                 (m_bIsLocal? " through Local Bus" : "") + " Form";
  71.             cmboMode.Items.AddRange(new object[]{"8 bits", "16 bits", "32 bits", "64 bits"});
  72.             cmboTransType.Items.AddRange(new object[]{"block", "non-block"});
  73.             chkBoxInc.Enabled = false;
  74.             txtNumBytes.Enabled = false;
  75.         }
  76.         protected override void Dispose( bool disposing )
  77.         {
  78.             if( disposing )
  79.             {
  80.                 if(components != null)
  81.                 {
  82.                     components.Dispose();
  83.                 }
  84.             }
  85.             base.Dispose( disposing );
  86.         }
  87. #region Windows Form Designer generated code
  88.         private void InitializeComponent()
  89.         {
  90.             this.cmboBar = new System.Windows.Forms.ComboBox();
  91.             this.cmboMode = new System.Windows.Forms.ComboBox();
  92.             this.txtOffset = new System.Windows.Forms.TextBox();
  93.             this.cmboTransType = new System.Windows.Forms.ComboBox();
  94.             this.txtNumBytes = new System.Windows.Forms.TextBox();
  95.             this.lblNumBytes = new System.Windows.Forms.Label();
  96.             this.lblOffset = new System.Windows.Forms.Label();
  97.             this.txtData = new System.Windows.Forms.TextBox();
  98.             this.btRead = new System.Windows.Forms.Button();
  99.             this.btExit = new System.Windows.Forms.Button();
  100.             this.groupBox1 = new System.Windows.Forms.GroupBox();
  101.             this.btLog = new System.Windows.Forms.Button();
  102.             this.btWrite = new System.Windows.Forms.Button();
  103.             this.lblBar = new System.Windows.Forms.Label();
  104.             this.lblTransType = new System.Windows.Forms.Label();
  105.             this.label3 = new System.Windows.Forms.Label();
  106.             this.chkBoxInc = new System.Windows.Forms.CheckBox();
  107.             this.groupBox2 = new System.Windows.Forms.GroupBox();
  108.             this.label1 = new System.Windows.Forms.Label();
  109.             this.label2 = new System.Windows.Forms.Label();
  110.             this.txtInput = new System.Windows.Forms.TextBox();
  111.             this.label4 = new System.Windows.Forms.Label();
  112.             this.label5 = new System.Windows.Forms.Label();
  113.             this.groupBox1.SuspendLayout();
  114.             this.groupBox2.SuspendLayout();
  115.             this.SuspendLayout();
  116.             // cmboBar
  117.             this.cmboBar.Font = new System.Drawing.Font("Microsoft Sans Serif", 
  118.                 8.25F, System.Drawing.FontStyle.Regular,                
  119.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  120.             this.cmboBar.Location = new System.Drawing.Point(8, 32);
  121.             this.cmboBar.Name = "cmboBar";
  122.             this.cmboBar.Size = new System.Drawing.Size(280, 21);
  123.             this.cmboBar.TabIndex = 0;
  124.             this.cmboBar.Text = "---- ----";
  125.             // cmboMode
  126.             this.cmboMode.Font = new System.Drawing.Font("Microsoft Sans Serif",
  127.                 8.25F, System.Drawing.FontStyle.Regular,
  128.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  129.             this.cmboMode.Location = new System.Drawing.Point(8, 96);
  130.             this.cmboMode.Name = "cmboMode";
  131.             this.cmboMode.Size = new System.Drawing.Size(121, 21);
  132.             this.cmboMode.TabIndex = 1;
  133.             this.cmboMode.Text = "---- ----";
  134.             // txtOffset
  135.             this.txtOffset.Font = new System.Drawing.Font("Microsoft Sans Serif",
  136.                 8.25F, System.Drawing.FontStyle.Regular, 
  137.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  138.             this.txtOffset.Location = new System.Drawing.Point(24, 160);
  139.             this.txtOffset.Name = "txtOffset";
  140.             this.txtOffset.TabIndex = 5;
  141.             this.txtOffset.Text = "";
  142.             // cmboTransType
  143.             this.cmboTransType.Font = new System.Drawing.Font("Microsoft Sans Serif",
  144.                 8.25F, System.Drawing.FontStyle.Regular, 
  145.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  146.             this.cmboTransType.ItemHeight = 13;
  147.             this.cmboTransType.Location = new System.Drawing.Point(168, 96);
  148.             this.cmboTransType.Name = "cmboTransType";
  149.             this.cmboTransType.Size = new System.Drawing.Size(104, 21);
  150.             this.cmboTransType.TabIndex = 2;
  151.             this.cmboTransType.Text = "---- ----";
  152.             this.cmboTransType.SelectedIndexChanged += 
  153.                 new System.EventHandler(this.cmboTransType_SelectedIndexChanged);
  154.             // txtNumBytes
  155.             this.txtNumBytes.Font = new System.Drawing.Font("Microsoft Sans Serif",
  156.                 8.25F, System.Drawing.FontStyle.Regular,
  157.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  158.             this.txtNumBytes.Location = new System.Drawing.Point(336, 48);
  159.             this.txtNumBytes.Name = "txtNumBytes";
  160.             this.txtNumBytes.TabIndex = 3;
  161.             this.txtNumBytes.Text = "";
  162.             // lblNumBytes
  163.             this.lblNumBytes.Font = new System.Drawing.Font("Microsoft Sans Serif",
  164.                 8.25F, System.Drawing.FontStyle.Regular,
  165.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  166.             this.lblNumBytes.Location = new System.Drawing.Point(328, 24);
  167.             this.lblNumBytes.Name = "lblNumBytes";
  168.             this.lblNumBytes.Size = new System.Drawing.Size(120, 23);
  169.             this.lblNumBytes.TabIndex = 5;
  170.             this.lblNumBytes.Text = "Number of Bytes (hex):";
  171.             // lblOffset
  172.             this.lblOffset.Font = new System.Drawing.Font("Microsoft Sans Serif",
  173.                 8.25F, System.Drawing.FontStyle.Regular, 
  174.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  175.             this.lblOffset.Location = new System.Drawing.Point(8, 136);
  176.             this.lblOffset.Name = "lblOffset";
  177.             this.lblOffset.TabIndex = 6;
  178.             this.lblOffset.Text = "Offset (hex):";
  179.             // txtData
  180.             this.txtData.AutoSize = false;
  181.             this.txtData.Font = new System.Drawing.Font("Microsoft Sans Serif",
  182.                 8.25F, System.Drawing.FontStyle.Regular, 
  183.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  184.             this.txtData.Location = new System.Drawing.Point(32, 192);
  185.             this.txtData.Multiline = true;
  186.             this.txtData.Name = "txtData";
  187.             this.txtData.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
  188.             this.txtData.Size = new System.Drawing.Size(480, 136);
  189.             this.txtData.TabIndex = 15;
  190.             this.txtData.Text = "";
  191.             // btRead
  192.             this.btRead.Font = new System.Drawing.Font("Microsoft Sans Serif",
  193.                 8.25F, System.Drawing.FontStyle.Regular, 
  194.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  195.             this.btRead.Location = new System.Drawing.Point(488, 24);
  196.             this.btRead.Name = "btRead";
  197.             this.btRead.TabIndex = 7;
  198.             this.btRead.Text = "Read";
  199.             this.btRead.Click += new System.EventHandler(this.btRead_Click);
  200.             // btExit
  201.             this.btExit.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  202.             this.btExit.Font = new System.Drawing.Font("Microsoft Sans Serif",
  203.                 8.25F, System.Drawing.FontStyle.Regular, 
  204.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  205.             this.btExit.Location = new System.Drawing.Point(24, 136);
  206.             this.btExit.Name = "btExit";
  207.             this.btExit.TabIndex = 11;
  208.             this.btExit.Text = "Exit";
  209.             // groupBox1
  210.             this.groupBox1.Controls.Add(this.btLog);
  211.             this.groupBox1.Controls.Add(this.btWrite);
  212.             this.groupBox1.Controls.Add(this.btExit);
  213.             this.groupBox1.Location = new System.Drawing.Point(464, 8);
  214.             this.groupBox1.Name = "groupBox1";
  215.             this.groupBox1.Size = new System.Drawing.Size(120, 168);
  216.             this.groupBox1.TabIndex = 10;
  217.             this.groupBox1.TabStop = false;
  218.             // btLog
  219.             this.btLog.Font = new System.Drawing.Font("Microsoft Sans Serif",
  220.                 8.25F, System.Drawing.FontStyle.Regular, 
  221.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  222.             this.btLog.Location = new System.Drawing.Point(23, 96);
  223.             this.btLog.Name = "btLog";
  224.             this.btLog.TabIndex = 9;
  225.             this.btLog.Text = "Clear Log";
  226.             this.btLog.Click += new System.EventHandler(this.btLog_Click);
  227.             // btWrite
  228.             this.btWrite.Font = new System.Drawing.Font("Microsoft Sans Serif",
  229.                 8.25F, System.Drawing.FontStyle.Regular, 
  230.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  231.             this.btWrite.Location = new System.Drawing.Point(24, 56);
  232.             this.btWrite.Name = "btWrite";
  233.             this.btWrite.TabIndex = 8;
  234.             this.btWrite.Text = "Write";
  235.             this.btWrite.Click += new System.EventHandler(this.btWrite_Click);
  236.             // lblBar
  237.             this.lblBar.Font = new System.Drawing.Font("Microsoft Sans Serif",
  238.                 8.25F, System.Drawing.FontStyle.Regular, 
  239.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  240.             this.lblBar.Location = new System.Drawing.Point(8, 8);
  241.             this.lblBar.Name = "lblBar";
  242.             this.lblBar.Size = new System.Drawing.Size(120, 23);
  243.             this.lblBar.TabIndex = 11;
  244.             this.lblBar.Text = "Address Bar";
  245.             // lblTransType
  246.             this.lblTransType.Font = new System.Drawing.Font("Microsoft Sans Serif",
  247.                 8.25F, System.Drawing.FontStyle.Regular, 
  248.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  249.             this.lblTransType.Location = new System.Drawing.Point(168, 72);
  250.             this.lblTransType.Name = "lblTransType";
  251.             this.lblTransType.Size = new System.Drawing.Size(120, 23);
  252.             this.lblTransType.TabIndex = 12;
  253.             this.lblTransType.Text = "Transfer Type";
  254.             // label3
  255.             this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif",
  256.                 8.25F, System.Drawing.FontStyle.Regular, 
  257.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  258.             this.label3.Location = new System.Drawing.Point(8, 72);
  259.             this.label3.Name = "label3";
  260.             this.label3.Size = new System.Drawing.Size(120, 23);
  261.             this.label3.TabIndex = 13;
  262.             this.label3.Text = "Transfer Mode";
  263.             // chkBoxInc
  264.             this.chkBoxInc.Font = new System.Drawing.Font("Microsoft Sans Serif",
  265.                 8.25F, System.Drawing.FontStyle.Regular, 
  266.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  267.             this.chkBoxInc.Location = new System.Drawing.Point(328, 80);
  268.             this.chkBoxInc.Name = "chkBoxInc";
  269.             this.chkBoxInc.TabIndex = 4;
  270.             this.chkBoxInc.Text = "AutoIncrement Address";
  271.             // groupBox2
  272.             this.groupBox2.Controls.Add(this.label1);
  273.             this.groupBox2.Font = new System.Drawing.Font("Microsoft Sans Serif",
  274.                 9F, System.Drawing.FontStyle.Italic, 
  275.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  276.             this.groupBox2.Location = new System.Drawing.Point(304, 8);
  277.             this.groupBox2.Name = "groupBox2";
  278.             this.groupBox2.Size = new System.Drawing.Size(152, 104);
  279.             this.groupBox2.TabIndex = 15;
  280.             this.groupBox2.TabStop = false;
  281.             this.groupBox2.Text = "Block Transfer Options";
  282.             // label1
  283.             this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif",
  284.                 8.25F, System.Drawing.FontStyle.Regular, 
  285.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  286.             this.label1.Location = new System.Drawing.Point(16, 40);
  287.             this.label1.Name = "label1";
  288.             this.label1.Size = new System.Drawing.Size(16, 23);
  289.             this.label1.TabIndex = 16;
  290.             this.label1.Text = "0x";
  291.             // label2
  292.             this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif",
  293.                 8.25F, System.Drawing.FontStyle.Regular, 
  294.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  295.             this.label2.Location = new System.Drawing.Point(8, 160);
  296.             this.label2.Name = "label2";
  297.             this.label2.Size = new System.Drawing.Size(16, 23);
  298.             this.label2.TabIndex = 16;
  299.             this.label2.Text = "0x";
  300.             // txtInput
  301.             this.txtInput.Font = new System.Drawing.Font("Microsoft Sans Serif",
  302.                 8.25F, System.Drawing.FontStyle.Regular, 
  303.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  304.             this.txtInput.Location = new System.Drawing.Point(160, 160);
  305.             this.txtInput.Name = "txtInput";
  306.             this.txtInput.Size = new System.Drawing.Size(288, 20);
  307.             this.txtInput.TabIndex = 6;
  308.             this.txtInput.Text = "";
  309.             // label4
  310.             this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif",
  311.                 8.25F, System.Drawing.FontStyle.Regular, 
  312.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  313.             this.label4.Location = new System.Drawing.Point(144, 160);
  314.             this.label4.Name = "label4";
  315.             this.label4.Size = new System.Drawing.Size(16, 23);
  316.             this.label4.TabIndex = 18;
  317.             this.label4.Text = "0x";
  318.             // label5
  319.             this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif",
  320.                 8.25F, System.Drawing.FontStyle.Regular, 
  321.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  322.             this.label5.Location = new System.Drawing.Point(160, 128);
  323.             this.label5.Name = "label5";
  324.             this.label5.Size = new System.Drawing.Size(280, 32);
  325.             this.label5.TabIndex = 19;
  326.             this.label5.Text = "Input for Write Transactions (hex):  For Block "
  327.                 + "transfer, please enter in little endian mode";
  328.             // AddrSpaceTransferForm
  329.             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  330.             this.ClientSize = new System.Drawing.Size(600, 341);
  331.             this.Controls.Add(this.label5);
  332.             this.Controls.Add(this.label4);
  333.             this.Controls.Add(this.txtInput);
  334.             this.Controls.Add(this.label2);
  335.             this.Controls.Add(this.chkBoxInc);
  336.             this.Controls.Add(this.cmboMode);
  337.             this.Controls.Add(this.label3);
  338.             this.Controls.Add(this.lblTransType);
  339.             this.Controls.Add(this.lblBar);
  340.             this.Controls.Add(this.btRead);
  341.             this.Controls.Add(this.txtData);
  342.             this.Controls.Add(this.lblOffset);
  343.             this.Controls.Add(this.lblNumBytes);
  344.             this.Controls.Add(this.txtNumBytes);
  345.             this.Controls.Add(this.txtOffset);
  346.             this.Controls.Add(this.cmboTransType);
  347.             this.Controls.Add(this.cmboBar);
  348.             this.Controls.Add(this.groupBox1);
  349.             this.Controls.Add(this.groupBox2);
  350.             this.Font = new System.Drawing.Font("Microsoft Sans Serif",
  351.                 8.25F, System.Drawing.FontStyle.Italic, 
  352.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  353.             this.Name = "AddrSpaceTransferForm";
  354.             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  355.             this.Text = "Read/Write Address Space Form";
  356.             this.groupBox1.ResumeLayout(false);
  357.             this.groupBox2.ResumeLayout(false);
  358.             this.ResumeLayout(false);
  359.         }
  360. #endregion
  361.         public bool GetInput()
  362.         {            
  363.             m_obj = new object[1];
  364.             DialogResult result = DialogResult.Retry;
  365.             while((result = ShowDialog()) == DialogResult.Retry);
  366.             return true;
  367.         }
  368.         private void btRead_Click(object sender, System.EventArgs e)
  369.         {
  370.             m_direction = RW.READ;
  371.             btClick();            
  372.         }
  373.         private void btWrite_Click(object sender, System.EventArgs e)
  374.         {
  375.             m_direction = RW.WRITE;
  376.             btClick();                
  377.         }
  378.         private void btClick()
  379.         {
  380.             DialogResult = DialogResult.None;
  381.             try
  382.             {
  383.                 TranslateInput();
  384.             }
  385.             catch 
  386.             {
  387.                 MessageBox.Show(m_excp.Message, "Input Entry Error",
  388.                     MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  389.                 DialogResult = DialogResult.Retry;
  390.                 return;
  391.             } 
  392.             if(m_bIsLocal)
  393.                 ReadWriteLocalBus();
  394.             else
  395.                 ReadWriteAddrSpace();    
  396.         }
  397.         private void ReadWriteAddrSpace()
  398.         {
  399.             DWORD dwStatus = 0;
  400.             BOOL bIsBlock = (m_type == TRANSFER_TYPE.BLOCK);
  401.             BOOL bIsRead = (m_direction == RW.READ);
  402.             WDC_ADDR_RW_OPTIONS dwOptions = (m_bAutoInc ? 
  403.                 WDC_ADDR_RW_OPTIONS.WDC_ADDR_RW_DEFAULT : 
  404.                 WDC_ADDR_RW_OPTIONS.WDC_ADDR_RW_NO_AUTOINC);
  405.             DWORD dwFloorBytes = ((DWORD)(m_dwBytes / (DWORD)m_mode)) * 
  406.                 (DWORD)m_mode;
  407.             switch(m_mode)
  408.             {
  409.             case WDC_ADDR_MODE.WDC_MODE_8:
  410.                 {
  411.                     if(bIsRead)
  412.                         dwStatus = bIsBlock ? 
  413.                             wdc_lib_decl.WDC_ReadAddrBlock(m_device.Handle, 
  414.                                 m_dwBar, m_dwOffset, dwFloorBytes, m_bData,
  415.                                 m_mode, dwOptions) :
  416.                             wdc_lib_decl.WDC_ReadAddr8(m_device.Handle, 
  417.                                 m_dwBar, m_dwOffset, ref m_bData[0]);
  418.                     else
  419.                         dwStatus = bIsBlock?
  420.                             wdc_lib_decl.WDC_WriteAddrBlock(m_device.Handle, 
  421.                                 m_dwBar, m_dwOffset, dwFloorBytes, m_bData, 
  422.                                 m_mode, dwOptions) :
  423.                             wdc_lib_decl.WDC_WriteAddr8(m_device.Handle,
  424.                                 m_dwBar, m_dwOffset, m_bData[0]);
  425.                     m_obj[0] = m_bData; 
  426.                     break;
  427.                 }
  428.             case WDC_ADDR_MODE.WDC_MODE_16:
  429.                 {
  430.                     if(bIsRead)
  431.                         dwStatus = bIsBlock ? 
  432.                             wdc_lib_decl.WDC_ReadAddrBlock(m_device.Handle, 
  433.                                 m_dwBar, m_dwOffset, dwFloorBytes, m_wData, 
  434.                                 m_mode, dwOptions) :
  435.                             wdc_lib_decl.WDC_ReadAddr16(m_device.Handle, 
  436.                                 m_dwBar, m_dwOffset, ref m_wData[0]);
  437.                     else
  438.                         dwStatus = bIsBlock?
  439.                             wdc_lib_decl.WDC_WriteAddrBlock(m_device.Handle, 
  440.                                 m_dwBar, m_dwOffset, dwFloorBytes, m_wData, 
  441.                                 m_mode, dwOptions) :
  442.                             wdc_lib_decl.WDC_WriteAddr16(m_device.Handle, 
  443.                                 m_dwBar, m_dwOffset, m_wData[0]);
  444.                     m_obj[0] = m_wData; 
  445.                     break;
  446.                 }
  447.             case WDC_ADDR_MODE.WDC_MODE_32:
  448.                 {
  449.                     if(bIsRead)
  450.                         dwStatus = bIsBlock ? 
  451.                             wdc_lib_decl.WDC_ReadAddrBlock(m_device.Handle,
  452.                                 m_dwBar, m_dwOffset, dwFloorBytes, m_u32Data,
  453.                                 m_mode, dwOptions) :
  454.                             wdc_lib_decl.WDC_ReadAddr32(m_device.Handle, 
  455.                                 m_dwBar, m_dwOffset, ref m_u32Data[0]);
  456.                     else
  457.                         dwStatus = bIsBlock?
  458.                             wdc_lib_decl.WDC_WriteAddrBlock(m_device.Handle, 
  459.                                 m_dwBar, m_dwOffset, dwFloorBytes, m_u32Data,
  460.                                 m_mode, dwOptions) :
  461.                             wdc_lib_decl.WDC_WriteAddr32(m_device.Handle, 
  462.                                 m_dwBar, m_dwOffset, m_u32Data[0]);
  463.                     m_obj[0] = m_u32Data; 
  464.                     break;
  465.                 }
  466.             case WDC_ADDR_MODE.WDC_MODE_64:
  467.                 {
  468.                     if(bIsRead)
  469.                         dwStatus = bIsBlock ? 
  470.                             wdc_lib_decl.WDC_ReadAddrBlock(m_device.Handle, 
  471.                                 m_dwBar, m_dwOffset, dwFloorBytes, m_u64Data,
  472.                                 m_mode, dwOptions) :
  473.                             wdc_lib_decl.WDC_ReadAddr64(m_device.Handle, 
  474.                                 m_dwBar, m_dwOffset, ref m_u64Data[0]);
  475.                     else
  476.                         dwStatus = bIsBlock?
  477.                             wdc_lib_decl.WDC_WriteAddrBlock(m_device.Handle, 
  478.                                 m_dwBar, m_dwOffset, dwFloorBytes, m_u64Data,
  479.                                 m_mode, dwOptions) :
  480.                             wdc_lib_decl.WDC_WriteAddr64(m_device.Handle, 
  481.                                 m_dwBar, m_dwOffset, m_u64Data[0]);
  482.                     m_obj[0] = m_u64Data; 
  483.                     break;
  484.                 }
  485.             }
  486.             TraceLog(bIsRead, (wdc_err)dwStatus);            
  487.         }
  488.         private void ReadWriteLocalBus()
  489.         {
  490.             DWORD dwStatus = 0;
  491.             BOOL bIsBlock = (m_type == TRANSFER_TYPE.BLOCK);
  492.             BOOL bIsRead = (m_direction == RW.READ);
  493.             WDC_ADDR_RW_OPTIONS dwOptions = (m_bAutoInc ? 
  494.                 WDC_ADDR_RW_OPTIONS.WDC_ADDR_RW_DEFAULT : 
  495.                 WDC_ADDR_RW_OPTIONS.WDC_ADDR_RW_NO_AUTOINC);
  496.             DWORD dwFloorBytes = ((DWORD)(m_dwBytes / (DWORD)m_mode)) * 
  497.                 (DWORD)m_mode;
  498.             switch(m_mode)
  499.             {
  500.             case WDC_ADDR_MODE.WDC_MODE_8:
  501.                 {
  502.                     if(bIsRead)
  503.                         dwStatus = bIsBlock ? 
  504.                             m_device.ReadAddrLocalBlock((PLX_ADDR)m_dwBar,
  505.                                 m_dwOffset, dwFloorBytes, m_bData, m_mode, 
  506.                                 dwOptions) :
  507.                             m_device.ReadAddrLocal8((PLX_ADDR)m_dwBar,
  508.                                 m_dwOffset, ref m_bData[0]);
  509.                     else
  510.                         dwStatus = bIsBlock?
  511.                             m_device.WriteAddrLocalBlock((PLX_ADDR)m_dwBar,
  512.                                 m_dwOffset, dwFloorBytes, m_bData, m_mode,
  513.                                 dwOptions) :
  514.                             m_device.WriteAddrLocal8((PLX_ADDR)m_dwBar, 
  515.                                 m_dwOffset, m_bData[0]);
  516.                     m_obj[0] = m_bData; 
  517.                     break;
  518.                 }
  519.             case WDC_ADDR_MODE.WDC_MODE_16:
  520.                 {
  521.                     if(bIsRead)
  522.                         dwStatus = bIsBlock ? 
  523.                             m_device.ReadAddrLocalBlock((PLX_ADDR)m_dwBar, 
  524.                                 m_dwOffset, dwFloorBytes, m_wData, m_mode, 
  525.                                 dwOptions) :
  526.                             m_device.ReadAddrLocal16((PLX_ADDR)m_dwBar, 
  527.                                 m_dwOffset, ref m_wData[0]);
  528.                     else
  529.                         dwStatus = bIsBlock?
  530.                             m_device.WriteAddrLocalBlock((PLX_ADDR)m_dwBar, 
  531.                                 m_dwOffset, dwFloorBytes, m_wData, m_mode,
  532.                                 dwOptions) :
  533.                             m_device.WriteAddrLocal16((PLX_ADDR)m_dwBar, 
  534.                                 m_dwOffset, m_wData[0]);
  535.                     m_obj[0] = m_wData; 
  536.                     break;
  537.                 }
  538.             case WDC_ADDR_MODE.WDC_MODE_32:
  539.                 {
  540.                     if(bIsRead)
  541.                         dwStatus = bIsBlock ? 
  542.                             m_device.ReadAddrLocalBlock((PLX_ADDR)m_dwBar, 
  543.                                 m_dwOffset, dwFloorBytes, m_u32Data, m_mode,
  544.                                 dwOptions) :
  545.                             m_device.ReadAddrLocal32((PLX_ADDR)m_dwBar, 
  546.                                 m_dwOffset, ref m_u32Data[0]);
  547.                     else
  548.                         dwStatus = bIsBlock?
  549.                             m_device.WriteAddrLocalBlock((PLX_ADDR)m_dwBar,
  550.                                 m_dwOffset, dwFloorBytes, m_u32Data, m_mode,
  551.                                 dwOptions) :
  552.                             m_device.WriteAddrLocal32((PLX_ADDR)m_dwBar, 
  553.                                 m_dwOffset, m_u32Data[0]);
  554.                     m_obj[0] = m_u32Data; 
  555.                     break;
  556.                 }
  557.             case WDC_ADDR_MODE.WDC_MODE_64:
  558.                 {
  559.                     if(bIsRead)
  560.                         dwStatus = bIsBlock ? 
  561.                             m_device.ReadAddrLocalBlock((PLX_ADDR)m_dwBar, 
  562.                                 m_dwOffset, dwFloorBytes, m_u64Data, m_mode, 
  563.                                 dwOptions) :
  564.                             m_device.ReadAddrLocal64((PLX_ADDR)m_dwBar, 
  565.                                 m_dwOffset, ref m_u64Data[0]);
  566.                     else
  567.                         dwStatus = bIsBlock?
  568.                             m_device.WriteAddrLocalBlock((PLX_ADDR)m_dwBar, 
  569.                                 m_dwOffset, dwFloorBytes, m_u64Data, m_mode,
  570.                                 dwOptions) :
  571.                             m_device.WriteAddrLocal64((PLX_ADDR)m_dwBar, 
  572.                                 m_dwOffset, m_u64Data[0]);
  573.                     m_obj[0] = m_u64Data; 
  574.                     break;
  575.                 }
  576.             }
  577.             TraceLog(bIsRead, (wdc_err)dwStatus);            
  578.         }
  579.         private void TranslateInput()
  580.         {
  581.             string str = "";
  582.             m_excp = new Exception("Choose a BAR");
  583.             if((uint)cmboBar.SelectedIndex == 0xffffffff)
  584.                 throw m_excp;
  585.             m_dwBar = (DWORD)cmboBar.SelectedIndex + (DWORD)(m_bIsLocal?
  586.                 PLX_ADDR.PLX_ADDR_SPACE0 : PLX_ADDR.PLX_ADDR_REG);    
  587.             m_excp = new Exception("Choose the Transfer Mode");
  588.             uint uiModeIndex = (uint)cmboMode.SelectedIndex;
  589.             if(uiModeIndex == 0xffffffff)
  590.                 throw m_excp;
  591.             m_mode = (uiModeIndex == 0)? WDC_ADDR_MODE.WDC_MODE_8: 
  592.                 (uiModeIndex == 1)? WDC_ADDR_MODE.WDC_MODE_16:
  593.                 (uiModeIndex == 2)? WDC_ADDR_MODE.WDC_MODE_32:
  594.                 WDC_ADDR_MODE.WDC_MODE_64;
  595.             m_excp = new Exception("Choose the Transfer Type");
  596.             if((uint)cmboTransType.SelectedIndex == 0xffffffff)
  597.                 throw m_excp;
  598.             m_type = (cmboTransType.SelectedIndex == 0)?
  599.             TRANSFER_TYPE.BLOCK : TRANSFER_TYPE.NONBLOCK;
  600.             if(txtNumBytes.Enabled == true)
  601.             {
  602.                 int iBarIndex = (int)m_dwBar - 
  603.                     (int)(m_bIsLocal? PLX_ADDR.PLX_ADDR_SPACE0 : PLX_ADDR.PLX_ADDR_REG); 
  604.                 m_excp = new Exception("Please enter the number of bytes. " +
  605.                     "Entered value should be a hex number." + 
  606.                     Environment.NewLine + " (Maximum value: 0x" +
  607.                     m_device.AddrDesc[iBarIndex].dwBytes.ToString("X") + ")");
  608.                 m_dwBytes = Convert.ToUInt32(txtNumBytes.Text,16);
  609.                 if(m_dwBytes > m_device.AddrDesc[iBarIndex].dwBytes)
  610.                     throw m_excp;
  611.             }
  612.             else 
  613.                 m_dwBytes = (DWORD)((m_mode == WDC_ADDR_MODE.WDC_MODE_8) ? 1 :
  614.                     ((m_mode == WDC_ADDR_MODE.WDC_MODE_16) ? 2 :
  615.                     ((m_mode == WDC_ADDR_MODE.WDC_MODE_32) ? 4 : 8)));
  616.             if(chkBoxInc.Enabled == true)
  617.                 m_bAutoInc = chkBoxInc.Checked;
  618.             m_excp = new Exception("Please enter the offset. " +
  619.                 "Entered value should be a hex number");
  620.             m_dwOffset = (DWORD)Convert.ToInt32(txtOffset.Text,16);
  621.             if(m_direction == RW.WRITE && txtInput.Text == "")
  622.             {
  623.                 m_excp = new Exception("You must enter the data to write. " +
  624.                     "data should be hex");
  625.                 throw m_excp;
  626.             }
  627.             m_excp = new Exception("The data you've entered is invalid. please "
  628.                 + "try again (hex)");
  629.             
  630.             switch(m_mode)
  631.             {
  632.             case WDC_ADDR_MODE.WDC_MODE_8:
  633.                 {    
  634.                     m_bData = new byte[m_dwBytes];
  635.                     if(m_direction == RW.WRITE)
  636.                     {
  637.                         str = txtInput.Text;
  638.                         for(int i=0, j=0; i<str.Length && j<m_dwBytes; j++)
  639.                         {
  640.                             while (str[i] == ' ') ++i;
  641.                             m_bData[j] = Convert.ToByte(str.Substring(i,2),16);
  642.                             i+=2;
  643.                         }
  644.                     }                        
  645.                     break;
  646.                 }
  647.             case WDC_ADDR_MODE.WDC_MODE_16:
  648.                 {
  649.                     m_wData = new WORD[m_dwBytes/2];
  650.                     if(m_direction == RW.WRITE)
  651.                     {
  652.                         str = txtInput.Text;
  653.                         for(int i=0, j=0; i<str.Length && j<m_dwBytes/2; j++)
  654.                         {
  655.                             while (str[i] == ' ') ++i;
  656.                             m_wData[j] = Convert.ToUInt16(str.Substring(i,4),16);
  657.                             i+=4;
  658.                         }        
  659.                     }
  660.                     break;
  661.                 }
  662.             case WDC_ADDR_MODE.WDC_MODE_32:
  663.                 {
  664.                     m_u32Data = new UINT32[m_dwBytes/4];
  665.                     if(m_direction == RW.WRITE)
  666.                     {
  667.                         str = txtInput.Text;
  668.                         for(int i=0, j=0; i<str.Length && j<m_dwBytes/4; j++)
  669.                         {
  670.                             while (str[i] == ' ') ++i;
  671.                             m_u32Data[j] = Convert.ToUInt32(str.Substring(i,8),
  672.                                 16);
  673.                             i+=8;
  674.                         }
  675.                     }                        
  676.                     break;
  677.                 }
  678.             case WDC_ADDR_MODE.WDC_MODE_64:
  679.                 {
  680.                     m_u64Data = new UINT64[m_dwBytes/8];
  681.                     if(m_direction == RW.WRITE)
  682.                     {
  683.                         str = txtInput.Text;
  684.                         for(int i=0, j=0; i<str.Length && j<m_dwBytes/8; j++)
  685.                         {
  686.                             while (str[i] == ' ') ++i;
  687.                             m_u64Data[j] = Convert.ToUInt64(str.Substring(i,2),
  688.                                 16);
  689.                             i+=16;
  690.                         }
  691.                     }                        
  692.                     break;
  693.                 }
  694.             }                    
  695.         }
  696.         private void cmboTransType_SelectedIndexChanged(object sender, 
  697.             System.EventArgs e)
  698.         {
  699.             if((string)cmboTransType.SelectedItem == "non-block")
  700.             {
  701.                 txtNumBytes.Enabled = false;
  702.                 chkBoxInc.Enabled = false;
  703.             }
  704.             else if((string)cmboTransType.SelectedItem == "block")
  705.             {
  706.                 txtNumBytes.Enabled = true;
  707.                 chkBoxInc.Enabled = true;
  708.             }
  709.         }        
  710.         private void btLog_Click(object sender, System.EventArgs e)
  711.         {
  712.             txtData.Clear();
  713.         }    
  714.         private void TraceLog(BOOL bIsRead, wdc_err status)
  715.         {
  716.             string sData = "";
  717.             string sInfo = "";
  718.             if (status == wdc_err.WD_STATUS_SUCCESS)
  719.             {
  720.                 sData = (bIsRead? "R: " : "W: ") + 
  721.                     diag_lib.DisplayHexBuffer(m_obj, m_dwBytes, m_mode);
  722.                 sInfo = (bIsRead ? " from " : " to ") +    "offset " + 
  723.                     m_dwOffset.ToString("X") + " on BAR " + m_dwBar.ToString() 
  724.                     + "(" + m_device.ToString(false) + ")";
  725.                 Log.TraceLog("AddrSpaceTransferForm: " + sData + sInfo);
  726.             }
  727.             else 
  728.             {
  729.                 sData = "failed to " + (bIsRead? "read from" : "write to") + 
  730.                     " offset " + m_dwOffset.ToString("X") + " on BAR " + 
  731.                     m_dwBar.ToString() + "status 0x" + status.ToString("X") + 
  732.                     ": " + utils.Stat2Str((DWORD)status);
  733.                                 sInfo = "(" + m_device.ToString(false) + ")";
  734.                 Log.ErrLog("AddrSpaceTransferForm: " + sData + sInfo);
  735.             }
  736.             txtData.Text += sData + Environment.NewLine;            
  737.         }
  738.     }
  739. }