USB Device

Dear All,

I am having a USB device with 1 Control Point and 3 BulkPoints. I too have the source code for the driver developed by the vendor. Now I need to get the data from the device using VC++ at user level.

Please guide me or tell me how to proceed, in order to get data from the device. Is there any System calls or Windows API to be used ? Please advice and give me the steps to proceed.

Many thanks in advance.

Best Regards,
Gajendran

If this is a proprietary interface (not a standard HID for example) then the
driver has to create symbolic links visible to user mode applications for
its device objects that represent its USB endpoints. There are two
mechanisms the driver could use to do this:

  1. the driver could use *IoCreateSymbolicLink - *and would provide an
    explicit name for the link.
  2. the driver could use *IoRegisterDeviceInterface* - and would provide
    an Interface GUID for the symbolic links.

In the first case you use the symbolic link name to open the device using
the standard PlatfomSDK CreateFile API.
In the second case you use the Interface GUID to find the symbolic link
names by calling the appropriate SetupDi APIs in the PlatformSDK, and then
you call CreateFile.

Once you have a handle to your driver’s device object, communciation
generally is done through the use of custom IOCTLs. Your driver source code
again will be the guide to what those IOCTLs are and how they are used.

On Sat, May 24, 2008 at 7:50 AM, Gajendran Gajendran
wrote:

> Dear All,
>
> I am having a USB device with 1 Control Point and 3 BulkPoints. I too have
> the source code for the driver developed by the vendor. Now I need to get
> the data from the device using VC++ at user level.
>
> Please guide me or tell me how to proceed, in order to get data from the
> device. Is there any System calls or Windows API to be used ? Please advice
> and give me the steps to proceed.
>
> Many thanks in advance.
>
> Best Regards,
> Gajendran
>
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Mark Roddy

Dear Mark,

Thank you so much for your prompt and kind reply.

I use the first method to open the device and I got the HANDLE correctly. But I don’t know how to give the IOCTL’s to the device. In the driver source code there are certain IOCTL’s which I have studied. Please guide me how to give the control codes. Also I tried using the DeviceIoControl but I am doing some mistakes. That is I dont know how to implement in the code. Please advice.

Many thanks.

Kind Regards,
Gajendran

Mark Roddy wrote: If this is a proprietary interface (not a standard HID for example) then the driver has to create symbolic links visible to user mode applications for its device objects that represent its USB endpoints. There are two mechanisms the driver could use to do this:

the driver could use IoCreateSymbolicLink - and would provide an explicit name for the link.
the driver could use IoRegisterDeviceInterface - and would provide an Interface GUID for the symbolic links.
In the first case you use the symbolic link name to open the device using the standard PlatfomSDK CreateFile API.
In the second case you use the Interface GUID to find the symbolic link names by calling the appropriate SetupDi APIs in the PlatformSDK, and then you call CreateFile.

Once you have a handle to your driver’s device object, communciation generally is done through the use of custom IOCTLs. Your driver source code again will be the guide to what those IOCTLs are and how they are used.

On Sat, May 24, 2008 at 7:50 AM, Gajendran Gajendran wrote:

Dear All,

I am having a USB device with 1 Control Point and 3 BulkPoints. I too have the source code for the driver developed by the vendor. Now I need to get the data from the device using VC++ at user level.

Please guide me or tell me how to proceed, in order to get data from the device. Is there any System calls or Windows API to be used ? Please advice and give me the steps to proceed.

Many thanks in advance.

Best Regards,
Gajendran
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


Mark Roddy — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

The WDK samples include user mode applications that use DeviceIoControl to
communicate with a driver. Study those samples and your driver source code.

On Sat, May 24, 2008 at 9:27 AM, Gajendran Gajendran
wrote:

