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

驱动编程

开发平台:

Visual C++

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using System.Runtime.InteropServices;
  8. using System.Threading;
  9. using Jungo.wdapi_dotnet;
  10. using Jungo.plx_lib;
  11. using wdc_err = Jungo.wdapi_dotnet.WD_ERROR_CODES;
  12. using DWORD = System.UInt32;
  13. using WORD = System.UInt16;
  14. using BYTE = System.Byte;
  15. using BOOL = System.Boolean;
  16. using UINT32 = System.UInt32;
  17. using UINT64 = System.UInt64;
  18. using WDC_DEVICE_HANDLE = System.IntPtr;
  19. using WDC_ADDR_SIZE = System.UInt32;
  20. using HANDLE = System.IntPtr;
  21. namespace Jungo.PLX_Sample
  22. {
  23.     public enum RW
  24.     {
  25.         READ = 0,
  26.         WRITE = 1,
  27.         READ_ALL = 2
  28.     }
  29.     public enum TRANSFER_TYPE
  30.     {
  31.         BLOCK = 0,
  32.         NONBLOCK = 1
  33.     }
  34.     public enum COMPLETION
  35.     {
  36.         INTERRUPT = 0,
  37.         POLLING = 1
  38.     }
  39.     public enum ALLOCATION_TYPE
  40.     {
  41.         SG = 0,
  42.         CONTIG = 1,
  43.     }
  44.     public enum ACTION_TYPE
  45.     {
  46.         DMA = 0,
  47.         CFG = 1,
  48.         RT = 2,
  49.         EEPROM = 3
  50.     }
  51.     public class PLX_Sample : System.Windows.Forms.Form
  52.     {
  53.         private System.ComponentModel.Container components = null;
  54.         private DWORD PLX_DEFAULT_VENDOR_ID = 0x10b5; 
  55.         private DWORD PLX_DEFAULT_DEVICE_ID = 0x0;
  56.         private PLX_DeviceList plxDevList;
  57.         private DmaInfoList dmaList;
  58.         private Log log;
  59.         private System.Windows.Forms.TextBox txtLog;
  60.         private System.Windows.Forms.MainMenu mainMenu1;
  61.         private System.Windows.Forms.MenuItem menuAddrSpaces;
  62.         private System.Windows.Forms.MenuItem menuEnableInt;
  63.         private System.Windows.Forms.MenuItem menuDMA;
  64.         private System.Windows.Forms.MenuItem menuEvents;
  65.         private System.Windows.Forms.MenuItem menuEEPROM;
  66.         private System.Windows.Forms.MenuItem menuRegisterEvent;
  67.         private System.Windows.Forms.MenuItem menuChannel0;
  68.         private System.Windows.Forms.MenuItem menuChannel1;
  69.         private System.Windows.Forms.MenuItem menuOpenChn0;
  70.         private System.Windows.Forms.MenuItem menuTransferChn0;
  71.         private System.Windows.Forms.MenuItem menuOpenChn1;
  72.         private System.Windows.Forms.MenuItem menuCfgSpace;
  73.         private System.Windows.Forms.MenuItem menuRTRegs;
  74.         private System.Windows.Forms.Label lblLog;
  75.         private System.Windows.Forms.Label lblPLXDev;
  76.         private System.Windows.Forms.Label label1;
  77.         private System.Windows.Forms.Button btLog;
  78.         private System.Windows.Forms.Button btExit;
  79.         private System.Windows.Forms.ListBox lstBxDevices;
  80.         private System.Windows.Forms.MenuItem menuTransferChn1;
  81.         private System.Windows.Forms.MenuItem menuCfgOffset;
  82.         private System.Windows.Forms.MenuItem menuCfgReg;
  83.         private System.Windows.Forms.MenuItem menuAddrRW;
  84.         private System.Windows.Forms.MenuItem menuLocalRW;
  85.         private System.Windows.Forms.MenuItem menuRTRegsRW;
  86.         private System.Windows.Forms.MenuItem menuEEpromRW;
  87.         private System.Windows.Forms.MenuItem menuInt0;
  88.         private System.Windows.Forms.MenuItem menuMasterInterrupts;
  89.         private System.Windows.Forms.MenuItem menuTargetInterrupts;
  90.         private System.Windows.Forms.MenuItem menuGenerateInt;
  91.         private System.Windows.Forms.MenuItem menuTargetEnableInt;
  92.         private System.Windows.Forms.Button btDevice;
  93.         private System.Windows.Forms.MenuItem menuInt1;
  94.         public PLX_Sample()
  95.         {
  96.             InitializeComponent();
  97.             dmaList = new DmaInfoList();
  98.             log = new Log(new Log.TRACE_LOG(TraceLog),
  99.                new Log.ERR_LOG(ErrLog));
  100.             plxDevList = PLX_DeviceList.TheDeviceList();
  101.         }
  102.         protected override void Dispose( bool disposing )
  103.         {
  104.             if( disposing )
  105.             {
  106.                 if (components != null) 
  107.                 {
  108.                     components.Dispose();
  109.                 }
  110.             }
  111.             base.Dispose( disposing );
  112.         }
  113. #region Windows Form Designer generated code
  114.         /// Required method for Designer support - do not modify
  115.         /// the contents of this method with the code editor.
  116.         private void InitializeComponent()
  117.         {
  118.             this.txtLog = new System.Windows.Forms.TextBox();
  119.             this.lstBxDevices = new System.Windows.Forms.ListBox();
  120.             this.mainMenu1 = new System.Windows.Forms.MainMenu();
  121.             this.menuAddrSpaces = new System.Windows.Forms.MenuItem();
  122.             this.menuAddrRW = new System.Windows.Forms.MenuItem();
  123.             this.menuLocalRW = new System.Windows.Forms.MenuItem();
  124.             this.menuTargetInterrupts = new System.Windows.Forms.MenuItem();
  125.             this.menuTargetEnableInt = new System.Windows.Forms.MenuItem();
  126.             this.menuGenerateInt = new System.Windows.Forms.MenuItem();
  127.             this.menuMasterInterrupts = new System.Windows.Forms.MenuItem();
  128.             this.menuEnableInt = new System.Windows.Forms.MenuItem();
  129.             this.menuInt0 = new System.Windows.Forms.MenuItem();
  130.             this.menuInt1 = new System.Windows.Forms.MenuItem();
  131.             this.menuDMA = new System.Windows.Forms.MenuItem();
  132.             this.menuChannel0 = new System.Windows.Forms.MenuItem();
  133.             this.menuOpenChn0 = new System.Windows.Forms.MenuItem();
  134.             this.menuTransferChn0 = new System.Windows.Forms.MenuItem();
  135.             this.menuChannel1 = new System.Windows.Forms.MenuItem();
  136.             this.menuOpenChn1 = new System.Windows.Forms.MenuItem();
  137.             this.menuTransferChn1 = new System.Windows.Forms.MenuItem();
  138.             this.menuEvents = new System.Windows.Forms.MenuItem();
  139.             this.menuRegisterEvent = new System.Windows.Forms.MenuItem();
  140.             this.menuEEPROM = new System.Windows.Forms.MenuItem();
  141.             this.menuEEpromRW = new System.Windows.Forms.MenuItem();
  142.             this.menuCfgSpace = new System.Windows.Forms.MenuItem();
  143.             this.menuCfgOffset = new System.Windows.Forms.MenuItem();
  144.             this.menuCfgReg = new System.Windows.Forms.MenuItem();
  145.             this.menuRTRegs = new System.Windows.Forms.MenuItem();
  146.             this.menuRTRegsRW = new System.Windows.Forms.MenuItem();
  147.             this.lblLog = new System.Windows.Forms.Label();
  148.             this.lblPLXDev = new System.Windows.Forms.Label();
  149.             this.label1 = new System.Windows.Forms.Label();
  150.             this.btLog = new System.Windows.Forms.Button();
  151.             this.btExit = new System.Windows.Forms.Button();
  152.             this.btDevice = new System.Windows.Forms.Button();
  153.             this.SuspendLayout();
  154.             // txtLog
  155.             this.txtLog.AutoSize = false;
  156.             this.txtLog.Location = new System.Drawing.Point(24, 176);
  157.             this.txtLog.Multiline = true;
  158.             this.txtLog.Name = "txtLog";
  159.             this.txtLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
  160.             this.txtLog.Size = new System.Drawing.Size(624, 208);
  161.             this.txtLog.TabIndex = 24;
  162.             this.txtLog.Text = "";
  163.             // lstBxDevices
  164.             this.lstBxDevices.Location = new System.Drawing.Point(24, 80);
  165.             this.lstBxDevices.Name = "lstBxDevices";
  166.             this.lstBxDevices.Size = new System.Drawing.Size(416, 56);
  167.             this.lstBxDevices.TabIndex = 27;
  168.             this.lstBxDevices.SelectedIndexChanged += 
  169.                 new System.EventHandler(this.lstBxDevices_SelectedIndexChanged);
  170.             this.lstBxDevices.DoubleClick += new 
  171.                 System.EventHandler(this.lstBxDevices_DoubleClicked);
  172.             // mainMenu1
  173.             this.mainMenu1.MenuItems.AddRange(new 
  174.                 System.Windows.Forms.MenuItem[] {
  175.                 this.menuAddrSpaces,
  176.                 this.menuTargetInterrupts,
  177.                 this.menuMasterInterrupts,
  178.                 this.menuDMA,
  179.                 this.menuEvents,
  180.                 this.menuEEPROM,
  181.                 this.menuCfgSpace,
  182.                 this.menuRTRegs});
  183.             // menuAddrSpaces
  184.             this.menuAddrSpaces.Index = 0;
  185.             this.menuAddrSpaces.MenuItems.AddRange(new 
  186.                 System.Windows.Forms.MenuItem[] {
  187.                 this.menuAddrRW,
  188.                 this.menuLocalRW});
  189.             this.menuAddrSpaces.Text = "Address Spaces";
  190.             // menuAddrRW
  191.             this.menuAddrRW.Index = 0;
  192.             this.menuAddrRW.Text = "Read/Write Address Space";
  193.             this.menuAddrRW.Click += new 
  194.                 System.EventHandler(this.menuAddrRW_Click);
  195.             // menuLocalRW
  196.             this.menuLocalRW.Index = 1;
  197.             this.menuLocalRW.Text = "Read/Write Local Bus";
  198.             this.menuLocalRW.Click += new 
  199.                 System.EventHandler(this.menuLocalRW_Click);
  200.             // menuTargetInterrupts
  201.             this.menuTargetInterrupts.Index = 1;
  202.             this.menuTargetInterrupts.MenuItems.AddRange(new 
  203.                 System.Windows.Forms.MenuItem[] {
  204.                 this.menuTargetEnableInt,
  205.                 this.menuGenerateInt});
  206.             this.menuTargetInterrupts.Text = "Interrupts";
  207.             this.menuTargetInterrupts.Select +=
  208.                 new System.EventHandler(this.menuTargetInterrupts_Select);
  209.             // menuTargetEnableInt
  210.             this.menuTargetEnableInt.Index = 0;
  211.             this.menuTargetEnableInt.Text = "Enable Interrupts";
  212.             this.menuTargetEnableInt.Click += new
  213.                 System.EventHandler(this.menuTargetEnableInt_Click);
  214.             // menuGenerateInt
  215.             this.menuGenerateInt.Index = 1;
  216.             this.menuGenerateInt.Text = "Generate Interrupt (slave only)";
  217.             this.menuGenerateInt.Click += new 
  218.                 System.EventHandler(this.menuGenerateInt_Click);
  219.             // menuMasterInterrupts
  220.             this.menuMasterInterrupts.Index = 2;
  221.             this.menuMasterInterrupts.MenuItems.AddRange(new
  222.                 System.Windows.Forms.MenuItem[] {
  223.                 this.menuEnableInt});
  224.             this.menuMasterInterrupts.Text = "Interrupts";
  225.             this.menuMasterInterrupts.Select += new 
  226.                 EventHandler(menuMasterInterrupts_Select);
  227.             // menuEnableInt
  228.             this.menuEnableInt.Index = 0;
  229.             this.menuEnableInt.MenuItems.AddRange(new
  230.                 System.Windows.Forms.MenuItem[] {
  231.                 this.menuInt0,
  232.                 this.menuInt1});
  233.             this.menuEnableInt.Text = "Enable Interrupts";
  234.             this.menuEnableInt.Select += new
  235.                 System.EventHandler(this.menuEnableInt_Select);
  236.             // menuInt0
  237.             this.menuInt0.Index = 0;
  238.             this.menuInt0.Text = "On DMA Channel 0";
  239.             this.menuInt0.Click += new System.EventHandler(this.menuInt0_Click);
  240.             // menuInt1
  241.             this.menuInt1.Index = 1;
  242.             this.menuInt1.Text = "On DMA Channel 1";
  243.             this.menuInt1.Click += new
  244.                 System.EventHandler(this.menuInt1_Click);
  245.             // menuDMA
  246.             this.menuDMA.Index = 3;
  247.             this.menuDMA.MenuItems.AddRange(new
  248.                 System.Windows.Forms.MenuItem[] {
  249.                 this.menuChannel0,
  250.                 this.menuChannel1});
  251.             this.menuDMA.Text = "DMA";
  252.             // menuChannel0
  253.             this.menuChannel0.Index = 0;
  254.             this.menuChannel0.MenuItems.AddRange(new
  255.                 System.Windows.Forms.MenuItem[] {
  256.                 this.menuOpenChn0,
  257.                 this.menuTransferChn0});
  258.             this.menuChannel0.Text = "Channel 0";
  259.             this.menuChannel0.Select += new
  260.                 System.EventHandler(this.menuChannel0_Select);
  261.             // menuOpenChn0
  262.             this.menuOpenChn0.Index = 0;
  263.             this.menuOpenChn0.Text = "Open";
  264.             this.menuOpenChn0.Click += new
  265.                 System.EventHandler(this.menuOpenChn0_Click);
  266.             // menuTransferChn0
  267.             this.menuTransferChn0.Index = 1;
  268.             this.menuTransferChn0.Text = "Read/Write";
  269.             this.menuTransferChn0.Click += new 
  270.                 System.EventHandler(this.menuTransferChn0_Click);
  271.             // menuChannel1
  272.             this.menuChannel1.Index = 1;
  273.             this.menuChannel1.MenuItems.AddRange(new
  274.                 System.Windows.Forms.MenuItem[] {
  275.                 this.menuOpenChn1,
  276.                 this.menuTransferChn1});
  277.             this.menuChannel1.Text = "Channel 1";
  278.             this.menuChannel1.Select += new 
  279.                 System.EventHandler(this.menuChannel1_Select);
  280.             // menuOpenChn1
  281.             this.menuOpenChn1.Index = 0;
  282.             this.menuOpenChn1.Text = "Open";
  283.             this.menuOpenChn1.Click += new 
  284.                 System.EventHandler(this.menuOpenChn1_Click);
  285.             // menuTransferChn1
  286.             this.menuTransferChn1.Index = 1;
  287.             this.menuTransferChn1.Text = "Read/Write";
  288.             this.menuTransferChn1.Click += new
  289.                 System.EventHandler(this.menuTransferChn1_Click);
  290.             // menuEvents
  291.             this.menuEvents.Index = 4;
  292.             this.menuEvents.MenuItems.AddRange(new
  293.                 System.Windows.Forms.MenuItem[] {
  294.                 this.menuRegisterEvent});
  295.             this.menuEvents.Text = "Events";
  296.             this.menuEvents.Select += new 
  297.                 System.EventHandler(this.menuEvents_Select);
  298.             // menuRegisterEvent
  299.             this.menuRegisterEvent.Index = 0;
  300.             this.menuRegisterEvent.Text = "Regsiter Events";
  301.             this.menuRegisterEvent.Click += new 
  302.                 System.EventHandler(this.menuRegisterEvent_Click);
  303.             // menuEEPROM
  304.             this.menuEEPROM.Index = 5;
  305.             this.menuEEPROM.MenuItems.AddRange(new
  306.                 System.Windows.Forms.MenuItem[] {
  307.                 this.menuEEpromRW});
  308.             this.menuEEPROM.Text = "EEPROM";
  309.             // menuEEpromRW
  310.             this.menuEEpromRW.Index = 0;
  311.             this.menuEEpromRW.Text = "Read/Write EEPROM";
  312.             this.menuEEpromRW.Click += new
  313.                 System.EventHandler(this.menuEEpromRW_Click);
  314.             // menuCfgSpace
  315.             this.menuCfgSpace.Index = 6;
  316.             this.menuCfgSpace.MenuItems.AddRange(new
  317.                 System.Windows.Forms.MenuItem[] {
  318.                 this.menuCfgOffset,
  319.                 this.menuCfgReg});
  320.             this.menuCfgSpace.Text = "Configuration Space";
  321.             // menuCfgOffset
  322.             this.menuCfgOffset.Index = 0;
  323.             this.menuCfgOffset.Text = "By Offset ";
  324.             this.menuCfgOffset.Click += new 
  325.                 System.EventHandler(this.menuCfgOffset_Click);
  326.             // menuCfgReg
  327.             this.menuCfgReg.Index = 1;
  328.             this.menuCfgReg.Text = "By Register";
  329.             this.menuCfgReg.Click += new 
  330.                 System.EventHandler(this.menuCfgReg_Click);
  331.             // menuRTRegs
  332.             this.menuRTRegs.Index = 7;
  333.             this.menuRTRegs.MenuItems.AddRange(new 
  334.                 System.Windows.Forms.MenuItem[] {
  335.                 this.menuRTRegsRW});
  336.             this.menuRTRegs.Text = "RunTime Registers";
  337.             // menuRTRegsRW
  338.             this.menuRTRegsRW.Index = 0;
  339.             this.menuRTRegsRW.Text = "Read/Write RT Registers";
  340.             this.menuRTRegsRW.Click += new
  341.                 System.EventHandler(this.menuRTRegsRW_Click);
  342.             // lblLog
  343.             this.lblLog.Location = new System.Drawing.Point(24, 152);
  344.             this.lblLog.Name = "lblLog";
  345.             this.lblLog.TabIndex = 28;
  346.             this.lblLog.Text = "Log";
  347.             // lblPLXDev
  348.             this.lblPLXDev.Location = new System.Drawing.Point(24, 56);
  349.             this.lblPLXDev.Name = "lblPLXDev";
  350.             this.lblPLXDev.Size = new System.Drawing.Size(120, 23);
  351.             this.lblPLXDev.TabIndex = 29;
  352.             this.lblPLXDev.Text = "PLX Devices Found:";
  353.             // label1
  354.             this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif",
  355.                 9.75F, System.Drawing.FontStyle.Bold, 
  356.                 System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  357.             this.label1.Location = new System.Drawing.Point(40, 16);
  358.             this.label1.Name = "label1";
  359.             this.label1.Size = new System.Drawing.Size(232, 23);
  360.             this.label1.TabIndex = 30;
  361.             this.label1.Text = "Select a device to activate its menu";
  362.             // btLog
  363.             this.btLog.Location = new System.Drawing.Point(672, 208);
  364.             this.btLog.Name = "btLog";
  365.             this.btLog.Size = new System.Drawing.Size(80, 40);
  366.             this.btLog.TabIndex = 31;
  367.             this.btLog.Text = "Clear Log";
  368.             this.btLog.Click += new System.EventHandler(this.btLog_Click);
  369.             // btExit
  370.             this.btExit.Location = new System.Drawing.Point(672, 304);
  371.             this.btExit.Name = "btExit";
  372.             this.btExit.Size = new System.Drawing.Size(80, 40);
  373.             this.btExit.TabIndex = 32;
  374.             this.btExit.Text = "Exit";
  375.             this.btExit.Click += new System.EventHandler(this.btExit_Click);
  376.             // btDevice
  377.             this.btDevice.Location = new System.Drawing.Point(464, 96);
  378.             this.btDevice.Name = "btDevice";
  379.             this.btDevice.Size = new System.Drawing.Size(112, 23);
  380.             this.btDevice.TabIndex = 33;
  381.             this.btDevice.Text = "Open Device";
  382.             this.btDevice.Click += new System.EventHandler(this.btDevice_Click);
  383.             // PLX_Sample
  384.             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  385.             this.ClientSize = new System.Drawing.Size(768, 409);
  386.             this.Controls.Add(this.btDevice);
  387.             this.Controls.Add(this.btExit);
  388.             this.Controls.Add(this.btLog);
  389.             this.Controls.Add(this.label1);
  390.             this.Controls.Add(this.lblPLXDev);
  391.             this.Controls.Add(this.lblLog);
  392.             this.Controls.Add(this.lstBxDevices);
  393.             this.Controls.Add(this.txtLog);
  394.             this.Menu = this.mainMenu1;
  395.             this.Name = "PLX_Sample";
  396.             this.StartPosition = 
  397.                 System.Windows.Forms.FormStartPosition.CenterScreen;
  398.             this.Text = "PLX .NET Sample";
  399.             this.Load += new System.EventHandler(this.PLX_Sample_Load);
  400.             this.Closed += new System.EventHandler(this.PLX_Sample_Closing);
  401.             this.ResumeLayout(false);
  402.         }
  403. #endregion
  404.         /// The main entry point for the application.
  405.         [STAThread]
  406.             static void Main() 
  407.             {
  408.                 Application.Run(new PLX_Sample());
  409.             }
  410.         /* Open a handle to a device */
  411.         private bool DeviceOpen(int iSelectedIndex)
  412.         {
  413.             DWORD dwStatus;
  414.             PLX_Device device = plxDevList.Get(iSelectedIndex);
  415.             /* Open a handle to the device */
  416.             dwStatus = device.DeviceOpen();
  417.             if (dwStatus != (DWORD)wdc_err.WD_STATUS_SUCCESS)
  418.             {
  419.                 Log.ErrLog("PLX_Sample.DeviceOpen: Failed opening a " +
  420.                     "handle to the device (" + device.ToString(false) + ")" );
  421.                 return false;
  422.             }
  423.             Log.TraceLog("PLX_Sample.DeviceOpen: The device was successfully open." +
  424.                 "You can now activate the device through the enabled menu above");
  425.             return true;
  426.         }
  427.         /* Close handle to a PLX device */
  428.         private BOOL DeviceClose(int iSelectedIndex)
  429.         {
  430.             PLX_Device device = plxDevList.Get(iSelectedIndex);
  431.             BOOL bStatus = false;
  432.                         
  433.             DmaInfoList dmaDevList = dmaList.GetItems(device.Handle);
  434.             foreach (DmaInfo dmaInfo in dmaDevList)
  435.             {
  436.                 dmaList.Remove(dmaInfo);
  437.                 dmaInfo.Close();
  438.                 Log.TraceLog("DMA Channel " + 
  439.                     (((DWORD)dmaInfo.DmaChannel == 0)? "0 " : "1 ") + "was closed. {" +
  440.                     device.ToString(false) + "}");
  441.             }
  442.                         
  443.             if (device.Handle != IntPtr.Zero && !(bStatus = device.DeviceClose()))
  444.             {
  445.                 Log.ErrLog("PLX_Sample.DeviceClose: Failed closing PLX "
  446.                     + "device (" + device.ToString(false) + ")");
  447.             }
  448.             else
  449.                 device.Handle = IntPtr.Zero;
  450.             return bStatus;
  451.         }
  452.         private void PLX_Sample_Load(object sender, System.EventArgs e)
  453.         {
  454.             DWORD dwStatus = plxDevList.Init();           
  455.             if(dwStatus != (DWORD)wdc_err.WD_STATUS_SUCCESS)
  456.                 goto Error;
  457.             
  458.             int index = plxDevList.Populate(PLX_DEFAULT_VENDOR_ID, 
  459.                 PLX_DEFAULT_DEVICE_ID);
  460.             if(index < 0)
  461.                 goto Error;
  462.             foreach(PLX_Device dev in plxDevList)
  463.                 lstBxDevices.Items.Add(dev.ToString(true));
  464.             lstBxDevices.SelectedIndex = 0;
  465.             return;            
  466. Error:
  467.             DisableMenu();
  468.             btDevice.Enabled = false;            
  469.         }
  470.         private void PLX_IntHandler(PLX_TargetDevice dev)
  471.         {
  472.             Log.TraceLog("interrupt for device {" + dev.ToString(false) +
  473.                 "} received!");
  474.         }
  475.         private void PLX_DMAIntHandler(PLX_MasterDevice dev, IntPtr pWdDma)
  476.         {        
  477.             MarshalWdDma m_wdDmaMarshaler = new MarshalWdDma(); 
  478.             WD_DMA wdDma = (WD_DMA)m_wdDmaMarshaler.MarshalNativeToManaged(pWdDma);
  479.             BOOL bIsRead = (wdDma.dwOptions & (DWORD)WD_DMA_OPTIONS.DMA_FROM_DEVICE) != 0;
  480.             byte[] data = new byte[wdDma.dwBytes];
  481.             Marshal.Copy(wdDma.pUserAddr, data, 0, (int)wdDma.dwBytes);
  482.             Log.TraceLog("interrupt for device {" + dev.ToString(false) +
  483.                 "} received! " + Environment.NewLine +
  484.                 (bIsRead? "read: " : "wrote: ") +
  485.                 diag_lib.DisplayHexBuffer(data, wdDma.dwBytes));                
  486.         }
  487.         private void PLX_EventHandler(ref WD_EVENT wdEvent, PLX_Device dev)
  488.         {
  489.             string sAction;
  490.             switch((WD_EVENT_ACTION)wdEvent.dwAction)
  491.             {
  492.                 case WD_EVENT_ACTION.WD_INSERT:
  493.                     sAction = "WD_INSERT";
  494.                     break;
  495.                 case WD_EVENT_ACTION.WD_REMOVE:
  496.                     sAction = "WD_REMOVE";
  497.                     break;
  498.                 case WD_EVENT_ACTION.WD_POWER_CHANGED_D0:
  499.                     sAction = "WD_POWER_CHANGED_D0";
  500.                     break;
  501.                 case WD_EVENT_ACTION.WD_POWER_CHANGED_D1:
  502.                     sAction = "WD_POWER_CHANGED_D1";
  503.                     break;
  504.                 case WD_EVENT_ACTION.WD_POWER_CHANGED_D2:
  505.                     sAction = "WD_POWER_CHANGED_D2";
  506.                     break;
  507.                 case WD_EVENT_ACTION.WD_POWER_CHANGED_D3:
  508.                     sAction = "WD_POWER_CHANGED_D3";
  509.                     break;
  510.                 case WD_EVENT_ACTION.WD_POWER_SYSTEM_WORKING:
  511.                     sAction = "WD_POWER_SYSTEM_WORKING";
  512.                     break;
  513.                 case WD_EVENT_ACTION.WD_POWER_SYSTEM_SLEEPING1:
  514.                     sAction = "WD_POWER_SYSTEM_SLEEPING1";
  515.                     break;
  516.                 case WD_EVENT_ACTION.WD_POWER_SYSTEM_SLEEPING2:
  517.                     sAction = "WD_POWER_SYSTEM_SLEEPING2";
  518.                     break;
  519.                 case WD_EVENT_ACTION.WD_POWER_SYSTEM_SLEEPING3:
  520.                     sAction = "WD_POWER_SYSTEM_SLEEPING3";
  521.                     break;
  522.                 case WD_EVENT_ACTION.WD_POWER_SYSTEM_HIBERNATE:
  523.                     sAction = "WD_POWER_SYSTEM_HIBERNATE";
  524.                     break;
  525.                 case WD_EVENT_ACTION.WD_POWER_SYSTEM_SHUTDOWN:
  526.                     sAction = "WD_POWER_SYSTEM_SHUTDOWN";
  527.                     break;
  528.                 default:
  529.                     sAction = wdEvent.dwAction.ToString("X");
  530.                     break;
  531.             }
  532.             Log.TraceLog("Received event notification of type " + sAction +
  533.                 " on " + dev.ToString(false));    
  534.         }
  535.         private void PLX_Sample_Closing(object sender, System.EventArgs e)
  536.         {
  537.             plxDevList.Dispose();
  538.             dmaList.Dispose();
  539.         }        
  540.         /* list box lstBxDevices */
  541.         private void lstBxDevices_SelectedIndexChanged(object sender, 
  542.             System.EventArgs e)
  543.         {
  544.             if(lstBxDevices.SelectedIndex < 0)
  545.             {
  546.                 DisableMenu();
  547.                 btDevice.Enabled = false;
  548.             }
  549.             else
  550.             {
  551.                 PLX_Device dev = 
  552.                     plxDevList.Get(lstBxDevices.SelectedIndex);
  553.                 UpdateMenu(lstBxDevices.SelectedIndex);
  554.                 btDevice.Enabled = true;
  555.                 if(dev.Handle == IntPtr.Zero)
  556.                     btDevice.Text = "Open Device";
  557.                 else 
  558.                     btDevice.Text = "Close Device";
  559.             }
  560.         }
  561.         private void lstBxDevices_DoubleClicked(object sender, 
  562.             System.EventArgs e)
  563.         {
  564.             btDevice_Click(sender, e);
  565.         }
  566.         /* device button */
  567.         private void btDevice_Click(object sender, System.EventArgs e)
  568.         {
  569.             if(btDevice.Text == "Open Device")
  570.             {
  571.                 if(DeviceOpen(lstBxDevices.SelectedIndex) == true)
  572.                 {
  573.                     btDevice.Text = "Close Device";
  574.                     EnableMenu();                
  575.                 }
  576.             }
  577.             else
  578.             {
  579.                 PLX_Device dev =
  580.                     plxDevList.Get(lstBxDevices.SelectedIndex);
  581.                 DeviceClose(lstBxDevices.SelectedIndex); 
  582.                 btDevice.Text = "Open Device";
  583.                 DisableMenu(); 
  584.             }        
  585.         }
  586.         /* Menu*/
  587.         private void UpdateMenu(int index)
  588.         {
  589.             PLX_Device dev =
  590.                 plxDevList.Get(lstBxDevices.SelectedIndex);
  591.             if(dev.Handle == IntPtr.Zero)
  592.                 DisableMenu();
  593.             else 
  594.                 EnableMenu();
  595.             menuTargetInterrupts.Visible = (dev.IsMaster)? false: true;
  596.             menuMasterInterrupts.Visible = (dev.IsMaster)? true: false;
  597.             menuDMA.Visible = (dev.IsMaster)? true: false;
  598.         }
  599.         private void EnableMenu()
  600.         {
  601.             ToggleMenu(true);
  602.         }
  603.         private void DisableMenu()
  604.         {
  605.             ToggleMenu(false);
  606.         }
  607.         private void ToggleMenu(bool flag)
  608.         {
  609.             for(int index=0; index < mainMenu1.MenuItems.Count; ++index)
  610.                 mainMenu1.MenuItems[index].Enabled = flag;
  611.         }
  612.         /* Address Space Item */
  613.         private void menuAddrRW_Click(object sender, System.EventArgs e)
  614.         {
  615.             PLX_Device dev =
  616.                 plxDevList.Get(lstBxDevices.SelectedIndex);
  617.             string[] sBars = dev.AddrDescToString(false);
  618.             AddrSpaceTransferForm addrSpcFrm = new 
  619.                 AddrSpaceTransferForm(dev, sBars, false);
  620.             addrSpcFrm.GetInput();
  621.         }
  622.         private void menuLocalRW_Click(object sender, System.EventArgs e)
  623.         {
  624.             PLX_Device dev = 
  625.                 plxDevList.Get(lstBxDevices.SelectedIndex);
  626.             string[] sBars = dev.AddrDescToString(true);
  627.             AddrSpaceTransferForm addrSpcFrm = new AddrSpaceTransferForm(dev
  628.                 , sBars, true);
  629.             addrSpcFrm.GetInput();
  630.         }
  631.         /* Interrupts items*/
  632.         private void menuTargetInterrupts_Select(object sender, 
  633.             System.EventArgs e)
  634.         {
  635.             if(menuTargetInterrupts.Enabled == false)
  636.                 return;
  637.             PLX_TargetDevice dev = (PLX_TargetDevice)plxDevList.Get(
  638.                 lstBxDevices.SelectedIndex);
  639.             bool bIsEnb = dev.IsEnabledInt();
  640.             menuTargetEnableInt.Text = bIsEnb? "Disable Interrupts":
  641.                 "Enable Interrupts";     
  642.             menuGenerateInt.Enabled = bIsEnb? true: false;
  643.         }
  644.         private void menuTargetEnableInt_Click(object sender,
  645.             System.EventArgs e)
  646.         {
  647.             PLX_TargetDevice dev = (PLX_TargetDevice)plxDevList.Get(
  648.                 lstBxDevices.SelectedIndex);
  649.             if(menuTargetEnableInt.Text == "Enable Interrupts")
  650.             {
  651.                 DWORD dwStatus = dev.EnableInterrupts(new
  652.                     USER_INTERRUPT_TARGET_CALLBACK(PLX_IntHandler));
  653.                 if(dwStatus == (DWORD)wdc_err.WD_STATUS_SUCCESS)
  654.                     menuTargetEnableInt.Text = "Disable Interrupts";
  655.             }
  656.             else
  657.             {
  658.                 DWORD dwStatus = dev.DisableInterrupts();
  659.                 if(dwStatus == (DWORD)wdc_err.WD_STATUS_SUCCESS)
  660.                     menuTargetEnableInt.Text = "Enable Interrupts";
  661.             }                        
  662.         }        
  663.         private void menuGenerateInt_Click(object sender, System.EventArgs e)
  664.         {
  665.             ((PLX_TargetDevice)(plxDevList.Get(
  666.                 lstBxDevices.SelectedIndex))).GenerateTargetInterrupt(0);
  667.         }
  668.         private void menuMasterInterrupts_Select(object sender,
  669.             System.EventArgs e)
  670.         {
  671.             if(menuMasterInterrupts.Enabled == false)
  672.                 return;
  673.             PLX_MasterDevice dev = (PLX_MasterDevice)plxDevList.Get(
  674.                 lstBxDevices.SelectedIndex);
  675.             bool bIsEnb = dev.IsEnabledInt();
  676.             menuEnableInt.Text = bIsEnb? "Disable Interrupts":
  677.                 "Enable Interrupts";                
  678.         }                
  679.         public void menuEnableInt_Select(object sender, System.EventArgs e)
  680.         {
  681.             if(menuEnableInt.Enabled == false)
  682.                 return;
  683.             PLX_MasterDevice dev = (PLX_MasterDevice)plxDevList.Get(
  684.                 lstBxDevices.SelectedIndex);
  685.             if(menuEnableInt.Text == "Enable Interrupts")
  686.             {
  687.                 menuInt0.Visible = true;
  688.                 menuInt1.Visible = true;                                
  689.             }
  690.             else
  691.             {
  692.                 bool bIsChn0 =
  693.                     (dev.IsChannelIntEnabled(PLX_DMA_CHANNEL.PLX_DMA_CHANNEL_0));
  694.                 menuInt0.Visible = bIsChn0? true: false;
  695.                 menuInt1.Visible = bIsChn0? false: true;
  696.             }                                        
  697.         }                
  698.         private void menuInt0_Click(object sender, System.EventArgs e)
  699.         {
  700.             menuInt_Click(PLX_DMA_CHANNEL.PLX_DMA_CHANNEL_0);
  701.         }
  702.         private void menuInt1_Click(object sender, System.EventArgs e)
  703.         {
  704.             menuInt_Click(PLX_DMA_CHANNEL.PLX_DMA_CHANNEL_1);
  705.         }
  706.         private void menuInt_Click(PLX_DMA_CHANNEL chn)
  707.         {
  708.             PLX_MasterDevice dev = (PLX_MasterDevice)plxDevList.Get(
  709.                 lstBxDevices.SelectedIndex);
  710.             if(dev.IsEnabledInt())
  711.                 dev.DisableInterrupts();
  712.             else
  713.                 dev.EnableInterrupts(new 
  714.                     USER_INTERRUPT_MASTER_CALLBACK(PLX_DMAIntHandler), chn);
  715.         }
  716.         /* DMA items */
  717.         private void menuChannel0_Select(object sender, System.EventArgs e)
  718.         {
  719.             if(menuChannel0.Enabled == false)
  720.                 return;
  721.             PLX_MasterDevice dev = (PLX_MasterDevice)plxDevList.Get(
  722.                 lstBxDevices.SelectedIndex);
  723.             bool bIsOpen = dmaList.IsDMAOpen(dev.Handle,
  724.                 PLX_DMA_CHANNEL.PLX_DMA_CHANNEL_0);
  725.             menuOpenChn0.Text = bIsOpen? "Close" : "Open";
  726.             menuTransferChn0.Enabled = bIsOpen? true : false;                
  727.         }
  728.         private void menuOpenChn_Click(PLX_DMA_CHANNEL plxChn,
  729.             System.Windows.Forms.MenuItem chnItem)
  730.         {
  731.             PLX_MasterDevice dev = (PLX_MasterDevice)plxDevList.Get(
  732.                 lstBxDevices.SelectedIndex);
  733.             if(chnItem.Text == "Open")
  734.             {
  735.                 DmaBuffer dmaBuff = null;
  736.                 UINT32 u32localAddr = 0;
  737.                 RW direction = 0;
  738.                 ALLOCATION_TYPE wAllocType = 0;
  739.                 DWORD dwBytes = 0;
  740.                 BOOL bAutoInc = false;
  741.                 IntPtr pBuffer = IntPtr.Zero;
  742.                 OpenDMAForm openDmaFrm = new OpenDMAForm(plxChn);
  743.                 if(openDmaFrm.GetInput(ref u32localAddr, ref direction,
  744.                     ref wAllocType, ref dwBytes, ref bAutoInc) == false)
  745.                     return;
  746.                 if (wAllocType == ALLOCATION_TYPE.SG)
  747.                 {
  748.                     pBuffer = Marshal.AllocHGlobal((int)dwBytes);
  749.                     if(pBuffer == IntPtr.Zero)
  750.                     {
  751.                         Log.ErrLog("PLX_Sample: Failed to allocate buffer for " +
  752.                             "Scatter-Gather DMA");
  753.                         return;
  754.                     }
  755.                     dmaBuff = new DmaBufferSG(dev);
  756.                 }
  757.                 else
  758.                     dmaBuff = new DmaBufferContig(dev);
  759.                 if(dmaBuff.Open(u32localAddr, (direction == RW.READ), dwBytes,
  760.                     ref pBuffer, bAutoInc, WDC_ADDR_MODE.WDC_MODE_32) !=
  761.                     (DWORD)wdc_err.WD_STATUS_SUCCESS)
  762.                     return;
  763.                 dmaList.AddItem(dmaBuff, plxChn, pBuffer);
  764.                 chnItem.Text = "Close";
  765.                 Log.TraceLog("DMA buffer for {" +
  766.                     dev.ToString(false) + "}, Channel " +
  767.                     (((DWORD)plxChn == 0)? "0 " : "1 ") + 
  768.                     "was opened successfully");
  769.                 return;
  770.             }
  771.             else
  772.             {
  773.                 DmaInfo dmaInfo = dmaList.GetItem(dev.Handle, plxChn);
  774.                 dmaInfo.Close();
  775.                 dmaList.Remove(dmaInfo);
  776.                 chnItem.Text = "Open";
  777.                 Log.TraceLog("DMA Channel " + 
  778.                     (((DWORD)plxChn == 0)? "0 " : "1 ") + "was closed. {" +
  779.                     dev.ToString(false) + "}");
  780.                 return;
  781.             }
  782.         }
  783.         private void menuOpenChn0_Click(object sender, System.EventArgs e)
  784.         {
  785.             menuOpenChn_Click(PLX_DMA_CHANNEL.PLX_DMA_CHANNEL_0, menuOpenChn0);
  786.         }
  787.         private void menuTransferChn0_Click(object sender, System.EventArgs e)
  788.         {
  789.             menuTransferChn_Click(PLX_DMA_CHANNEL.PLX_DMA_CHANNEL_0);
  790.         }
  791.         private void menuChannel1_Select(object sender, System.EventArgs e)
  792.         {
  793.             if(menuChannel1.Enabled == false)
  794.                 return;
  795.             PLX_MasterDevice dev = (PLX_MasterDevice)plxDevList.Get(
  796.                 lstBxDevices.SelectedIndex);
  797.             bool bIsOpen = dmaList.IsDMAOpen(dev.Handle,
  798.                 PLX_DMA_CHANNEL.PLX_DMA_CHANNEL_1);
  799.             menuOpenChn1.Text = bIsOpen? "Close" : "Open";
  800.             menuTransferChn1.Enabled = bIsOpen? true : false;
  801.         }
  802.         private void menuOpenChn1_Click(object sender, System.EventArgs e)
  803.         {
  804.             menuOpenChn_Click(PLX_DMA_CHANNEL.PLX_DMA_CHANNEL_1, menuOpenChn1);
  805.         }
  806.         private void menuTransferChn1_Click(object sender, System.EventArgs e)
  807.         {
  808.             menuTransferChn_Click(PLX_DMA_CHANNEL.PLX_DMA_CHANNEL_1);
  809.         }
  810.         private void menuTransferChn_Click(PLX_DMA_CHANNEL chn)
  811.         {
  812.             PLX_MasterDevice dev = (PLX_MasterDevice)plxDevList.Get(
  813.                 lstBxDevices.SelectedIndex);
  814.             DmaBuffer dmaBuffer = dmaList.GetItem(dev.Handle, chn).DmaBuffer;
  815.             MarshalWdDma wdDmaMarshaler = new MarshalWdDma();
  816.             IntPtr pBuffer = ((WD_DMA)wdDmaMarshaler.MarshalNativeToManaged(dmaBuffer.pWdDma)).pUserAddr;
  817.             DMATransferForm transFrom = new DMATransferForm(dev, dmaBuffer, pBuffer, 
  818.                 chn, dmaBuffer.IsRead);
  819.             transFrom.GetInput();
  820.         }        
  821.         /* Event Items*/
  822.         private void menuEvents_Select(object sender, System.EventArgs e)
  823.         {
  824.             if(menuEvents.Enabled == false)
  825.                 return;
  826.             PLX_Device dev = plxDevList.Get(lstBxDevices.SelectedIndex);
  827.             menuRegisterEvent.Text = dev.IsEventRegistered() ?
  828.                 "Unregister Events" : "Register Events";
  829.         }
  830.         private void menuRegisterEvent_Click(object sender, System.EventArgs e)
  831.         {
  832.             if(menuRegisterEvent.Text == "Register Events")
  833.             {
  834.                 plxDevList.Get(lstBxDevices.SelectedIndex).
  835.                     EventRegister(new USER_EVENT_CALLBACK(PLX_EventHandler));
  836.                 menuRegisterEvent.Text = "Unregister Events";
  837.             }
  838.             else
  839.             {
  840.                 plxDevList.Get(lstBxDevices.SelectedIndex).
  841.                     EventUnregister();
  842.                 menuRegisterEvent.Text = "Register Events";
  843.             }                
  844.         }
  845.         /* EEPROM Items*/
  846.         private void menuEEpromRW_Click(object sender, System.EventArgs e)
  847.         {
  848.             PLX_Device dev =
  849.                 plxDevList.Get(lstBxDevices.SelectedIndex);
  850.             RegistersForm EForm = new RegistersForm(dev, ACTION_TYPE.EEPROM);
  851.             EForm.GetInput();
  852.         }
  853.         /* Configuration Space Items*/
  854.         private void menuCfgOffset_Click(object sender, System.EventArgs e)
  855.         {
  856.             PLX_Device dev =
  857.                 plxDevList.Get(lstBxDevices.SelectedIndex);
  858.             CfgTransfersForm cfgOffsetFrom = new CfgTransfersForm(dev);
  859.             cfgOffsetFrom.GetInput();        
  860.         }
  861.         private void menuCfgReg_Click(object sender, System.EventArgs e)
  862.         {
  863.             PLX_Device dev =
  864.                 plxDevList.Get(lstBxDevices.SelectedIndex);
  865.             RegistersForm regForm = new RegistersForm(dev, ACTION_TYPE.CFG);
  866.             regForm.GetInput();
  867.         }
  868.         /*RunTime Registers Items*/
  869.         private void menuRTRegsRW_Click(object sender, System.EventArgs e)
  870.         {
  871.             PLX_Device dev =
  872.                 plxDevList.Get(lstBxDevices.SelectedIndex);
  873.             RegistersForm regForm = new RegistersForm(dev, ACTION_TYPE.RT);
  874.             regForm.GetInput();        
  875.         }                
  876.         private void btExit_Click(object sender, System.EventArgs e)
  877.         {
  878.             Close();
  879.             Dispose();
  880.         }
  881.         private void btLog_Click(object sender, System.EventArgs e)
  882.         {
  883.             txtLog.Clear();
  884.         }                                                
  885.         public void LogFunc(string str)
  886.         {
  887.             if(txtLog != null)
  888.                 txtLog.Text += str + Environment.NewLine;
  889.         }
  890.         public void TraceLog(string str)
  891.         {
  892.             if(this.InvokeRequired)
  893.                 Invoke(new Log.TRACE_LOG(LogFunc), new object[]{str});
  894.             else
  895.                 LogFunc(str);
  896.         }
  897.         public void ErrLog(string str)
  898.         {
  899.             if(this.InvokeRequired)
  900.                 Invoke(new Log.ERR_LOG(LogFunc), new object[]{str});
  901.             else
  902.                 LogFunc(str);
  903.         }        
  904.     }  
  905.     public class diag_lib
  906.     {
  907.         public static string PadBuffer(string str, uint fromIndex, uint toIndex)
  908.         {
  909.             for(uint i=fromIndex; i < toIndex; ++i)
  910.                 str += "0";
  911.             return str;
  912.         }
  913.         public static string DisplayHexBuffer(object[] obj, DWORD dwBuffSize, 
  914.              WDC_ADDR_MODE mode)
  915.         {
  916.             string display = "";
  917.             switch(mode)
  918.             {
  919.             case WDC_ADDR_MODE.WDC_MODE_8:
  920.                 {
  921.                     BYTE[] buff = (BYTE[])obj[0];
  922.                     for(uint i=0; i<dwBuffSize; ++i)
  923.                         display = string.Concat(display, 
  924.                             buff[i].ToString("X2"), " ");
  925.                     break;
  926.                 }
  927.             case WDC_ADDR_MODE.WDC_MODE_16:
  928.                 {
  929.                     WORD[] buff = (WORD[])obj[0];
  930.                     for(int i=0; i<dwBuffSize/2; ++i)
  931.                         display = string.Concat(display, 
  932.                             buff[i].ToString("X4"), " ");
  933.                     break;
  934.                 }
  935.             case WDC_ADDR_MODE.WDC_MODE_32:
  936.                 {
  937.                     UINT32[] buff = (UINT32[])obj[0];
  938.                     for(int i=0; i<dwBuffSize/4; ++i)
  939.                         display = string.Concat(display,
  940.                             buff[i].ToString("X8"), " ");
  941.                     break;
  942.                 }
  943.             case WDC_ADDR_MODE.WDC_MODE_64:
  944.                 {
  945.                     UINT64[] buff = (UINT64[])obj[0];
  946.                     for(int i=0; i<dwBuffSize/8; ++i)
  947.                         display = string.Concat(display, 
  948.                             buff[i].ToString("X16"), " ");
  949.                     break;
  950.                 }
  951.             }                                
  952.             return display;
  953.         }
  954.         public static string DisplayHexBuffer(byte[] buff, uint dwBuffSize)
  955.         {
  956.             return DisplayHexBuffer(new object[]{buff}, dwBuffSize,
  957.                 WDC_ADDR_MODE.WDC_MODE_8);
  958.         }
  959.     };
  960.     /*holds the information relevant for a dma channel transfer*/
  961.     public class DmaInfo
  962.     {
  963.         private DmaBuffer m_dmaBuffer;
  964.         private PLX_DMA_CHANNEL m_plxChannel;
  965.         private IntPtr m_pBuffer;
  966.         public DmaInfo(DmaBuffer dmaBuffer, PLX_DMA_CHANNEL plxChn, IntPtr pBuffer)                        
  967.         {
  968.             m_dmaBuffer = dmaBuffer;
  969.             m_plxChannel = plxChn;
  970.             m_pBuffer = pBuffer;
  971.         }
  972.         public DmaBuffer DmaBuffer
  973.         {
  974.             get
  975.             {
  976.                 return m_dmaBuffer;
  977.             }
  978.             set
  979.             {
  980.                 m_dmaBuffer = value;
  981.             }
  982.         }
  983.         public WDC_DEVICE_HANDLE DeviceHandle
  984.         {
  985.             get
  986.             {
  987.                 return m_dmaBuffer.DeviceHandle;
  988.             }
  989.         }
  990.         public PLX_DMA_CHANNEL DmaChannel
  991.         {
  992.             get
  993.             {
  994.                 return m_plxChannel;
  995.             }
  996.         }
  997.         public IntPtr Buffer
  998.         {
  999.             get
  1000.             {
  1001.                 return m_pBuffer;
  1002.             }
  1003.         }
  1004.         public void Close()
  1005.         {
  1006.             if(m_dmaBuffer is DmaBufferSG && m_pBuffer != IntPtr.Zero)
  1007.                 Marshal.FreeHGlobal(m_pBuffer);
  1008.             m_dmaBuffer.Close();
  1009.         }
  1010.         public void Dispose()
  1011.         {
  1012.             Close();
  1013.         }
  1014.     }
  1015.     public class DmaInfoList : ArrayList
  1016.     {
  1017.         public void AddItem(DmaBuffer dmaBuffer, PLX_DMA_CHANNEL plxChn, IntPtr pBuffer)
  1018.         {
  1019.             DmaInfo dmaInfo = new DmaInfo(dmaBuffer, plxChn, pBuffer);
  1020.             this.Add(dmaInfo);
  1021.         }
  1022.         public DmaInfo GetItem(WDC_DEVICE_HANDLE hDev, PLX_DMA_CHANNEL plxChn)
  1023.         {
  1024.             Exception excp = new Exception();
  1025.                         
  1026.             foreach (DmaInfo dmaInfo in this)
  1027.                 if(dmaInfo.DeviceHandle == hDev && dmaInfo.DmaChannel == plxChn)
  1028.                     return dmaInfo;
  1029.             throw excp;
  1030.         }
  1031.         public DmaInfoList GetItems(WDC_DEVICE_HANDLE hDev)
  1032.         {
  1033.             DmaInfoList dmaDevList = new DmaInfoList();
  1034.             foreach (DmaInfo dmaInfo in this)
  1035.                 if(dmaInfo.DeviceHandle == hDev)
  1036.                     dmaDevList.Add(dmaInfo);
  1037.             return dmaDevList;
  1038.         }
  1039.         public bool IsDMAOpen(WDC_DEVICE_HANDLE hDev, PLX_DMA_CHANNEL plxChn)
  1040.         {
  1041.             try
  1042.             {
  1043.                 return (GetItem(hDev, plxChn) != null);
  1044.             }
  1045.             catch
  1046.             {
  1047.                 return false;
  1048.             }
  1049.         }
  1050.         public void Dispose()
  1051.         {
  1052.             foreach (DmaInfo dmaInfo in this)
  1053.                 dmaInfo.Dispose();
  1054.             this.Clear();
  1055.         }
  1056.     }
  1057. }