Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista Drivers > How to send/read data from a USB device in Host App?

Reply
Thread Tools Display Modes

How to send/read data from a USB device in Host App?

 
 
USB Device User
Guest
Posts: n/a

 
      06-02-2010
I have a Zebra barcode printer connected to my pC with USB. The printer is
not a win USB device and neither do we use the vendor driver. The
enummeration process detects the printer as a USB raw device. How can use
bulk transfer to send/read data from the printer in the host app? Is there
any api calls I can use or do I have to write a simple driver? Is there any
C# sample code?
Thanks,
 
Reply With Quote
 
 
 
 
Tim Roberts
Guest
Posts: n/a

 
      06-03-2010
USB Device User <> wrote:
>
>I have a Zebra barcode printer connected to my pC with USB. The printer is
>not a win USB device...


What does that mean?

>...and neither do we use the vendor driver. The
>enummeration process detects the printer as a USB raw device. How can use
>bulk transfer to send/read data from the printer in the host app? Is there
>any api calls I can use or do I have to write a simple driver?


WinUSB can do that. WinUSB is a basic USB driver that Microsoft has
written for generic access to USB devices, plus a thin DLL that provides a
user-mode API for accessing it. You'll have to write an INF file to get
the driver loaded.

>Is there any C# sample code?


Most of the sample code is in C++, but the API is fairly simple.
--
Tim Roberts,
Providenza & Boekelheide, Inc.
 
Reply With Quote
 
USB Device User
Guest
Posts: n/a

 
      06-04-2010


"Tim Roberts" wrote:

> USB Device User <> wrote:
> >
> >I have a Zebra barcode printer connected to my pC with USB. The printer is
> >not a win USB device...

>
> What does that mean?


The device does not use WINUSB driver. It uses USBPRINT as the default driver.

>
> >...and neither do we use the vendor driver. The
> >enummeration process detects the printer as a USB raw device. How can use
> >bulk transfer to send/read data from the printer in the host app? Is there
> >any api calls I can use or do I have to write a simple driver?

>
> WinUSB can do that. WinUSB is a basic USB driver that Microsoft has
> written for generic access to USB devices, plus a thin DLL that provides a
> user-mode API for accessing it. You'll have to write an INF file to get
> the driver loaded.


If a device is not developed as a WINUSB driver device, could I write an NF
file and install the WINUSB driver to make it a WINUSB device? From Host
requirements, should I also need to get a vendor provided application to
communicate to the printer to make WINUSB work for the printer?

>
> >Is there any C# sample code?

>
> Most of the sample code is in C++, but the API is fairly simple.


I tried to use the the WriteFile to send the text command to the printer and
WriteFile always returns 0x57 error. Here ia the code:
public bool WriteToUSB(SafeFileHandle fileHandle, string information)
{
Byte[] writeBuffer = new byte[information.Length]; //initialize buffer
int iCount = 0;
while (iCount < information.Length)
{
writeBuffer[iCount] =
System.Convert.ToByte(information.ToCharArray()[iCount]);
iCount++;
}
int bytesWritten = 0;
return WriteToUSB(fileHandle, writeBuffer, writeBuffer.Length, ref
bytesWritten);
}
public bool WriteToUSB(SafeFileHandle fileHandle,byte[] bWriteBuffer, int
bytesToWrite, ref int nBytesWritten)
{
return WriteFile(fileHandle, bWriteBuffer, bytesToWrite, ref
nBytesWritten, IntPtr.Zero);
}

Anyone knows why?


> --
> Tim Roberts,
> Providenza & Boekelheide, Inc.
> .
>

 
Reply With Quote
 
Tim Roberts
Guest
Posts: n/a

 
      06-05-2010
USB Device User <> wrote:
>"Tim Roberts" wrote:
>> USB Device User <> wrote:
>> >
>> >I have a Zebra barcode printer connected to my pC with USB. The printer is
>> >not a win USB device...

>>
>> What does that mean?

>
>The device does not use WINUSB driver. It uses USBPRINT as the default driver.


I'm confused. You said:

* The printer is not a win USB device
* neither do we use the vendor driver
* The enummeration process detects the printer as a USB raw device

If it is not enumerated as a printer, and you do not use a vendor driver,
then how did USBPRINT get involved?

>If a device is not developed as a WINUSB driver device, could I write an NF
>file and install the WINUSB driver to make it a WINUSB device? From Host
>requirements, should I also need to get a vendor provided application to
>communicate to the printer to make WINUSB work for the printer?


You can create your own INF and install WinUSB as the driver. However, you
will need to know which sequences to send to the printer to get it to do
things. Most label printers are strictly bitmap devices. You need to send
them a bitmap of some kind, in some format, at the proper resolution.

>I tried to use the the WriteFile to send the text command to the printer and
>WriteFile always returns 0x57 error. Here ia the code:
>public bool WriteToUSB(SafeFileHandle fileHandle, string information)
> {
> Byte[] writeBuffer = new byte[information.Length]; //initialize buffer


Where did you get the file handle?
--
Tim Roberts,
Providenza & Boekelheide, Inc.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Unable to unload driver in Win 7 Tim Roberts Windows Vista Drivers 2 12-08-2009 12:24 PM
cannot install Vista ACPI error Salsakidd Windows Vista Installation 6 10-10-2007 10:12 AM
Going Golfing but not with Vista markbyrn Windows Vista Games 15 03-08-2007 10:59 AM
americas army stuttering under vista premium ernie Windows Vista Games 0 02-27-2007 10:20 PM
problem in dxdiag Peewee64 Windows Vista Games 0 02-14-2007 09:49 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59