> Dear Mark,
>
> Thank you so much for your prompt and kind reply.
>
> I use the first method to open the device and I got the HANDLE correctly.
> But I don’t know how to give the IOCTL’s to the device. In the driver source
> code there are certain IOCTL’s which I have studied. Please guide me how to
> give the control codes. Also I tried using the DeviceIoControl but I am
> doing some mistakes. That is I dont know how to implement in the code.
> Please advice.
>
> Many thanks.
>
> Kind Regards,
> Gajendran
>
>
> Mark Roddy wrote:
>
> If this is a proprietary interface (not a standard HID for example) then
> the driver has to create symbolic links visible to user mode applications
> for its device objects that represent its USB endpoints. There are two
> mechanisms the driver could use to do this:
>
> 1. the driver could use *IoCreateSymbolicLink - *and would provide an
> explicit name for the link.
> 2. the driver could use IoRegisterDeviceInterface - and would provide
> an Interface GUID for the symbolic links.
>
> In the first case you use the symbolic link name to open the device using
> the standard PlatfomSDK CreateFile API.
> In the second case you use the Interface GUID to find the symbolic link
> names by calling the appropriate SetupDi APIs in the PlatformSDK, and then
> you call CreateFile.
>
> Once you have a handle to your driver’s device object, communciation
> generally is done through the use of custom IOCTLs. Your driver source code
> again will be the guide to what those IOCTLs are and how they are used.
>
> On Sat, May 24, 2008 at 7:50 AM, Gajendran Gajendran <
> xxxxx@yahoo.com> wrote:
>
>> Dear All,
>>
>> I am having a USB device with 1 Control Point and 3 BulkPoints. I too have
>> the source code for the driver developed by the vendor. Now I need to get
>> the data from the device using VC++ at user level.
>>
>> Please guide me or tell me how to proceed, in order to get data from the
>> device. Is there any System calls or Windows API to be used ? Please advice
>> and give me the steps to proceed.
>>
>> Many thanks in advance.
>>
>> Best Regards,
>> Gajendran
>> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
>> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
>> the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
>
>
>
> –
> Mark Roddy — NTDEV is sponsored by OSR For our schedule of WDF, WDM,
> debugging and other seminars visit: http://www.osr.com/seminars To
> unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Mark Roddy

Another alternative for you if you do not want to maintain a driver is to use winusb instead. It will let you read/write data on the bulk endpoints.

d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Saturday, May 24, 2008 7:04 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] USB Device

The WDK samples include user mode applications that use DeviceIoControl to communicate with a driver. Study those samples and your driver source code.
On Sat, May 24, 2008 at 9:27 AM, Gajendran Gajendran > wrote:
Dear Mark,

Thank you so much for your prompt and kind reply.

I use the first method to open the device and I got the HANDLE correctly. But I don’t know how to give the IOCTL’s to the device. In the driver source code there are certain IOCTL’s which I have studied. Please guide me how to give the control codes. Also I tried using the DeviceIoControl but I am doing some mistakes. That is I dont know how to implement in the code. Please advice.

Many thanks.

Kind Regards,
Gajendran

Mark Roddy > wrote:
If this is a proprietary interface (not a standard HID for example) then the driver has to create symbolic links visible to user mode applications for its device objects that represent its USB endpoints. There are two mechanisms the driver could use to do this:

1. the driver could use IoCreateSymbolicLink - and would provide an explicit name for the link.
2. the driver could use IoRegisterDeviceInterface - and would provide an Interface GUID for the symbolic links.
In the first case you use the symbolic link name to open the device using the standard PlatfomSDK CreateFile API.
In the second case you use the Interface GUID to find the symbolic link names by calling the appropriate SetupDi APIs in the PlatformSDK, and then you call CreateFile.

Once you have a handle to your driver’s device object, communciation generally is done through the use of custom IOCTLs. Your driver source code again will be the guide to what those IOCTLs are and how they are used.

On Sat, May 24, 2008 at 7:50 AM, Gajendran Gajendran > wrote:
Dear All,

I am having a USB device with 1 Control Point and 3 BulkPoints. I too have the source code for the driver developed by the vendor. Now I need to get the data from the device using VC++ at user level.

Please guide me or tell me how to proceed, in order to get data from the device. Is there any System calls or Windows API to be used ? Please advice and give me the steps to proceed.

Many thanks in advance.

Best Regards,
Gajendran
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


Mark Roddy — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


Mark Roddy — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Dear Mark and all,

I have tried with your advices and opened the device properly. But I am facing some problem in issuing IOCTLS through DeviceIoControl. The code snippet is

