|
From: Dave H. <DAV...@ni...> - 2007-06-06 12:59:23
|
Help, please. I've started writing a programme to use libusb-win32, but
I'm getting an error right at the start.
First, some background. I've used libusb under Linux (Fedora Core 5)
successfully, to write driver functions for the first USB device that I
wrote firmware for. That device works entirely happily under FC5 and
under RISC O (yes, the Acorn/Pace/Castle one). I have now written
firmware for a second device. Perhaps unsurprisingly, this device's
firmware is very heavily based on the previous one. This device also
works entirely happily under RISC OS. I thought I'd try this Windows
thing, but I'm having no success.
The entire programme is here:
// Can I get this system to do what I want?
#include <usb.h>
#include <stdio.h>
#define VENDOR_ID_NICE 0x16A8
#define PRODUCT_ID_CONTACT_CLOSURE 0x0004
int init (void)
{
//int usb_busses;
struct usb_bus* bus;
struct usb_device* dev;
usb_dev_handle *udev;
int retval =3D -1;
int uci;
int done =3D 0;
printf ("Hello\n");
usb_init ();
usb_find_busses ();
usb_find_devices ();
for (bus =3D usb_get_busses (); bus; bus =3D bus->next)
{
for (dev =3D bus->devices; dev && (done =3D=3D 0); dev =3D
dev->next)
{
udev =3D usb_open (dev);
printf ("udev =3D %p\n", udev);
if ((dev->descriptor.idVendor =3D=3D VENDOR_ID_NICE)
&& (dev->descriptor.idProduct =3D=3D
PRODUCT_ID_CONTACT_CLOSURE))
{
printf ("Found it!\n");
uci =3D usb_claim_interface (udev, 0);
printf ("Return value from
usb_claim_interface: %d\n", uci);
retval =3D uci;
done =3D 1;
}
else
{
printf ("Not ours, VID =3D %04X, PID =3D
%04X\n", dev->descriptor.idVendor, dev->descriptor.idProduct);
usb_close (udev);
printf ("Closed: %p\n", udev);
}
}
}
return retval;
}
int main (void)
{
int init_result;
init_result =3D init ();
if (init_result =3D=3D 0)
{
printf ("Starting...\n");
}
else
{
printf ("Failed\n");
}
}
When I run it, I get a couple of "Not ours, VID =3D " etc. messages for
other USB items I have, followed by "Found it!" But then "Return value
from usb_claim_interface: -22" which I don't understand. I think it
indicates an illegal parameter. udev must be OK, I assume. My device
only has interface 0. It's a very simple device, with a vendor-specific
protocol, specified at interface level.
Can anyone see what I'm doing wrong, please?
libusb-win32 downloaded from the main libusb-win32 site this week. No
previous copy on this computer. Windows XP.
Dave
***************************************************************************=
***************************************************************************=
***************************************************************************=
****************
NICE CTI Systems UK Limited ("NICE") is registered in England under company=
number, 3403044. The registered office of NICE is at Tollbar Way, Hedge E=
nd, Southampton, Hampshire SO30 2ZP.
Confidentiality: This communication and any attachments are intended for th=
e above-named persons only and may be confidential and/or legally privilege=
d. Any opinions expressed in this communication are not necessarily those o=
f NICE. If this communication has come to you in error you must take no act=
ion based on it, nor must you copy or show it to anyone; please delete/dest=
roy and inform the sender by e-mail immediately.
Monitoring: NICE may monitor incoming and outgoing e-mails.
Viruses: Although we have taken steps toward ensuring that this e-mail and=
attachments are free from any virus, we advise that in keeping with good c=
omputing practice the recipient should ensure they are actually virus free.
***************************************************************************=
***************************************************************************=
***************************************************************************=
*******************
=20
|