How to identified a virtual com port is a printer

We have a USB printer device when connecting this printer with PC then it appears in device manager as a virtual com port (Printer has FTDI chip). We want to write a driver by which it comes in the list of the printer and when user press ctrl+p or using the standard printing application then it comes in the printer option.

Is there anyway so that my printer which appears in COM-PORT come into the printer list. I am a newbie in windows driver development, so please show me the path.

You can create a “virtual” printer that shows up in the list and then
communicates with the real hardware via the COM port. You need to look
at the printer driver docs, I suspect there is more than one way to do
this, with various levels of “useless” middle sections.

Alternatively you can use a special program to print to your device,
but it sounds like you do not want this.

Thank you so much for your valuable reply. So I am going through the virtual printer. Have you any idea beside the virtual printer.

Mr. Mishra,

Posting the same topic multiple times is a serious violation of forum etiquette.

Please don’t do it again. For your convenience, I have merged both threads here.

Peter

We have USB printer that contains FTDI chip. Due to FTDI chip printer enumerate as a com port. We are able to print data using the serial application. But now our requirement to list out the printer in printer list and print the data like another printer using the (ctrl + p) command or IP and port. So here I am confused that we need to create a driver for it or there is any setting available that we can show virtual com port in the printer list and it behaves like another printer.

You don’t want a virtual printer. Since it shows up as its own device you will want to write an inf that matches the hardware id of the com port and installs as a printer. You can probably continue to install the com port driver in the same inf.

pritosh_mishra wrote:

We have USB printer that contains FTDI chip. Due to FTDI chip printer enumerate as a com port. We are able to print data using the serial application. But now our requirement to list out the printer in printer list and print the data like another printer using the (ctrl + p) command or IP and port. So here I am confused that we need to create a driver for it or there is any setting available that we can show virtual com port in the printer list and it behaves like another printer.

You need to think about this in a different way.  COM ports are not
plug-and-play, so there’s no way for the system to ask the COM port “who
are you?”.

However, the USB device certainly is plug-and-play.  Some of the FTDI
chips let you change the VID and PID in the descriptors.  If you set
your own VID and PID, then you could have an INF file that maps that VID
and PID to your custom printer driver.  You wouldn’t even need to expose
a virtual COM port.

I’m not convinced those FTDI chips are a net gain to the industry.  COM
ports should have died out a generation ago.  If your printer has a USB
connector, then design a USB printer, by god.  There’s a well-defined
spec for those.

Note: The email was trying to reply to an invalid Discussion (290766).

Tim, Thanks for your reply, the com port is a virtual com port and there is already an FTDI chip in the printer. When we connect the printer through the USB cable then and virtual comport is invoked. So here I am getting confused that how I can proceed with this work.

pritosh_mishra wrote:

Tim, Thanks for your reply, the com port is a virtual com port and there is already an FTDI chip in the printer. When we connect the printer through the USB cable then and virtual comport is invoked. So here I am getting confused that how I can proceed with this work.

I described one potential method in my previous message.  Your FTDI chip
advertises a USB vendor ID and product ID in its USB descriptors. 
Today, through an INF file, that VID and PID get mapped to a USB driver
that creates a virtual COM port.  That’s a dead end; virtual COM ports
are not PnP, so there’s no way to trigger the loading of a printer driver.

However, there is no reason why you have to load that USB virtual COM
port driver at all.  You could write your own INF to match the FTDI
chip’s VID and PID, and have that INF loads a printer driver.  Your
printer driver would have to communicate with the FTDI chip using USB
packets instead of COM port I/O, but that’s easy; the FTDI bus traffic
is trivial.  You would really want to change the descriptors in the FTDI
chip to your own set, so you didn’t conflict with other FTDI devices.  I
think most of the FTDI chips can be programmed; if not, then this is not
very practical.

@Tim_Roberts said:
pritosh_mishra wrote:

Tim, Thanks for your reply, the com port is a virtual com port and there is already an FTDI chip in the printer. When we connect the printer through the USB cable then and virtual comport is invoked. So here I am getting confused that how I can proceed with this work.

I described one potential method in my previous message. Your FTDI chip
advertises a USB vendor ID and product ID in its USB descriptors.
Today, through an INF file, that VID and PID get mapped to a USB driver
that creates a virtual COM port. That’s a dead end; virtual COM ports
are not PnP, so there’s no way to trigger the loading of a printer driver.

However, there is no reason why you have to load that USB virtual COM
port driver at all. You could write your own INF to match the FTDI
chip’s VID and PID, and have that INF loads a printer driver. Your
printer driver would have to communicate with the FTDI chip using USB
packets instead of COM port I/O, but that’s easy; the FTDI bus traffic
is trivial. You would really want to change the descriptors in the FTDI
chip to your own set, so you didn’t conflict with other FTDI devices. I
think most of the FTDI chips can be programmed; if not, then this is not
very practical.