USB_STRING_DESCRIPTOR *pstrdes=new USB_STRING_DESCRIPTOR();
o.Offset=0;
o.OffsetHigh = 0;
o.hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);

usbscan->NumberOfPipes;
usbscan->PipeInfo;
DWORD junk;

hfile = CreateFile(lpFileName, GENERIC_WRITE|GENERIC_READ, 0, &m_security, OPEN_ALWAYS, (FILE_ATTRIBUTE_NORMAL |FILE_FLAG_OVERLAPPED ), 0);

if (hfile == INVALID_HANDLE_VALUE)
{
// Handle the error.
printf (“CreateFile failed with error %d.\n”, GetLastError());
return (1);
}
else
{
status = DeviceIoControl(hfile, // device to be queried
IOCTL_BSU_GET_STRING_DESCRIPTOR, // operation to perform
NULL, 0, // no input buffer
pstrdes, sizeof(pstrdes), // output buffer
&junk, // # bytes returned
&o); // asynchronous I/O
}
_tprintf(TEXT(“deviceiocontrol error %d\n”,GetLastError()));
CloseHandle(hfile);

The method DeviceIoControl is having problem. I think that I am missing something. The driver source code has some CTL codes and I use one of them in the DeviceIoControl method but no values are returned in the buffer. I tried the method with both Sync and Async operations.

status = DeviceIoControl(hfile,IOCTL_BSU_GET_STRING_DESCRIPTOR,NULL, 0,pstrdes, sizeof(pstrdes),&junk, &o);

In the above method I use the CTL code which is defined in the source code of the driver. When I revealed the source of the driver the above CTL code uses USB_STRING_DESCRIPTOR_TYPE to get the string descriptor. Please advice.

Many thanks in advance.

Regards,
Gajendran

Mark Roddy wrote: The WDK samples include user mode applications that use DeviceIoControl to communicate with a driver. Study those samples and your driver source code.

On Sat, May 24, 2008 at 9:27 AM, Gajendran Gajendran wrote:
Dear Mark,

Thank you so much for your prompt and kind reply.

I use the first method to open the device and I got the HANDLE correctly. But I don’t know how to give the IOCTL’s to the device. In the driver source code there are certain IOCTL’s which I have studied. Please guide me how to give the control codes. Also I tried using the DeviceIoControl but I am doing some mistakes. That is I dont know how to implement in the code. Please advice.

Many thanks.

Kind Regards,
Gajendran

Mark Roddy wrote:

If this is a proprietary interface (not a standard HID for example) then the driver has to create symbolic links visible to user mode applications for its device objects that represent its USB endpoints. There are two mechanisms the driver could use to do this:

the driver could use IoCreateSymbolicLink - and would provide an explicit name for the link.
the driver could use IoRegisterDeviceInterface - and would provide an Interface GUID for the symbolic links.
In the first case you use the symbolic link name to open the device using the standard PlatfomSDK CreateFile API.
In the second case you use the Interface GUID to find the symbolic link names by calling the appropriate SetupDi APIs in the PlatformSDK, and then you call CreateFile.

Once you have a handle to your driver’s device object, communciation generally is done through the use of custom IOCTLs. Your driver source code again will be the guide to what those IOCTLs are and how they are used.

On Sat, May 24, 2008 at 7:50 AM, Gajendran Gajendran wrote:

Dear All,

I am having a USB device with 1 Control Point and 3 BulkPoints. I too have the source code for the driver developed by the vendor. Now I need to get the data from the device using VC++ at user level.

Please guide me or tell me how to proceed, in order to get data from the device. Is there any System calls or Windows API to be used ? Please advice and give me the steps to proceed.

Many thanks in advance.

Best Regards,
Gajendran
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer



Mark Roddy — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


Mark Roddy — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Gajendran Gajendran wrote:

I have tried with your advices and opened the device properly. But I
am facing some problem in issuing IOCTLS through DeviceIoControl. The
code snippet is

usbscan->NumberOfPipes;
usbscan->PipeInfo;

What do you think that does?

status = DeviceIoControl(hfile, // device to be queried
IOCTL_BSU_GET_STRING_DESCRIPTOR, // operation to perform
NULL, 0, // no input buffer
pstrdes, sizeof(pstrdes), // output buffer
&junk, // # bytes returned
&o); // asynchronous I/O
}
_tprintf(TEXT(“deviceiocontrol error %d\n”,GetLastError()));
CloseHandle(hfile);

