1

I am writing an application to communicate with a magnetic band reader through the libusb. in ubuntu 14.04 it works perfectly but in the pi rasperry when I execute the same code it shows me this error:

libusb: error [reap_for_handle] reap failed error -1 errno=14 libusb: error [handle_events] backend handle_events failed with error -1 libusb: error [sync_transfer_wait_for_completion] libusb_handle_events failed: LIBUSB_ERROR_IO, cancelling transfer and retrying,

This happens when he tries to read what comes through the port with the function:

u_char * answer ={'\0'};
u_char epAdress;
epAdress=0x81;
r=libusb_bulk_transfer(dev_handle,epAdress,answer,sizeof(answer),&actual, 0);
eyllanesc
  • 235,170
  • 19
  • 170
  • 241

2 Answers2

0

The endpoint 0x81 is an IN endpoint (i.e. device-to-host), since the direction bit (the most significant bit) is 1, which means you are moving data from the device into answer.

The problem is that u_char * answer = {'\0'} performs scalar initialization, and is equivalent to uchar * answer = '\0' and indeed equivalent to uchar * answer = 0.

Obviously, writing to memory location 0 will be invalid. I'm surprised it worked on Ubuntu, maybe the compiler managed to optimize out that write. What you should write instead is u_char answer[] = {'\0'} which will perform array initialization. Then when you pass answer to libusb_bulk_transfer, the array type will decay into a pointer type pointing to the start of the array.

jcarpenter2
  • 5,312
  • 4
  • 22
  • 49
0

Already solved the issue was a bug of the version of libusb that had installed from the default repository .. what I did was download the latest version of it and compile it into the rasperry and that was all worked perfect.

Here's [http://www.linuxfromscratch.org/blfs/view/cvs/general/libusb.html]