Author Topic: working with USB in VC++  (Read 13856 times)

alpidor

  • Member
  • ***
  • Posts: 2
working with USB in VC++
« on: June 24, 2010, 01:10:22 am »
hello,

In my project, I need to communicate across a USB port.
I have developed a program In Visual C++ where I use the CreateFile function to obtain a handler.

Ex.
    CreateFile("COM1:" .....)

But :
1. On my laptop, I have 6 USB ports but only the COM3 returns a valid handler.
2. Even if the handler is valid, nothing is  sent across the  USB port.
3. how can I identify the USB port .


Your help will be greatly appreciated,
 Gelu

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: working with USB in VC++
« Reply #1 on: June 24, 2010, 10:26:11 am »
Applications don't access USB ports; they can only access specific devices attached to ports.

How an application communicates with a USB device depends on the device driver that Windows has assigned to the device. The choice of driver in turn depends on finding a match between the information in the descriptors that Windows retrieves on device attachment or bootup and the information stored in the PC's INF files. Often the application doesn't have to know whether the device uses USB or another interface. For example, applications access files on a drive in the same way whether the drive uses USB, IEEE-1394, SCSI, ATAPI, or another interface. The interface-specific details are handled at a lower level. Some devices use drivers included with Windows. Other devices use a vendor-specific driver that he user must install.

If you want to access a USB device as a COM port, you need a device that identifies itself as a COM-port device. ftdichip.com is one source of chips for this.

Also see my USB FAQ, first questions:

http://www.janaxelson.com/usbfaq.htm

Jan
« Last Edit: March 28, 2018, 08:26:22 pm by Jan Axelson »

alpidor

  • Member
  • ***
  • Posts: 2
Re: working with USB in VC++
« Reply #2 on: June 25, 2010, 12:16:37 am »
Hello Jan,

Thank you for your prompt answer.
I would like to detail some aspects of my project.
We have an old version of a software that sends markers to a medical device across the parallel port.
Because we want to run our soft on a laptop, we need a substitute solution.
For that, we try to use a USB / Parallel port adapter (cable). When we connect a printer on the cable,  everything  works fine.
Now I thought naively that it is an easy way to do replace the parallel port interface by an USB interface in C (in a old project, I controlled a GPS device working on USB simply by opening the port with  CreateFile("COMn", ...) command).

Any idea could help me a lot.

Thank you in advance,
Gelu

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: working with USB in VC++
« Reply #3 on: June 25, 2010, 11:57:29 am »
Most commercial USB/parallel=port adapters identify themselves to the host computer as printers and thus only work with printers.

For other parallel-port devices, see:

Converter From USB To Parallel from Henrik Haftmann

http://www-user.tu-chemnitz.de/~heha/bastelecke/Rund%20um%20den%20PC/USB2LPT/index.html.en

Jan Axelson
« Last Edit: March 28, 2018, 08:26:30 pm by Jan Axelson »