The method DeviceIoControl is having problem. I think that I am
missing something. The driver source code has some CTL codes and I use
one of them in the DeviceIoControl method but no values are returned
in the buffer. I tried the method with both Sync and Async operations.

status = DeviceIoControl(hfile,IOCTL_BSU_GET_STRING_DESCRIPTOR,NULL,
0,pstrdes, sizeof(pstrdes),&junk, &o);

In the above method I use the CTL code which is defined in the source
code of the driver. When I revealed the source of the driver the above
CTL code uses USB_STRING_DESCRIPTOR_TYPE to get the string descriptor.

It is very difficult to help you without all of the information. The
ioctls you are discussing are private; they were invented by the author
of the driver you are using, so none of us know anything about them.

Now, I can take an educated guess at the problem. USB devices have
several string descriptors. So, it is likely that this ioctl has some
way for you to tell it which string descriptor you want. That would
have to go in as an input buffer. Only you can figure this out, by
looking at the driver code. Are they expecting to find the descriptor
number in the input buffer?

You are not using overlapped I/O properly. When you make an
asynchronous request, at some point you have to wait for the result.
You aren’t doing that. For now, I suggest that you not use overlapped
I/O until you really need it.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

typedef struct _USB_STRING_DESCRIPTOR {
UCHAR bLength ;
UCHAR bDescriptorType ;
WCHAR bString[1] ;
} USB_STRING_DESCRIPTOR, *PUSB_STRING_DESCRIPTOR ;

This is a standard windows variable length structure pattern. You cannot
just allocate a pointer to one of these and expect it to magically contain
enough storage space for more than one WCHAR of string.

Instead you have two choices:

  1. allocate a block of memory that is “*big enough”* for the largest string.
  2. iterate over DeviceIoControl calls using information returned when the
    provided output buffer is not big enough to allocate the correct amount of
    buffer space.

(2) only works if the IOCTL code in the driver supports returning the length
required information to you.
(1) is easy as I believe the USB descriptor string is defined with a max
size.

On Tue, May 27, 2008 at 5:14 AM, Gajendran Gajendran
wrote:

