/**************************** * Device Open & Close * *****************************/ /* public methods */ public virtual DWORD Open()//pcie类方法 { DWORD dwStatus; WD_PCI_CARD_INFO deviceInfo = new WD_PCI_CARD_INFO();//定义一个设备数据类 //检索设备源信息 /* Retrieve the device's resources information */ deviceInfo.pciSlot = slot; dwStatus = wdc_lib_decl.WDC_PciGetDeviceInfo(deviceInfo); //调用API 获得状态信息 if ((DWORD)wdc_err.WD_STATUS_SUCCESS != dwStatus) //如果不成功 { Log.ErrLog("PCIE_Device.Open: Failed retrieving the " + "device's resources information. Error 0x" + //在log中打印数据 dwStatus.ToString("X") + ": " + utils.Stat2Str(dwStatus) + "(" + this.ToString(false) + ")"); return(dwStatus); } /* NOTE: You can modify the device's resources information here, * if necessary (mainly the deviceInfo.Card.Items array or the * items number - deviceInfo.Card.dwItems) in order to register * only some of the resources or register only a portion of a * specific address space, for example. * 注意:如果需要,您可以在此处修改设备的资源信息(主要是deviceInfo.Card.Items数组或项目编号 - deviceInfo.Card.dwItems), * 以仅注册一些资源或仅注册特定部分 地址空间,例如。 */ dwStatus = wdc_lib_decl.WDC_PciDeviceOpen(ref m_wdcDevice, deviceInfo, IntPtr.Zero, IntPtr.Zero, "", IntPtr.Zero); //状态正常之后尝试打开 if ((DWORD)wdc_err.WD_STATUS_SUCCESS != dwStatus) //如果打开失败 { Log.ErrLog("PCIE_Device.Open: Failed opening a " + "WDC device handle. Error 0x" + dwStatus.ToString("X") + ": " + utils.Stat2Str(dwStatus) + "(" + this.ToString(false) + ")"); goto Error; } Log.TraceLog("PCIE_Device.Open: Opened a PCI device " + this.ToString(false)); //更新 成功打开 调用tostring方法 /* Validate device information */ //验证信息 地址空间是否存在 if (DeviceValidate() != true) { dwStatus = (DWORD)wdc_err.WD_NO_RESOURCES_ON_DEVICE; goto Error; } return(dwStatus); Error: if (Handle != IntPtr.Zero) { Close(); } return(dwStatus); }
/**************************** * Device Open & Close * *****************************/ /* public methods */ public virtual DWORD Open() { DWORD dwStatus; deviceInfo = new WD_PCI_CARD_INFO(); /* Retrieve the device's resources information */ deviceInfo.pciSlot = slot; dwStatus = wdc_lib_decl.WDC_PciGetDeviceInfo(deviceInfo); if ((DWORD)wdc_err.WD_STATUS_SUCCESS != dwStatus) { Log.ErrLog("C6678DSP_Device.Open: Failed retrieving the " + "device's resources information. Error 0x" + dwStatus.ToString("X") + ": " + utils.Stat2Str(dwStatus) + "(" + this.ToString(false) + ")"); return(dwStatus); } /* NOTE: You can modify the device's resources information here, * if necessary (mainly the deviceInfo.Card.Items array or the * items number - deviceInfo.Card.dwItems) in order to register * only some of the resources or register only a portion of a * specific address space, for example. */ dwStatus = wdc_lib_decl.WDC_PciDeviceOpen(ref m_wdcDevice, deviceInfo, IntPtr.Zero, IntPtr.Zero, "", IntPtr.Zero); if ((DWORD)wdc_err.WD_STATUS_SUCCESS != dwStatus) { Log.ErrLog("C6678DSP_Device.Open: Failed opening a " + "WDC device handle. Error 0x" + dwStatus.ToString("X") + ": " + utils.Stat2Str(dwStatus) + "(" + this.ToString(false) + ")"); goto Error; } Log.TraceLog("C6678DSP_Device.Open: Opened a PCI device " + this.ToString(false)); /* Validate device information */ if (DeviceValidate() != true) { dwStatus = (DWORD)wdc_err.WD_NO_RESOURCES_ON_DEVICE; goto Error; } return(dwStatus); Error: if (Handle != IntPtr.Zero) { Close(); } return(dwStatus); }