Thread: Hardware interaction through USB port with C

  1. #1
    Registered User
    Join Date
    Nov 2007

    Hardware interaction through USB port with C

    hi folks, I want to start to handle hardware devices, like a printer, a webcam, and so on. I have looked for it on the internet, but all I've found was tutorials with serial ports. Any kind of information wich could help me to start with it will be really welcome. Thanks in advance!.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    What exactly would you like to do with your USB devices? In what operating system do you plan to do this?

    You'll have to understand that in a modern system such as Linux or Windows, device drivers exist at various levels, where a low-lever driver interfaces with the actual USB chip in the PC, essentially shuffling some data into the chip itself. Higher level device drivers layer on top of this for supporting specific device types (such as Web Camera or Printer), and on top of that is a specific device driver for that particular device (e.g. a HP Printer Driver) - this may for example support things like "asking how much ink there is left in the ink-cartridge" or "what to do when paper is out".

    For printers, there is also a generic printer device level, which handles converting the Windows GDI functionality into printer-language (PostScript, HP PCL or whatever) - these functions don't care a least bit if the printer is a USB printer, a Parallel printer cable or connected via an Ethernet cable, or is located the other side of the planet via the Internet - it's just a translation into something the printer can understand.

    Similarly for Web-Cameras, I expect there to be drivers that are just there to translate what the proprietary protocol of the camera is, into something that the upper layer generic display functions can use [e.g. a bitmap image in your web-browser or MPEG video in a Media Player]. Again, this is regardless of how the data got from the camera into the computer - at this point, we don't really care, we just know where the data is, and how to convert it to a more widely acceptable form.

    This may be a bit "Windows oriented", but the general concept applies in any "large" OS.

    I'm not sure this actually explains anything really, but perhaps you can see that the whole picture is quite complex.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Nov 2007
    Thanks guys!.
    salem: what a incredibly link you post!, just what I was looking for.
    mats: you explain it really nice, but also it scares me. I didn't have a clue about how it works, and it's just like you said, quite complex.
    Thanks, again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parallel Port to USB controller and outb()
    By coletek in forum Linux Programming
    Replies: 1
    Last Post: 06-05-2009, 06:57 AM
  2. FTP program
    By jakemott in forum Linux Programming
    Replies: 14
    Last Post: 10-06-2008, 01:58 PM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  4. USB port "monitor"
    By Victor in forum Windows Programming
    Replies: 1
    Last Post: 04-13-2005, 05:45 AM
  5. Replies: 1
    Last Post: 10-13-2004, 12:15 PM