hidden hit counter
Welcome to Soft32 Forums!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

USB:Pipe not Opening!

 
   Soft32 Home -> Windows -> Device Driver RSS
Next:  Hot keys from other programs  
Author Message
sanju

External


Since: May 04, 2009
Posts: 5



(Msg. 1) Posted: Tue May 26, 2009 6:23 am
Post subject: USB:Pipe not Opening!
Archived from groups: microsoft>public>windowsxp>device_driver>dev (more info?)

Hi all,

I'm developing a sample USB application on the host side, but it is
failing to open the pipe and write; It is getting the handle and
device path everything properly. I verified with the rwbulk.exe which
is provided by the microsoft as sample with the Win DDK. Even that is
getting the same device path and the pipe name and opening it nicely,
but my application is returning error code 2(ERROR_FILE_NOT_FOUND) in
the createfile for the pipe.

Can anyone help me in identifying why it is failing?

I'm using the LoopBack DSF sample as my device. and that is configured
to use bulkusb.sys.

#include "UsbDev.h"
#include <conio.h>
#include "setupapi.h"
#include "bulkusr.h"
#include "usbio.cpp"
#include <tchar.h>

char myPointer[200]={0};

HANDLE USBDeviceOpen(LPGUID );

HANDLE open_file (PCHAR);
HANDLE UsbRead ();
HANDLE UsbWrite ();
int ResetPipe(HANDLE);
void test(PUCHAR, ULONG *);

char inPipe[32] = "PIPE00";
char outPipe[32] = "PIPE01";
char DeviceName[256] = "";

