On Tue, 28 Jun 2005, coin wrote:
> Sorry but I was wrong compiling.
>
> This is my programa
Your program has one big error and a few things that could be improved.
> int main(){
> struct usbdevfs_bulktransfer bulk;
> struct usbdevfs_ioctl ctrl;
> int fd;
> int ret,*data,dato=0xFF,interface=0x00,*inter;
dato is a 4-byte integer variable, initialized to 0xFF. On a
little-endian system (like x86) it will be stored in memory as
0xFF 0x00 0x00 0x00
and on a big-endian system (like PPC) it will be stored in memory as
0x00 0x00 0x00 0xFF
Probably only one of these is what you want to send to the USB device.
You should change the program so that it will work the same on any kind of
computer. For example, you could write instead:
static unsigned char dato[4] = {0xFF, 0, 0, 0};
> //data=&dato;
Why is this line commented out? Now data is uninitialized. No wonder
your program fails!
> inter=&interface;
You don't need inter at all since it isn't used below.
You don't really need data either, because below you could simply write
bulk.data = &dato;
> fd = open("/proc/bus/usb/002/003", O_RDWR);
It would make your program more flexible if the bus and device numbers
were passed as command-line arguments instead of being fixed numbers.
After all, those numbers will change every time you plug in the USB
device.
> if(fd != -1) {
> //bulk.ep = USB_DIR_IN | 1;
> bulk.ep = 1;
> bulk.len = 4;
> bulk.data = data;
> bulk.timeout = 1000;
> //bulk.data = malloc(1024);
> ioctl(fd, USBDEVFS_CLAIMINTERFACE, &interface);
> perror("ioctl");
> ret=ioctl(fd, USBDEVFS_BULK, &bulk);
> perror("ioctl");
> close(fd);
> }
Why don't you print an error message if fd == -1?
> return 0;
> }
>
> I received this:
> ioctl: Success
> ioctl: Invalid argument
>
> syslog
> kernel: usb 2-2: usbfs: USBDEVFS_BULK failed ep 0x1 len 4 ret -22
This error occurred because bulk.data was set to a garbage value, not to
the address of dato.
Alan Stern
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel