LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 01-21-2014, 09:13 AM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
usb.h and libusb.


Hi:
Code:
#include <usb.h>
#include <stdio.h>
#include <string.h>
unsigned short IDVendor=   0x1384;              /*VID must be changed. */
unsigned short IDProduct=  0x8888;              /*PID must be changed. */

...........................

int main(int argc, char **argv)
{
        usb_dev_handle *d=NULL;
        unsigned char buffer[3];
        int i, mode, ret;
        char string[256];

        if(argc <2)
        {
                printf("give the voltage value.\n");
                exit(1);
        }
        i=floor(atof(argv[1])*51) ;
 if(i>255){printf("value must be between 0 and 5V\n"); exit(1);} 
        mode=0;
usb_init();
ret=usbOpenDevice(&d, IDVendor,IDProduct);
if(ret!=0){printf("usbOpenDevice failed\n"); return 0;}

	ret=usb_control_msg(d, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, mode, i, 0, (char *)buffer, sizeof(buffer), 5000);

//      printf("buffer %d \n", buffer[0]);
        return 0;
}
This is part of an application program running on linux. Looking for documentation for usb_control_msg(), shown in the last lines above, I first went to /usr/include/usb.h, that is in the #include's (first lines), and the function was there. Looking for the source, I found /usr/src/linux-3.2.29/drivers/usb/core/message.c, where it is defined but, alas, here it has the arguments in different order and they are 9 instead of 8). As the author asks for the libusb library, the logical thing was to look in its sources, which I installed, just now, from the O.S. distribution disks. But here there is no usb_control_msg(), nor even the usb.h file!

So, what should the source for usb.h be?

Note: in usb.h there is declared a function usb_control_msg with the same number and order of parameters as in my source.
 
Old 01-21-2014, 03:16 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by stf92 View Post
Looking for the source, I found /usr/src/linux-3.2.29/drivers/usb/core/message.c, where it is defined but, alas, here it has the arguments in different order and they are 9 instead of 8).
Continued from this thread, I think there is some confusion between libusb and the linux usb driver:
Quote:
Originally Posted by pan64 View Post
in general you do not need the source, just the documentation.
http://libusb.sourceforge.net/doc/fu...ontrolmsg.html
but sometimes it is not sufficient. In that case you can try to browse the source here:
http://lxr.free-electrons.com/source.../message.c#L81
(but I'm not really sure if it was the same version)
The documentation appears to be for the user space libusb function (8 args), and the source link is to the kernel driver (9 args).

The main page for libusb is http://www.libusb.org/, usb_control_msg is documented in the 0.1 (legacy) documentation, but not in the 1.0 version, presumably it was removed. There is a link to the 0.1 code which does contain usb_control_msg.

EDIT: the 0.1 code is libusb-compat-0.1:
Quote:
a compatibility library which provides the libusb-0.1 API by using the libusb-1.0 API.
So it won't be very enlightening to read its sources.

Last edited by ntubski; 01-21-2014 at 03:24 PM.
 
1 members found this post helpful.
  


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
LIBUSB - usb driver with non-root credentials Sorab Linux - Software 2 04-28-2017 07:40 AM
When will libusb plan to support USB 3.0? jiapei100 Linux - Software 2 05-01-2011 05:18 PM
Libusb on USB 3.0 Device and kernel 2.6.39-rc3 Equinn Programming 4 04-27-2011 11:30 AM
LIBUSB - usb driver with non-root credentials (repost) Sorab Fedora 1 04-25-2007 02:54 AM
libusb and C quesition - simple USB driver vargadanis Programming 2 01-14-2007 01:33 PM

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

All times are GMT -5. The time now is 11:57 PM.

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