LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-31-2013, 12:14 PM   #1
uhum2004
LQ Newbie
 
Registered: Sep 2005
Location: Hungary, Budapest
Distribution: Ubuntu
Posts: 4

Rep: Reputation: 0
usb_interrupt_read() returns device busy


Hi all,
I'm getting familiar with usb programming.
I can find my device based on a string search, but cannot read it.
My explore() counts the items connected and if one - and only one - is connected, then opens it.
This works fine, but when I try to read it I get error -16 /* Device or resource busy */
Any ide, please?


Code:
/* main.c */

#include <stdio.h>
#include <string.h>
#include <usb.h>
#include "myusbfunctions.h"

#define BREAK_HERE raise(SIGINT)

char version[] = "This is my string";
struct usb_device *curr_dev;
struct usb_dev_handle *curr_udev;
int	timeout = 2200;

#define	buflen	64
char buffer[buflen];

int main(void)
{
int i;

i=explore();										/* nr of matches */
if (0==i)
	{
	printf("No abs chip was found\n");
	exit(0);
	}
else
	{
	if (i>1)
		{
		printf("Confict: more than one chip was found\n");
		exit(0);
		}
	}
printf("%s\n", version);
//BREAK_HERE;
//i = usb_interrupt_read(curr_udev, curr_dev->config->interface->altsetting->endpoint->bEndpointAddress, buffer, curr_dev->config->interface->altsetting->endpoint->wMaxPacketSize, timeout);

	i=usb_interrupt_read(curr_udev, 0x81, buffer, 64, 2200);
	printf("i=%d\n",i);

usb_close (curr_udev);
return 0;
}
/* eof main.c */
and

Code:
/* myusbfunctions.h */
extern struct usb_device *curr_dev;
extern struct usb_dev_handle *curr_udev;
extern int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size, int timeout);

int explore (void)
{
struct usb_bus *bus;
struct usb_device *dev;
extern char version[];
int nr=0 ;

usb_init();
usb_find_busses();
usb_find_devices();

for (bus = usb_busses; bus; bus = bus->next)
	{
	for (dev = bus->devices; dev; dev = dev->next)
		{
		int ret;
		char string[256];
		usb_dev_handle *udev;

		udev = usb_open(dev);
		if (udev)
			{
			if (dev->descriptor.iManufacturer)
				{
				ret = usb_get_string_simple(udev, dev->descriptor.iManufacturer, string, sizeof(string));
				}

			if (dev->descriptor.iProduct)
				{
				ret = usb_get_string_simple(udev, dev->descriptor.iProduct, string, sizeof(string));
				if (ret > 0)
					{
					if (0==strcmp(version,string))	/* match */
						{
						curr_dev = dev;	/* copy device */
						nr++;
						}
					}
				}
			usb_close (udev);
			}
		}
	}
if (nr == 1)
	{
	curr_udev = usb_open(curr_dev);
	}
return nr;
}

/* eof myusbfunctions.h */
 
Old 06-01-2013, 10:22 AM   #2
uhum2004
LQ Newbie
 
Registered: Sep 2005
Location: Hungary, Budapest
Distribution: Ubuntu
Posts: 4

Original Poster
Rep: Reputation: 0
To help others with the same problem I answer my own question.
Another forum helped: the kernel hid is the problem. Removing it the read is ok without any modification.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] device-mapper? special device does not exist, already mounted or busy ezekieldas Linux - Software 1 05-23-2011 09:59 PM
mdadm --manage /dev/md0 --add /dev/sdb1 returns device busy JeepingAZ Linux - Desktop 2 02-17-2011 12:18 PM
Error opening PCM device Device or resource busy Herbivore Linux - Newbie 2 08-23-2008 01:45 AM
mdadm: device is busy yet not busy? disbeliever Linux - Server 7 07-24-2008 04:38 PM
Can't open audio device. Device or resource busy. deepumnit Linux - Software 2 06-16-2008 09:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration