hello
i want to pass two pointers to function ...
my code requirement is that i need to pass value tusb_dev1 and tusb_dev2 as it contains different data depending on the usb device found...
and then accordingly the further function to set configuration is done on that device...
but i am unable to pass two pointers to the function......
can anyone help me regarding this.........
my code is as below
[code]
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <usb.h>
struct usb_device *tusb_dev1,*tusb_dev2 = NULL;
usb_dev_handle *tusb = NULL;
int x;
//******************* Function for 3210 *******************/
int usb_found(struct usb_device *tusb_dev1)//AND ALSO NEED TO INCLUDE tusb_dev2 in this line //
{
struct usb_device *tusb_dev1,*tusb_dev2;
struct usb_dev_handle *tusb;
if(x==1)
{
printf("\nDevice 3210 found\n");
printf("\ntusb_dev1 %d \n",tusb_dev1);
if(tusb_dev1==NULL)
{
printf("\ntusb_dev1 is null \n");
return 0;
}
if((tusb=usb_open(tusb_dev1))==NULL)
{
printf("Error opening 3210 USB device.\n");
return 1;
}
}
else if(x==2)
{
printf("\nDevice 3211 found\n");
printf("\ntusb_dev2 %d \n",tusb_dev2);
if(tusb_dev2==NULL)
{
printf("\ntusb_dev2 is null \n");
return 0;
}
if((tusb=usb_open(tusb_dev2))==NULL)
{
printf("Error opening 3211 USB device.\n");
return 1;
}
}
printf("\n (Setting Configuration ........)\n");
if(usb_set_configuration(tusb, 1))
{
perror("\n Can't set configuration");
printf("\n (make sure you have write access to the device)\n");
if(x==1)
{printf("\n (Access given to 3211)\n");
x=2;
printf("\n x==%d\n",x);
usb_found(tusb_dev2);
}
else
{printf("\n (Access given to 3210)\n");
x=1;
printf("\n x==%d\n",x);
usb_found(tusb_dev1);
}
return 1;
}
printf("\n (Claiming Interface........)\n");
usb_claim_interface(tusb, 0);
printf("\n out of usb_found function\n");
return;
}
int main(void)
{
struct usb_bus *bus;
struct usb_device *dev;
struct usb_device *tusb_dev1,*tusb_dev2 = NULL;
struct usb_dev_handle *tusb = NULL;
int device_found,dev_num,no_of_devices;
//int interface;
char ans;
usb_init();
usb_find_busses();
usb_find_devices();
for (bus = usb_busses; bus; bus = bus->next) {
for (dev = bus->devices; dev; dev = dev->next) {
if(dev->descriptor.idVendor==0x0451 && dev->descriptor.idProduct==0x3210)
{
tusb_dev1=dev;
printf("\ntusb_dev1 %d\n", tusb_dev1);
device_found =1;
//dev_num =dev_num++;
}
else if(dev->descriptor.idVendor==0x0451 && dev->descriptor.idProduct==0x3211)
{
tusb_dev2=dev;
printf("\ntusb_dev2 %d \n",tusb_dev2);
device_found =2;
}
}
}
if(device_found>=3)
{
printf("\nMore than 2 devices\n");
return;
}
else if(device_found ==0)
{
printf("\nNo device found\n");
return -1;
}
for (bus = usb_busses; bus; bus = bus->next) {
for (dev = bus->devices; dev; dev = dev->next) {
if(dev->descriptor.idVendor==0x0451 && dev->descriptor.idProduct==0x3210 && device_found==1)
{
x=1;
usb_found(tusb_dev1);
}
else if(dev->descriptor.idVendor==0x0451 && dev->descriptor.idProduct==0x3211 && device_found==2)
{
x=2;
usb_found(tusb_dev2);
}
}
}
do
{
printf("\n Wish to continue??\n");
ans=getchar();
}
while(ans =='y'|| ans =='Y');
if(tusb!=NULL)
{
usb_close(tusb);
printf("\n tusb closed\n");
}
return;
}