I took this code from the forums here
openqnx.com/index.php?name=P … usb+device
but it doesn’t work, it connects to the USB stack but fails on usbd_attach()
I changed the VENDOR and DEVICE to my usb stick.
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/usbdi.h>
#define VENDOR 0x0d7d
#define DEVICE 0x1400
usbd_device_ident_t interest =
{
VENDOR,
DEVICE,
USBD_CONNECT_WILDCARD,
USBD_CONNECT_WILDCARD,
USBD_CONNECT_WILDCARD,
};
usbd_funcs_t funcs =
{
_USBDI_NFUNCS,
NULL,//insertion,
NULL,//removal,
NULL
};
usbd_connect_parm_t cparms =
{
NULL,
USB_VERSION,
USBD_VERSION,
0,
0, // argc
NULL, // *argv
0,
&interest,
&funcs
};
struct usbd_connection *connection;
struct usbd_device *device;
usbd_device_instance_t instance;
usbd_device_descriptor_t *ddesc=NULL;
struct usbd_desc_node *node=NULL;
usbd_string_descriptor_t *sdesc=NULL;
int main (void)
{
int error,status;
int devno,hostid;
char* ID;
error = usbd_connect (&cparms, &connection);
if (error != EOK)
{
printf ("\n usbd_connect() error number: %d \n",error);
return -1;
}
printf("usbd_connect okay\n");
instance.config = 1;
instance.iface = 0;
instance.alternate = 0;
for (hostid =0; hostid < 8; ++hostid)
{
for (devno = 0; devno < 16; ++devno)
{
memset(&instance, USBD_CONNECT_WILDCARD,sizeof(usbd_device_instance_t));
instance.path = hostid;
instance.devno = devno;
status = usbd_attach(connection, &instance,0,&device);
// the device has been found
if (status == EOK)
{
ddesc = usbd_device_descriptor(device,&node );
if (ddesc == NULL )
{
printf("\n usbd_device_descriptor () error !!\n");
return -1;
}
// is it a specific device ?
if (ddesc->idVendor == VENDOR)
{
sdesc = usbd_languages_descriptor(device,&node );
ID = usbd_string(device,3,sdesc->bString[0]);
printf ("I found it -> hostid: %d, devno: %d, seriall number:%s \n",hostid,devno,ID);
if (usbd_detach (device) != EOK)
printf ("\n usbd_detach (): error ! \n");
}
else
{
printf("Vender=%x\n",ddesc->idVendor);
if (usbd_detach (device) != EOK)
printf ("\n usbd_detach (): error ! \n");
}
}
}
}
if (usbd_disconnect(connection )!= EOK)
printf ("\n usbd_disconnect (): error ! \n");
return 0;
}