CCyUSBDevice::open()  got exception

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi everyone,

   

I wrote a python wrap for CyAPI.h and build the wrap on VC++. (not sure whether this is related to my problem.) And I am using Fx3 streamer example device as well as bootloader device.

   

I create a new cyusb device instance by calling new CCyUSBDevice() from Python command line, I got an exception and forced to quit python. After some debugging I found out that the exception happened when constructor function tried to open the device. If I choose not to open the device, the instance is created successfully, and I can get the device number by DeviceCount(). 

   

I am running this on winxp virtual machine and windows 7 laptop. And I tried vc++ example codes, which have no problem creating and opening instances. So I assume this must be something related to my python wrap. But the calling codes are really simple. Please take a look at the following codes.

   

In wrap file:

   

static PyObject *
do_createInstance(PyObject *self, PyObject *args)
{
    bool ret = False;
    ret=call_createInstance();
    return Py_BuildValue("O", ret?Py_True: Py_False);

   

}

   

In CPP file:

   

extern "C" bool
call_createInstance(void)
{
    int devnum=0;
    devHandler = new CCyUSBDevice();   //exception happens here.
    devnum=devHandler->DeviceCount(); //if I set bOpen to False, I can get this line and get devnum=1.
    if(0==devnum)
        return FALSE;
    return TRUE;
}

   

Why VC++ can open device correctly but my python wrap can not? They are eventually calling the same function. 

   

Can someone help me to find the cause of the error? Thank you very much.

0 Likes
1 Reply
Anonymous
Not applicable

The following amazingly make Open(device) work. Call from python command line.

   

1. devHandler=CCyUSBDevice(NULL, Cyusb_guid, False) //don't open device while create new instance

   

2. add some printing

   

3. open(0)

   

Looks like the printing helped. But Why?

0 Likes