On Mon, 27 Jun 2005, coin wrote:

> Sorry but I did not understand you.
> Once that I disconnect with this program:

It's easy to understand your confusion.  When I say "disconnect", I mean
"unplug the USB device".  Your program here does a USBDEVFS_DISCONNECT
ioctl, which is very different.  (USBDEVFS_DISCONNECT is a very poor name
IMHO; it really should be USBDEVFS_UNBIND.)

> nt main(){
>       struct usbdevfs_ioctl ctrl;
>       int fd;
>       fd = open("/proc/bus/usb/002/003", O_RDWR);
>       if(fd != -1) {
>               ctrl.ifno = 0; 
>               ctrl.ioctl_code = USBDEVFS_DISCONNECT;
>               ioctl(fd, USBDEVFS_IOCTL, &ctrl);
>               perror("ioctl");
>               close(fd);
>       } 
>       return 0;
> }
> 
> I received that:
> ioctl: Success
> syslog said:
> udev[9242]: removing device node '/dev/usb/hiddev0'

That's good.

> when I claim with this program:
> 
> int main(){
>       int fd;
>       int interface=0,*inter;
>       inter=&interface;
>       fd = open("/proc/bus/usb/002/003", O_RDWR);
>       if(fd != -1) {
>               ioctl(fd, USBDEVFS_CLAIMINTERFACE, &interface);
>               perror("ioctl");
>               close(fd);
>       } 
>       return 0;
> }
> 
> I received that:
> ioctl: Success
> And syslog did not said anything

Again that's good.  Sort of.

> when I try to send data with:
> int main(){
>       struct usbdevfs_bulktransfer bulk;
>       int fd;
>       int ret,*data,dato=0xFF;
>       data=&dato;
>       fd = open("/proc/bus/usb/002/003", O_RDWR);
>       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_BULK, &bulk);
>               perror("ioctl");
>               close(fd);
>       } 
>       return 0;
> }
> 
> 
> I received:
> ioctl: Invalid argument
> And syslog said that:
> kernel: usb 2-1: usbfs: process 9272 (enviar) did not claim interface
> 0 before use
> kernel: usb 2-1: usbfs: USBDEVFS_BULK failed ep 0x1 len 4 ret -22

The problem is that you are using three separate programs.  For the
USBDEVFS_DISCONNECT ioctl it's okay, because once the HID driver has been
unbound from the device it remains unbound.  But it's not okay for the 
second and third programs.  Your second program uses 
USBDEVFS_CLAIMINTERFACE to bind the interface, but the binding 
automatically goes away when the program ends and the file descriptor is 
closed.  That's why the third program fails; when it runs the interface is 
once again unbound.

You need to combine your second and third programs into one single 
program.

> Thank you 
> And sorry but my english is not good.

No need to apologize; your English is very understandable.

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

Reply via email to