Thanks, Tim now it is clear for me. So, Tim, I have a question here my printer is a ticket printer. So Can I use usbprint for it or need to create a virtual printer driver and map this driver to the printer device using the VID and PID. Doron told that there is no need to create virtual printer driver just need to create inf file for the same. Please correct me if I am wrong.

The printer driver will match to the vid/pid hardware id of the com port. There is nothing virtual about the printer driver, it is entirely hardware driven.

Bent from my phone


From: pritosh_mishra
Sent: Wednesday, November 14, 2018 4:43:09 AM
To: Doron Holan
Subject: Re: [NTDEV] How to identified a virtual com port is a printer

OSR https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcommunity.osr.com%2F&data=02|01|doron.holan%40microsoft.com|f4a09df76cfc494bbbf908d64a2ebbef|72f988bf86f141af91ab2d7cd011db47|1|0|636777961926242637&sdata=Av159zkS3%2BZeG%2F9PpRr75vTcjhBvVuOmp%2BwPcw5B%2Bi8%3D&reserved=0
pritosh_mishra commented on How to identified a virtual com port is a printer

> @Tim_Roberts said:
>
> pritosh_mishra wrote:
>
> > Tim, Thanks for your reply, the com port is a virtual com port and there is already an FTDI chip in the printer. When we connect the printer through the USB cable then and virtual comport is invoked. So here I am getting confused that how I can proceed with this work.
>
> I described one potential method in my previous message. Your FTDI chip
>
> advertises a USB vendor ID and product ID in its USB descriptors.
>
> Today, through an INF file, that VID and PID get mapped to a USB driver
>
> that creates a virtual COM port. That’s a dead end; virtual COM ports
>
> are not PnP, so there’s no way to trigger the loading of a printer driver.
>
> However, there is no reason why you have to load that USB virtual COM
>
> port driver at all. You could write your own INF to match the FTDI
>
> chip’s VID and PID, and have that INF loads a printer driver. Your
>
> printer driver would have to communicate with the FTDI chip using USB
>
> packets instead of COM port I/O, but that’s easy; the FTDI bus traffic
>
> is trivial. You would really want to change the descriptors in the FTDI
>
> chip to your own set, so you didn’t conflict with other FTDI devices. I
>
> think most of the FTDI chips can be programmed; if not, then this is not
>
> very practical.

Thanks, Tim now it is clear for me. So, Tim, I have a question here my printer is a ticket printer. So Can I use usbprint for it or need to create a virtual printer driver and map this driver to the printer device using the VID and PID. Doron told that there is no need to create virtual printer driver just need to create inf file for the same. Please correct me if I am wrong.

pritosh_mishra wrote:

Thanks, Tim now it is clear for me. So, Tim, I have a question here my printer is a ticket printer. So Can I use usbprint for it or need to create a virtual printer driver and map this driver to the printer device using the VID and PID. Doron told that there is no need to create virtual printer driver just need to create inf file for the same. Please correct me if I am wrong.

Sorry, no.  Usbprint works with devices that adhere to the USB Device
Class spec for Printing Devices, which assumes a bulk pipe and IEEE 1284
compatibility.  Your device is not like that.  You would essentially
have to write a driver that works like usbprint.sys, but knows how to
communicate through the interrupt pipe that the FTDI chips usually
expose.  Then you could have a printer driver or language monitor on top
of that, just as if it were a standard interface.

It’s going to be a fair amount of work.  Is it really worth it?

@Tim_Roberts said:
pritosh_mishra wrote:

Thanks, Tim now it is clear for me. So, Tim, I have a question here my printer is a ticket printer. So Can I use usbprint for it or need to create a virtual printer driver and map this driver to the printer device using the VID and PID. Doron told that there is no need to create virtual printer driver just need to create inf file for the same. Please correct me if I am wrong.

Sorry, no. Usbprint works with devices that adhere to the USB Device
Class spec for Printing Devices, which assumes a bulk pipe and IEEE 1284
compatibility. Your device is not like that. You would essentially
have to write a driver that works like usbprint.sys, but knows how to
communicate through the interrupt pipe that the FTDI chips usually
expose. Then you could have a printer driver or language monitor on top
of that, just as if it were a standard interface.

It’s going to be a fair amount of work. Is it really worth it?

Tim, previously I have never worked on the printer driver. I have some experience with the USB and serial driver. Can you please give any reference where I can get some help because I think I have to create a renderer in the printer driver to convert the EMF (print data) to printer’s raw format. Please correct me if I am wrong.

pritosh_mishra wrote:

Tim, previously I have never worked on the printer driver. I have some experience with the USB and serial driver. Can you please give any reference where I can get some help because I think I have to create a renderer in the printer driver to convert the EMF (print data) to printer’s raw format. Please correct me if I am wrong.

It’s been a many years since I worked with a GDI driver.

The printer driver world separates the render portion from the
communication portion.  You should be able to use the Microsoft
Universal Driver to do all of your rendering for you.  Then, a “print
monitor” takes the processed data from the spooler and actually sends it
to the device.

So, you’ll need to write a GPD file to configure the Universal Printer
Driver, and you’ll need a port monitor (a user-mode DLL) to direct the
spooled data to the printer itself.  There is a sample port monitor in
the WDK samples.

You have a fair amount of reading to do.

@Tim_Roberts said:
pritosh_mishra wrote:

Tim, previously I have never worked on the printer driver. I have some experience with the USB and serial driver. Can you please give any reference where I can get some help because I think I have to create a renderer in the printer driver to convert the EMF (print data) to printer’s raw format. Please correct me if I am wrong.

It’s been a many years since I worked with a GDI driver.

The printer driver world separates the render portion from the
communication portion. You should be able to use the Microsoft
Universal Driver to do all of your rendering for you. Then, a “print
monitor” takes the processed data from the spooler and actually sends it
to the device.

So, you’ll need to write a GPD file to configure the Universal Printer
Driver, and you’ll need a port monitor (a user-mode DLL) to direct the
spooled data to the printer itself. There is a sample port monitor in
the WDK samples.

You have a fair amount of reading to do.

Thanks, Tim, the problem is that printers take some specific commands to print data. Below is the example which we used to print the text and barcode.

ePS
eSS,I
eSO,0,0
eSP,1
eSF,FONT10,1,1
eDP,100,300
eSF,OCRA16,1,1
eSB,1,45,20,20,2,6
eDP,580,220
eDB,261700123456
eDL,80,109,160,110
eDL,160,20,161,110
eDL,600,109,680,110
eDL,680,20,681,110
eDP,780,220
eDB,261700123456
ePD

I am not able to understand how I can convert the raw data which is coming from the window application to the above format. I have installed the generic text driver and create a text file that contain hello. When printing this text file using the CTRL+P then I found that a huge data is going to the com port. I am attaching the data.

0d 0a 0a 0a 0a 0a 0a 20 20 20 20 20 20 20 20 20 …
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 74 65 73 tes
74 2e 74 78 74 0d 0a 20 20 20 20 20 20 20 68 65 t.txt… he
6c 6c 6f 0d 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a llo…
0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a …
0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a …
0a 0a 0a 0a 0a 0a 0a 0a 20 20 20 20 20 20 20 20 …
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 50 P
61 67 65 20 31 0c

Could you please give some hint here.

pritosh_mishra wrote:

Thanks, Tim, the problem is that printers take some specific commands to print data. Below is the example which we used to print the text and barcode.

PS
SS,I
SO,0,0
SP,1
SF,FONT10,1,1
DP,100,300
SF,OCRA16,1,1
SB,1,45,20,20,2,6
DP,580,220
DB,261700123456
DL,80,109,160,110
DL,160,20,161,110
DL,600,109,680,110
DL,680,20,681,110
DP,780,220
DB,261700123456
PD

I can guess what all of that means.  Select font, draw position, draw
line, data bytes.  Are you expecting users to do their own barcode
creation?    If not, are you always assuming exactly one barcode type? 
Is it going to be fixed size and fixed position on the page?

I am not able to understand how I can convert the raw data which is coming from the window application to the above format. I have installed the generic text driver and create a text file that contain hello. When printing this text file using the CTRL+P then I found that a huge data is going to the com port. I am attaching the data.

0d 0a 0a 0a 0a 0a 0a 20 20 20 20 20 20 20 20 20 …
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 74 65 73 tes
74 2e 74 78 74 0d 0a 20 20 20 20 20 20 20 68 65 t.txt… he
6c 6c 6f 0d 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a llo…
0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a …
0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a …
0a 0a 0a 0a 0a 0a 0a 0a 20 20 20 20 20 20 20 20 …
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 50 P
61 67 65 20 31 0c

Could you please give some hint here.

Alas, I weep for analytical skills.  Can you really not tell exactly
what that is just by looking at it?  I’m guessing you used Notepad to
create and print this.  Have you never looked at a page printed by
Notepad?  Notepad adds a header and a footer to the files it prints. 
There are 6 blank lines, then a centered header that has the name of the
file, then your string, indented by 7 spaces, then 52 blank lines to get
to the bottom of the page, and a centered footer that says “Page 1”,
followed by a page eject (0x0c).

You can try turning off the header and footer in Page Setup, but it’s
still going to add margins.  If you want just the raw string, you will
have to use your own application.