> Dear Mark and all,
>
> I have tried with your advices and opened the device properly. But I am
> facing some problem in issuing IOCTLS through DeviceIoControl. The code
> snippet is
>
> USB_STRING_DESCRIPTOR *pstrdes=new USB_STRING_DESCRIPTOR();
> o.Offset=0;
> o.OffsetHigh = 0;
> o.hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
>
> usbscan->NumberOfPipes;
> usbscan->PipeInfo;
> DWORD junk;
>
> hfile = CreateFile(lpFileName, GENERIC_WRITE|GENERIC_READ, 0,
> &m_security, OPEN_ALWAYS, (FILE_ATTRIBUTE_NORMAL |FILE_FLAG_OVERLAPPED ),
> 0);
>
> if (hfile == INVALID_HANDLE_VALUE)
> {
> // Handle the error.
> printf (“CreateFile failed with error %d.\n”, GetLastError());
> return (1);
> }
> else
> {
> status = DeviceIoControl(hfile, // device to be queried
> IOCTL_BSU_GET_STRING_DESCRIPTOR, // operation to perform
> NULL, 0, // no input buffer
> pstrdes, sizeof(pstrdes), // output buffer
> &junk, // # bytes returned
> &o); // asynchronous I/O
> }
> _tprintf(TEXT(“deviceiocontrol error %d\n”,GetLastError()));
> CloseHandle(hfile);
>
> The method DeviceIoControl is having problem. I think that I am missing
> something. The driver source code has some CTL codes and I use one of them
> in the DeviceIoControl method but no values are returned in the buffer. I
> tried the method with both Sync and Async operations.
>
> status = DeviceIoControl(hfile,IOCTL_BSU_GET_STRING_DESCRIPTOR,NULL,
> 0,pstrdes, sizeof(pstrdes),&junk, &o);
>
> In the above method I use the CTL code which is defined in the source code
> of the driver. When I revealed the source of the driver the above CTL code
> uses USB_STRING_DESCRIPTOR_TYPE to get the string descriptor. Please advice.
>
> Many thanks in advance.
>
> Regards,
> Gajendran
>
> Mark Roddy wrote:
>
> The WDK samples include user mode applications that use DeviceIoControl to
> communicate with a driver. Study those samples and your driver source code.
>
> On Sat, May 24, 2008 at 9:27 AM, Gajendran Gajendran <
> xxxxx@yahoo.com> wrote:
>
>> Dear Mark,
>>
>> Thank you so much for your prompt and kind reply.
>>
>> I use the first method to open the device and I got the HANDLE correctly.
>> But I don’t know how to give the IOCTL’s to the device. In the driver source
>> code there are certain IOCTL’s which I have studied. Please guide me how to
>> give the control codes. Also I tried using the DeviceIoControl but I am
>> doing some mistakes. That is I dont know how to implement in the code.
>> Please advice.
>>
>> Many thanks.
>>
>> Kind Regards,
>> Gajendran
>>
>>
>> Mark Roddy wrote:
>>
>> If this is a proprietary interface (not a standard HID for example)
>> then the driver has to create symbolic links visible to user mode
>> applications for its device objects that represent its USB endpoints. There
>> are two mechanisms the driver could use to do this:
>>
>> 1. the driver could use *IoCreateSymbolicLink - *and would provide an
>> explicit name for the link.
>> 2. the driver could use IoRegisterDeviceInterface - and would
>> provide an Interface GUID for the symbolic links.
>>
>> In the first case you use the symbolic link name to open the device using
>> the standard PlatfomSDK CreateFile API.
>> In the second case you use the Interface GUID to find the symbolic link
>> names by calling the appropriate SetupDi APIs in the PlatformSDK, and then
>> you call CreateFile.
>>
>> Once you have a handle to your driver’s device object, communciation
>> generally is done through the use of custom IOCTLs. Your driver source code
>> again will be the guide to what those IOCTLs are and how they are used.
>>
>> On Sat, May 24, 2008 at 7:50 AM, Gajendran Gajendran <
>> xxxxx@yahoo.com> wrote:
>>
>>> Dear All,
>>>
>>> I am having a USB device with 1 Control Point and 3 BulkPoints. I too
>>> have the source code for the driver developed by the vendor. Now I need to
>>> get the data from the device using VC++ at user level.
>>>
>>> Please guide me or tell me how to proceed, in order to get data from the
>>> device. Is there any System calls or Windows API to be used ? Please advice
>>> and give me the steps to proceed.
>>>
>>> Many thanks in advance.
>>>
>>> Best Regards,
>>> Gajendran
>>> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
>>> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
>>> the List Server section of OSR Online at
>>> http://www.osronline.com/page.cfm?name=ListServer
>>>
>>
>>
>>
>> –
>> Mark Roddy — NTDEV is sponsored by OSR For our schedule of WDF, WDM,
>> debugging and other seminars visit: http://www.osr.com/seminars To
>> unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
>>
>> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
>> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
>> the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
>
>
>
> –
> Mark Roddy — NTDEV is sponsored by OSR For our schedule of WDF, WDM,
> debugging and other seminars visit: http://www.osr.com/seminars To
> unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Mark Roddy

Dear Mark, Tim, Doron and all,

I have successfully get the data from the USB device by your guidances. I am very much thankful to you all and also for responding to my questions patiently. I am very glad to be a member of OSR family.

Many thanks to all.

Kind Regards,
Gajendran

Mark Roddy wrote:
typedef struct _USB_STRING_DESCRIPTOR {
UCHAR bLength ;
UCHAR bDescriptorType ;
WCHAR bString[1] ;
} USB_STRING_DESCRIPTOR, *PUSB_STRING_DESCRIPTOR ;

This is a standard windows variable length structure pattern. You cannot just allocate a pointer to one of these and expect it to magically contain enough storage space for more than one WCHAR of string.

Instead you have two choices:

1) allocate a block of memory that is “big enough” for the largest string.
2) iterate over DeviceIoControl calls using information returned when the provided output buffer is not big enough to allocate the correct amount of buffer space.

