Raghav Puranmalka wrote:
> Hi,
>
> I am trying to communicate with a FX2 USB device that I have. I am
> able to submit control transfers just fine. However, when I try to do
> a bulk transfer, I get a segmentation fault. I'm not sure what is
> happening. Any help would be appreciated.
>
> The code segment that is segfaulting is below:
>
>
> #define FLEX_2_EP 0x02
>
> //m_hDeviceHandle is a pointer libusb_device_handle
>
> int *nBytes;
> int result;
>
> char c = 'R';
> unsigned char endpoint = FLEX_2_EP;
> result = libusb_bulk_transfer(m_hDeviceHandle, endpoint, (unsigned
> char*) &c, sizeof(c), nBytes, 0); //segfault occurs here
>
Yes. You have a C misunderstanding here. The next to the last
parameter is an OUTPUT parameter. It doesn't want you to hand it an
"int *", it wants you to hand it the address of an "int" so that it can
fill in the number of bytes it actually sent. As it is, nBytes contains
garbage, and libusb tries to store the number of bytes at that garbage
address.
Change it to this:
int nBytes;
result = libusb_bulk_transfer( ..., sizeof(c), &nBytes, 0 );
--
Tim Roberts, ti...@pr...
Providenza & Boekelheide, Inc.
|