我写了一个python包装CyAPI.lib版并使用VC++构建包装器项目。(我怀疑这与我的问题有关。)我正在使用Cypress Fx3拖缆示例设备和Cypress引导加载程序设备。在
CCyUSBDevice::Open(index)使Python崩溃(没有异常或回溯)。但是,如果我在visualstudio2008上用相同的设备、相同的驱动程序在同一台计算机上运行CCyUSBDevice::Open(index)函数可以正常工作。在
调用代码非常简单。请看下面的代码。 在Python中:
>>>from wrapprj import *
>>>try:
... openDevice() ###exception happens here and quit python,no way to get following exception No. and string.
...except Exception as e:
... print "exception is {0}:{1}".format(e.errno,e.strerror)
自动换行文件:
^{pr2}$在CPP文件中:
extern "C" bool
call_openCyUSBDevice(void)
{
devHandler = new CCyUSBDevice(NULL,CyUSBDevice_GUID,False);//don't try to open the device here. Otherwise exception happens here.
if (NULL == devHandler)
{
return FALSE;
}
return devHandler->Open(0); // exception happens. But if I add some printing before this line, it CAN OPEN correctly. STRANGE!
}
在Cyapi.h中,CCyUSBDevice::Open()的定义如下:
class CCyUSBDevice
{
public:
CCyUSBDevice(HANDLE hnd = NULL, GUID guid = CYUSBDRV_GUID, BOOL bOpen = true);
~CCyUSBDevice(void);
.
.
bool Open(UCHAR dev);
.
.
}
在VisualStudioC++ 2008中,我运行代码,这样做很好: public ref class Form1 : public System::Windows::Forms::Form
{
public:
CCyUSBDevice *USBDevice;
public:
Form1(void)
{
InitializeComponent();
USBDevice = new CCyUSBDevice(NULL,CyUSBDevice_GUID,False);
USBDevice->Open(0);
}
.
.
}
为什么VC++可以正确地打开设备,而python包装器却不能,因为它们都调用相同的底层代码?在
目前没有回答
相关问题 更多 >
编程相关推荐