int main()
{
HANDLE hOut = INVALID_HANDLE_VALUE;
INT getInput;
CHAR Exit = 0;
#if 1
hOut = USBDeviceOpen((LPGUID) &GUID_CLASS_I82930_BULK);
if(hOut) {
printf("Device Opened SuccessFully\n");
}
else {
printf("Calling Exit.........\n");
exit(0);
}
#endif
do {

printf("\n0. Exit \n");
printf("1.Write \n ");

printf("\nSelect the operation you want to perform:
");
scanf("%d", &getInput);

switch(getInput) {
case 0:
Exit = 1;
break;

case 1:
printf("\nwrite has not implemented\n");
UsbWrite();
break;

default:
printf("\nInvalid input\n");
break;
}

}while(Exit != 1);

CloseHandle(hOut);
return 0;

}

HANDLE USBDeviceOpen(LPGUID pguid)
{

HDEVINFO
hardwareDeviceInfo;
PSP_DEVICE_INTERFACE_DETAIL_DATA
functionClassDeviceData = NULL;
SP_DEVICE_INTERFACE_DATA deviceInfoData;

ULONG
predictedLength = 0;

ULONG
requiredLength = 0;

HANDLE
hOut =INVALID_HANDLE_VALUE;

CHAR
*devName = NULL;

ULONG
ErrCode = 0;
//LPCTSTR dev;

hardwareDeviceInfo = SetupDiGetClassDevs(pguid,
NULL, // Define no
enumerator (global)
NULL, // Define no
(DIGCF_PRESENT | // Only
Devices present

DIGCF_DEVICEINTERFACE)); // Function class devices.

if (hardwareDeviceInfo == INVALID_HANDLE_VALUE)
{
printf("Invalid handle from SetupDiGetClassDevs \n");
// return INVALID_HANDLE_VALUE;
}

deviceInfoData.cbSize = sizeof (SP_DEVICE_INTERFACE_DATA);
if (!SetupDiEnumDeviceInterfaces(hardwareDeviceInfo,
NULL, // We don't care about
specific PDOs
pguid,
0,
&deviceInfoData))
{
// printf("SetupDiEnumDeviceInterfaces Failed \n");
printf("Device not found %d\n",GetLastError());
getch();
return 0;

}

if (SetupDiGetDeviceInterfaceDetail(hardwareDeviceInfo,
&deviceInfoData,
NULL, // probing so no
output buffer yet
0, // probing so output
buffer length of zero
&requiredLength,
NULL)) // not interested in
the specific dev-node
{
printf("SetupDiGetDeviceInterfaceDetail Failed \n");
// return INVALID_HANDLE_VALUE;
}

if (ERROR_INSUFFICIENT_BUFFER != GetLastError())
{
printf("ERROR_INSUFFICIENT_BUFFER \n");
// return INVALID_HANDLE_VALUE;
}

predictedLength = requiredLength;
// sizeof (SP_FNCLASS_DEVICE_DATA) + 512;

functionClassDeviceData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc
(predictedLength);

if (NULL == functionClassDeviceData)
{
printf("Allocation Failed \n");
// return INVALID_HANDLE_VALUE;
}

functionClassDeviceData->cbSize = sizeof
(SP_DEVICE_INTERFACE_DETAIL_DATA);

if (!SetupDiGetDeviceInterfaceDetail(hardwareDeviceInfo,

&deviceInfoData,

functionClassDeviceData,

predictedLength,

&requiredLength,

NULL))
{
free(functionClassDeviceData);

printf("SetupDiGetDeviceInterfaceDetail Failed \n");
// return INVALID_HANDLE_VALUE;
}

wcstombs(myPointer, functionClassDeviceData->DevicePath,
wcslen
( functionClassDeviceData->DevicePath)+1);

printf("Attempting to open %s\n", myPointer);

hOut = CreateFile(functionClassDeviceData->DevicePath,
GENERIC_READ |
GENERIC_WRITE,
FILE_SHARE_READ |
FILE_SHARE_WRITE,
NULL, // No
SECURITY_ATTRIBUTES structure
OPEN_EXISTING,// No special
create flags
0, // No special
attributes
NULL); // No template
file

if (INVALID_HANDLE_VALUE == hOut)
{
printf("FAILED to open \n");
}

SetupDiDestroyDeviceInfoList(hardwareDeviceInfo);
free(functionClassDeviceData);

return hOut;

}

HANDLE
open_file (
PCHAR filename
)

{

int success = 1;
HANDLE h;
char tempBuff[256] = "";
LPCWSTR p;

USBDeviceOpen((LPGUID) &GUID_CLASS_I82930_BULK);

//strcpy(tempBuff, (CHAR)functionClassDeviceData->DevicePath);
strcpy(tempBuff,myPointer);
printf("Attempting to open %s\n", tempBuff);
strcat(tempBuff, "\\");

if ((strlen(DeviceName) + strlen(filename)) > 255)
{
printf("Failed to open handle - possibly long filename
\n");

return INVALID_HANDLE_VALUE;
}

strcat(tempBuff, filename);

printf("tempBuff = (%s)\n", tempBuff);
//p=(LPCWSTR)tempBuff;

h = CreateFile((LPCWSTR)tempBuff,
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
0,
NULL);

if (h == INVALID_HANDLE_VALUE)
{
printf("Failed to open %d\n",GetLastError());

success = 0;
}
else
{
printf("Opened successfully. \n");

}

return h;

}

HANDLE
UsbWrite (VOID)
{
PCHAR poutBuf = NULL;
PCHAR pinBuf = NULL;
HANDLE hRead = INVALID_HANDLE_VALUE;
HANDLE hWrite = INVALID_HANDLE_VALUE;
DWORD nBytesRead = 0;
DWORD nBytesWrite = 0;
ULONG success;

poutBuf = (PCHAR)malloc(32 * sizeof(UCHAR));
pinBuf = (PCHAR)malloc(32 * sizeof(UCHAR));
if((NULL != poutBuf) &&(NULL != pinBuf)) {

hWrite = open_file(outPipe);
//hRead = open_file(inPipe);

strcpy(poutBuf, "1234abcd");

success = WriteFile(hWrite,
poutBuf,
(32 * sizeof(UCHAR)),
&nBytesWrite,
NULL);
if (success)
{
printf("Write Succcess\n");

}
else {
printf("WriteFile failed\n");
}
}
else {
printf("memory allocation for poutBuf and PinBuf is
failed\n");
free(poutBuf);
free(pinBuf);
return 0;
}

CloseHandle(hWrite);
CloseHandle(hRead);
free(poutBuf);
free(pinBuf);

return 0;
}
Back to top
Login to vote
Display posts from previous:   
Related Topics:
How to find out how much Power (electric current) Device c.. - Hi, please can someone have a look at this question:..

enable VGA monitor in Windows XP - I disbled the VGA and now the monitor does not work the XP logo shows up on reboot but then the screen goes black, the...

newbie's question - C:\test>build -WXP XmlLog::File::CopyXslFile(): Unable to copy the XML Style Sheet. C:\WinDDK\600 bin\x86\build.xsl ...

NDAS Scsi Controller driver problem, leads to blue screen... - Up until recently, my pc (PC1) accessed my network drive correctly along with 2 other pc's on my home network... Driv...

Compability issues - Hello, I always have to suppress the warning C2220 no 'object' file generated. I wonder if this is a compability issue...

DVD Writer Issue - Guys Sorry if this is the wrong NG I'd appreciate a bit of help please. -Using XP SP2 fully hotfixed and SP'ed -Unti...
       Soft32 Home -> Windows -> Device Driver All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum

Categories:
  Windows
 Linux
 Mac
 PDA


[ Contact us | Terms of Service/Privacy Policy ]