none
DeviceIoControl API returning zero value RRS feed

  • Question

  • Hello,

             I have succeeded to setup and build an OS Design with Platform Builder WINC7. Now i am trying to call GIO driver through application. I was created  2D  array for GPIO pin number and pin direction in application and I am passing the array address to driver, I tried to print that array values, its printing but but the DeviceIoControl returning the zero value

    The below structure i  am using

    struct gpio_description_t{
    	HANDLE		hGPIO;
    	int		(*GPIOPin_info)[2];
    	int		numberofGPIOs;
    	DWORD		rbuff;
    };

    and 2D array is           

    GPIOPin[][2]= {{100,1},

    {102,0}, };

    This the Devicelocontrol function i am using

     rtrnVal = DeviceIoControl(hDriver,
                               IOCTL_GPIO_SETMODE,
                               gpio_desc->GPIOPin_info,
                             sizeof(gpio_desc->numberofGPIOs),
                              NULL,
                               0,
                             &bytesHandled,
                              NULL );

    In this function may be the problem with 3rd or 4th argument


                                               



    • Edited by vamsikolla Monday, February 9, 2015 1:17 PM
    Monday, February 9, 2015 12:53 PM

Answers

  • Vamsi,

    If the function is not a pointer function then it should return only one value rather then multiple return statements as I can see in your code.

    And modify the remaining code in the following way -

    for(innerloop = 0; innerloop < 2; innerloop++)
    		{
    			//RETAILMSG(TRUE, (TEXT("GPIO: 6! --------")));
    			RETAILMSG(TRUE, (TEXT("STRUCTURE - The value is %d \n "),gpio_desc->GPIOPin_info[lp][innerloop]));
    			gpio_info[innerloop] = gpio_desc->GPIOPin_info[lp][innerloop];
                 
    		}
    
    		rtrnVal = DeviceIoControl(hDriver,
                                    IOCTL_GPIO_SETMODE,
                                    &gpio_info,
                                    sizeof(gpio_info),
                                    NULL,
                                    0,
                                    &bytesHandled,
                                    NULL );
    		
    
    		if(rtrnVal == SUCCESS)
    		 {
    			RETAILMSG(TRUE, (TEXT("GPIO: 4! --------")));
    			}else{
    					RETAILMSG(TRUE, (TEXT("GPIO: 5! --------")));
    					return 0;
    		 }
    
    		RETAILMSG(TRUE,(TEXT("The last error is %d"), GetLastError()));
    		printf("\n\n\n\n");
    	}
    	 
    	return TRUE;

    Tuesday, February 10, 2015 1:01 PM

All replies

  • Vamsikolla:

    You wrote your question as if we know something about your project.   We do not, so we can't help much - other than to offer the following suggestions:

    1. Call GetLastError() when the call to DeviceIoControl() fails.  The error code can be looked up in winerror.h.
    2. Debug your driver
    3. Assume that we do not know anything about you or your project and tell us more.  Don't assume that we know anything about whatever your GIO driver is or how it works - again we do not.


    Bruce Eitman (eMVP) Senior Engineer Bruce.Eitman AT Eurotech DOT com My BLOG http://geekswithblogs.net/bruceeitman Eurotech Inc. www.Eurotech.com

    Monday, February 9, 2015 7:35 PM
    Moderator
  • Dear Bruce Eitman

          Thanks for the response.

    i have followed your documents related to GPIO application and API's. I am going to do the same thing but different logic. I have created one application and one api file. And in my logic I am using structure to store the informaiton. My application is calling the OpenGPIO ApI that is the part of API library. and its working fine. i.e Its calling the driver GIO_Init.

    Now I want to set the mode of GPIO. and in my application I am using  

    struct gpio_description_t{
    	HANDLE		hGPIO;
    	int		(*GPIOPin_info)[2];
    	int		numberofGPIOs;
    	DWORD		rbuff;
    };

    for storing the information. GPIOPin_info contains the information about GPIO pin and mode(direction)

    and

    GPIOPin[][2]= {{100,1},
    
    {102,0}, };

    in application for initializing array with pin number and direction

    struct gpio_description_t *gpio_desc_ptr, gpio_desc = {0, GPIOPin, 4};

    Here I am creating one structure pointer and assigning some default values.

    My application is as -

    #include "stdafx.h"
    #include "gpioapp.h"
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	//----------------Default Configuration for all GPIO's--------------
    	int GPIOPin[][2] = {{103,1},
    						{7,1},
    						{96,0},
    						{100,1},
                            };
    
    	struct gpio_description_t *gpio_desc_ptr, gpio_desc = {0, GPIOPin, 4};
    	
    
    	gpio_desc_ptr = &gpio_desc;
    	
    	RETAILMSG(TRUE, (TEXT("GPIO address= %d--------"),gpio_desc));
    	
    	//----------------Opening & checking a GPIO device --------------
    	if(OpenGPIO(gpio_desc_ptr)){
    		RETAILMSG(TRUE, (TEXT("SUCCESS: GPIO Device opened successfully! --------")));
    
    		if(SetGPIODir(gpio_desc_ptr)){
    			RETAILMSG(TRUE, (TEXT("SUCCESS: GPIO direction set successfully! --------")));
    		}
    	}
    
    	CloseGPIO(&gpio_desc);
    
    	return 0;
    }
    
    

    And my API for SetGPIODir is shown below -

    BOOL SetGPIODir(struct gpio_description_t *gpio_desc) { HANDLE Driver; //RETAILMSG(TRUE, (TEXT("The value of range %d \n"),gpio_desc->numberofGPIOs)); //RETAILMSG(TRUE, (TEXT("GPIO: 5! --------"))); hDriver = gpio_desc->hGPIO; int rtrnVal = 0, lp, range, innerloop; DWORD bytesHandled; RETAILMSG(TRUE, (TEXT(" --- The GPIOPin is %u \n"),gpio_desc->GPIOPin_info)); ////RETAILMSG(TRUE, (TEXT(" --- The base addres of GPIOPin is %d \n"),gpio_desc->GPIOPin_info));*/ int (*gpio_info)[2]; range = gpio_desc->numberofGPIOs; //int (*a)[2]; //RETAILMSG(TRUE, (TEXT("The value of range %d \n"),range)); for(lp = 0; lp < range; lp++) { for(innerloop = 0; innerloop < 2; innerloop++) { //RETAILMSG(TRUE, (TEXT("GPIO: 6! --------"))); RETAILMSG(TRUE, (TEXT("The value is %d \n "),gpio_desc->GPIOPin_info[lp][innerloop])); rtrnVal = DeviceIoControl(hDriver, IOCTL_GPIO_SETMODE, gpio_desc->GPIOPin_info, sizeof(gpio_desc->numberofGPIOs), NULL, 0, &bytesHandled, NULL ); // RETAILMSG(TRUE, (TEXT("The value is %d"),a[lp][innerloop])); }

    RETAILMSG(TRUE,(TEXT("The last error is %d"), GetLastError()));

    printf("\n\n\n\n"); if(rtrnVal == SUCCESS) { RETAILMSG(TRUE, (TEXT("GPIO: 4! --------"))); return 1; }else{ RETAILMSG(TRUE, (TEXT("GPIO: 5! --------"))); return 0; } } return TRUE; }


    Here some retailmsg for my checking.....

    The GetLastError() value is  as - 61191 PID:5bf0126 TID:510012a The last error is 87

    Thats i said something is wrong related to 3rd or 4th argument is wrong

    Tuesday, February 10, 2015 5:05 AM
  • Like Bruce said its difficult to say anything as we don't know about your driver/solution.

    - Debug your driver, that's the most efficient way to step trough your code and determine what's going wrong

    - enable logzones for your driver.

    - I don't see that your are calling createfile for your device driver? So what is the value of hDriver?

    Show us your device driver code as well, is IOControl() even called in your device driver?


    Good Luck,

    Erwin Zwart, eMVP
    Check out my blog: http://guruce.com/blog
    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.

    Tuesday, February 10, 2015 8:04 AM
  • I build Image in debug  mode . The following are debug messages 

    123050 PID:553008e TID:46700e2  --- The base addres of GPIOPin is 195360
     123051 PID:553008e TID:46700e2 GPIO address= 0--------
     123052 PID:553008e TID:46700e2 GPIO: 1! --------
     123053 PID:553008e TID:46700e2 OPENGPIO: HANDLE value is 29756931
     123053 PID:553008e TID:46700e2 GPIO: 3! --------
     123054 PID:553008e TID:46700e2 SUCCESS: GPIO Device opened successfully! --------
     123255 PID:553008e TID:46700e2  --- The  GPIOPin is 195360
     123255 PID:553008e TID:46700e2 The value is 103
    
     123256 PID:553008e TID:46700e2 The value is 1
    
     123257 PID:553008e TID:46700e2 The last error is 87
     123260 PID:400002 TID:46700e2 +HWSetRTS(0xa83772c0)
     123261 PID:553008e TID:46700e2 GPIO: 5! --------
     123261 PID:553008e TID:46700e2 closed! --------
     123262 PID:553008e TID:46700e2 Dll list:
     123263 PID:400002 TID:46700e2 COM_Close: (1 handles) total RX 1, total TX 8, dropped (mdd, pdd) 0,0
     123265 PID:553008e TID:46700e2 OSAXST1: <<< Unloading Module 'coredll.dll' (0x9E411B38) at address 0x40010000-0x40163000 in Process 'gpioapp.exe' (0x9E4A63F0)
     123266 PID:553008e TID:46700e2 OSAXST1: <<< Unloading Module 'normalize.dll' (0x9E4134CC) at address 0x401E0000-0x40200000 in Process 'gpioapp.exe' (0x9E4A63F0)
     123266 PID:553008e TID:46700e2 OSAXST1: <<< Unloading Module 'locale.dll' (0x9E413028) at address 0x40170000-0x401B1000 in Process 'gpioapp.exe' (0x9E4A63F0)
     123267 PID:553008e TID:46700e2 OSAXST1: <<< Unloading Module 'gpioapp.exe' (0x9E4A63F0) at address 0x00010000-0x00015000 in Process 'gpioapp.exe' (0x9E4A63F0)
    PB Debugger Unloaded symbols for 'GPIOAPP.EXE'

     
    Tuesday, February 10, 2015 11:34 AM
  • again Debug your driver - or -

    show us the code of the device driver


    Good Luck,

    Erwin Zwart, eMVP
    Check out my blog: http://guruce.com/blog
    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.

    Tuesday, February 10, 2015 12:55 PM
  • Vamsi,

    If the function is not a pointer function then it should return only one value rather then multiple return statements as I can see in your code.

    And modify the remaining code in the following way -

    for(innerloop = 0; innerloop < 2; innerloop++)
    		{
    			//RETAILMSG(TRUE, (TEXT("GPIO: 6! --------")));
    			RETAILMSG(TRUE, (TEXT("STRUCTURE - The value is %d \n "),gpio_desc->GPIOPin_info[lp][innerloop]));
    			gpio_info[innerloop] = gpio_desc->GPIOPin_info[lp][innerloop];
                 
    		}
    
    		rtrnVal = DeviceIoControl(hDriver,
                                    IOCTL_GPIO_SETMODE,
                                    &gpio_info,
                                    sizeof(gpio_info),
                                    NULL,
                                    0,
                                    &bytesHandled,
                                    NULL );
    		
    
    		if(rtrnVal == SUCCESS)
    		 {
    			RETAILMSG(TRUE, (TEXT("GPIO: 4! --------")));
    			}else{
    					RETAILMSG(TRUE, (TEXT("GPIO: 5! --------")));
    					return 0;
    		 }
    
    		RETAILMSG(TRUE,(TEXT("The last error is %d"), GetLastError()));
    		printf("\n\n\n\n");
    	}
    	 
    	return TRUE;

    Tuesday, February 10, 2015 1:01 PM
  • Dear partap Singh

     i have checked and tested the code. now the corresponding API is running fine.

    Tuesday, February 10, 2015 1:23 PM