What is the differences between USB port and COM (serial) port?

Hi all;

I have a program in windows that is a PKCS#11 library to communicate with a
cryptographic token;

Also, I have multiple programs to implement a device manager using shared
memory and multithreading concepts.

In it’s windows version, it uses a windows-based token driver in low level
and a program (C++ class)
called “SerialWrapper.cpp” to connect to the usb token.

In the “SerialWrapper.cpp”, it uses the “DCB” structure and functions like
“CreateFile” to enumerate and communicate with serial(COM) ports.

I’m going to “PORT” this project to linux, so I use a library named “libusb”
and a program named “hid_LINUX” to enumerate devices(usb tokens) connected
to the system and also Interfaces, endpoints,… and open a handle to them
and write or read from token.

I test the “hid_linux” separately and it works fine.

But in porting “PKCS11 library”, I’ve faced a basic and conceptual problem!!

What’s the differences between a USB port and a COM(serial) port?

In windows-based version of the program, it interacts with COM ports, I was
thinking that COM port is a “9-pin” port at the back of case!

But I can’t understand why we have “COM1, COM2, …,COM9” in such
programming?!

In the windows version of the program, it supports and handles “4” slots
simultanousely.
That is, the program handles four tokens connected to the system, but using
the “SerialWrapper.cpp” to connect to these “USB Tokens”!

And the PKCS11 library supports 4 slots, as well!

But in linux version, I can’t map Serial ports to USB ports conceptually and
this is because I’m not familiar with differences between usb driver model
of windows and linux and this is my first programming experience with buses
or ports!

And I can’t realize the differences between COM port and USB port, BTW on
some laptops we don’t have COM port(9-pin port)!

Does the COM port predicate to USB port too?!

could you explain me these differences pithy and improve my bad
understanding please?

I’m so confused and need the experts’ explanations than searching in the
Internet!!

THX in Advance.

>Does the COM port predicate to USB port too?!

In Windows, the COM port is anything carrying the Serial PnP device interface+COM%d names, and also responding to IOCTL_SERIAL_ set of IOCTLs.

There are also primitive implementations of serial drivers in Windows, which are enough for TAPI to dial/accept call on a modem, but not enough for more complex apps like HyperTerminal.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

Here is my personal “COM/USB backgrounder”:

In the past, serial interfaces provided a proven, simple way of
exchanging a few bytes between a PC and a device.
Specifically the 16550 UART was very widespread.

Serial ports were also catered for in the PC BIOS, in MS-DOS, and in
Windows. MS-DOS and Windows exposed the serial interface in the form of
“COM*” interfaces. (Unix traditionally exposes these interfaces in form
of “device files”, usually in the /dev/ttyS* range.)

With the advent of USB,…

…many small-scale projects or older hardware did not want to implement
their own USB interface into the hardware design. Internally, they
wanted rather to stick to the simpler serial interface. Also some
external components - specifically smart card readers - already use
serial communication, so there a serial interface is a good choice.

…unfortunately nobody integrated a simple way into Windows to exchange
“just a few bytes” with another device. There was no simple “USB*”
interface like it worked with “COM*”: each and every hardware vendor had
to provide their own USB driver.
[On Windows, many (if not most) of these are derived from the “infamous”
BulkUSB sample (dropped from the latest WDKs).]

Now, several years later…

…for the hardware, the industry responded and many USB-to-serial
converters became available. You can still buy external USB-to-Serial
converter “cables”, but more often the converters are now directly
integrated in the device you have (e.g. Smart Card reader). On Windows,
the drivers of these converters usually register themselves as a “COM”
port. This is likely what you see for your SC reader hardware.

…for Windows, meanwhile Microsoft provides a relatively simple way for
applications to directly open a USB device and send/receive a few bytes
from it: via WinUSB. Also they introduced the UMDF and KMDF driver
frameworks to ease driver development (and improve security). Soy ou can
use the “COM” converter driver, but you also could talk to the reader
directly.

…for Linux, you don’t have an OS-internal COM-to-USB-mapping, and you
don’t need one. Here you can just open the USB device directly (like a
file), control it via IOCTLs, and send/receive data.
As I understand, you have a library and sample code, so please use these
samples to get familiar with your device and its interfaces.

Sorry for the long post. Corrections/additions welcome.