(2) only works if the IOCTL code in the driver supports returning the length required information to you.
(1) is easy as I believe the USB descriptor string is defined with a max size.

On Tue, May 27, 2008 at 5:14 AM, Gajendran Gajendran wrote:
Dear Mark and all,

I have tried with your advices and opened the device properly. But I am facing some problem in issuing IOCTLS through DeviceIoControl. The code snippet is

USB_STRING_DESCRIPTOR *pstrdes=new USB_STRING_DESCRIPTOR();
o.Offset=0;
o.OffsetHigh = 0;
o.hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);

usbscan->NumberOfPipes;
usbscan->PipeInfo;
DWORD junk;

hfile = CreateFile(lpFileName, GENERIC_WRITE|GENERIC_READ, 0, &m_security, OPEN_ALWAYS, (FILE_ATTRIBUTE_NORMAL |FILE_FLAG_OVERLAPPED ), 0);

if (hfile == INVALID_HANDLE_VALUE)
{
// Handle the error.
printf (“CreateFile failed with error %d.\n”, GetLastError());
return (1);
}
else
{
status = DeviceIoControl(hfile, // device to be queried
IOCTL_BSU_GET_STRING_DESCRIPTOR, // operation to perform
NULL, 0, // no input buffer
pstrdes, sizeof(pstrdes), // output buffer
&junk, // # bytes returned
&o); // asynchronous I/O
}
_tprintf(TEXT(“deviceiocontrol error %d\n”,GetLastError()));
CloseHandle(hfile);

The method DeviceIoControl is having problem. I think that I am missing something. The driver source code has some CTL codes and I use one of them in the DeviceIoControl method but no values are returned in the buffer. I tried the method with both Sync and Async operations.

status = DeviceIoControl(hfile,IOCTL_BSU_GET_STRING_DESCRIPTOR,NULL, 0,pstrdes, sizeof(pstrdes),&junk, &o);

In the above method I use the CTL code which is defined in the source code of the driver. When I revealed the source of the driver the above CTL code uses USB_STRING_DESCRIPTOR_TYPE to get the string descriptor. Please advice.

Many thanks in advance.

Regards,
Gajendran

Mark Roddy wrote: The WDK samples include user mode applications that use DeviceIoControl to communicate with a driver. Study those samples and your driver source code.

On Sat, May 24, 2008 at 9:27 AM, Gajendran Gajendran wrote:
Dear Mark,

Thank you so much for your prompt and kind reply.

I use the first method to open the device and I got the HANDLE correctly. But I don’t know how to give the IOCTL’s to the device. In the driver source code there are certain IOCTL’s which I have studied. Please guide me how to give the control codes. Also I tried using the DeviceIoControl but I am doing some mistakes. That is I dont know how to implement in the code. Please advice.

Many thanks.

Kind Regards,
Gajendran

Mark Roddy wrote:

If this is a proprietary interface (not a standard HID for example) then the driver has to create symbolic links visible to user mode applications for its device objects that represent its USB endpoints. There are two mechanisms the driver could use to do this:

the driver could use IoCreateSymbolicLink - and would provide an explicit name for the link.
the driver could use IoRegisterDeviceInterface - and would provide an Interface GUID for the symbolic links.
In the first case you use the symbolic link name to open the device using the standard PlatfomSDK CreateFile API.
In the second case you use the Interface GUID to find the symbolic link names by calling the appropriate SetupDi APIs in the PlatformSDK, and then you call CreateFile.

Once you have a handle to your driver’s device object, communciation generally is done through the use of custom IOCTLs. Your driver source code again will be the guide to what those IOCTLs are and how they are used.

On Sat, May 24, 2008 at 7:50 AM, Gajendran Gajendran wrote:

Dear All,

I am having a USB device with 1 Control Point and 3 BulkPoints. I too have the source code for the driver developed by the vendor. Now I need to get the data from the device using VC++ at user level.

Please guide me or tell me how to proceed, in order to get data from the device. Is there any System calls or Windows API to be used ? Please advice and give me the steps to proceed.

Many thanks in advance.

Best Regards,
Gajendran
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer



Mark Roddy — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


Mark Roddy — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


Mark Roddy — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer