Hi All,
My requirement on QNX system is to detect USB device and inform other application for USB device added.
I have code to detect specific usb device attach to system but don’t know how to notify other application, usb device is added on usb port ?? Please have a look on my code
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
#include <sys/usbdi.h>
#define VENDOR 0x0951
#define DEVICE 0x1600
usbd_device_ident_t interest = {
VENDOR,
DEVICE,
USBD_CONNECT_WILDCARD,
USBD_CONNECT_WILDCARD,
USBD_CONNECT_WILDCARD,
};
usbd_funcs_t funcs = {
_USBDI_NFUNCS,
NULL,
NULL,
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;
}
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 ("\n 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
{
if (usbd_detach (device) != EOK)
printf ("\n usbd_detach (): error ! \n");
}
} // IF end
} // 1ST for loop
} // 2ND for loop
if (usbd_disconnect(connection )!= EOK)
printf ("\n usbd_disconnect (): error ! \n");
return 0;
}