473,396 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

passing pointers to a function

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;
}
Oct 19 '08 #1
0 1218

Sign in to post your reply or Sign up for a free account.

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
3
by: John C | last post by:
Hi, I am a little uncertain about the concept of passing a reference to a class to another instance of a class. for instance I thought that the following was ok: Network network = Network();...
8
by: kalinga1234 | last post by:
there is a problem regarding passing array of characters to another function(without using structures,pointer etc,).can anybody help me to solve the problem.
2
by: Morgan | last post by:
Thanks to all of you because I solved the problem related with my previous post. I simply made confusion with pointers to pointers and then succeeded passing the reference to the first element...
2
by: LeTubs | last post by:
Hi I'm think I'm having some problem with pointers..... namely passing them around...Or I think ? I've used gdb to find the following (note conn is of type MYSQL *conn). Program received...
11
by: cps | last post by:
Hi, I'm a C programmer taking my first steps into the world of C++. I'm currently developing a C++ 3D graphics application using GLUT (OpenGL Utility Toolkit written in C) for the GUI...
8
by: Ivan Liu | last post by:
Hi, I'd like to ask if passing an object as an pointer into a function evokes the copy constructor. Ivan
4
by: Christian Maier | last post by:
Hi After surfing a while I have still trouble with this array thing. I have the following function and recive a Segmentation fault, how must I code this right?? Thanks Christian Maier
2
by: luis | last post by:
I'm using ctypes to call a fortran dll from python. I have no problems passing integer and double arryas, but I have an error with str arrys. For example: ..... StringVector = c_char_p *...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.