×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Hardware Interfacing thru C..

Hardware Interfacing thru C..

Hardware Interfacing thru C..

(OP)

Hi,  
   I m relatively a beginner in C, but after covering some major topics, i want to learn something abt interfacing hardware like printer parallel port or some LED etc thru C.
  can anyone guide me, or refer to any online material..

Thanks,
FaRaZ.

RE: Hardware Interfacing thru C..

Under DOS it is simple -- under WINDOWS -- well I don't do windows.

<nbucska@pcperipherals.com>

RE: Hardware Interfacing thru C..

Windows is just as simple, just need to know the tricks ;) ... Actually you can't direct interface to the hardware via an application (ring 3 code). However you can treat any port like a stream device.

RE: Hardware Interfacing thru C..

claganga:
Reading Chinese is simple, too, after you learn a few
thousand symbols...

<nbucska@pcperipherals.com>

RE: Hardware Interfacing thru C..

nbucska:
I guess I can't argue with that.

faraznasim:
Humm what exactly would like to write to a serial port, I'll give you a windows example if you want.

RE: Hardware Interfacing thru C..

Opening a serial port is done in a very illogical way: you have to make a call to CreateFile(), ReadFile(), and WriteFile() functions with the COM port specified as a string value, i.e. "COM1" or "COM2", etc. You can find good code examples on how to do this on www.codeproject.com. I think it should have been functions with names such as OpenDevice(), SendDeviceData(), and ReadDeviceData(), but what do I know.

Once you have opened the port, it's as simple as transmitting (WriteFile()) and receiving (ReadFile()) bytes.

Also take a look at the SetCommTimeouts() and SetCommState() functions, with the relevant COMMTIMEOUTS and DCB data structures as input. The MSDN library gives you all the help you'll need on these topics, and its available online as well.

Hope this helped.

RE: Hardware Interfacing thru C..

Hi-

The C programming enviornment for a 'nix machine is
much easier than going through much rigamarole in the
windows enviornment.

If you feel comfortable going into say the Linux land,
you will find all sorts of tools that will assist you
in playing with I/O.

I might recommend the following link:


http://www.linuxdocs.org/HOWTOs/mini/IO-Port-Programming-6.html#ss6.1

as a rather painless introduction to the subject.


   Cheers,

    Rich S.

RE: Hardware Interfacing thru C..

Since you mention "an LED," and a parallel port, I assume you're tinkering with physical hardware. As of NT4 and 98SE, Windows added a Virtual Device Manager layer in the executive between programs and hardware. It's much more difficult to bit-bang to physical hardware than before. I/O instructions like "in" and "out" no longer write directly to the port. It WAS a lot easier in the DOS days.

Some things are fairly straightforward, like getting to RTS/CTS and DSR/DTR bits on a serial port via the MSCOMM.DLL package. Just don't expect reliable real-time performance when you do. You can blink and read Morse Code, for example, but don't think you'll be able to bit-blast a 100kHz burst pattern for X10 emulation accurately at zero-crossing through most Windows tools.

If you're just trying to print something to a parallel port, just open the printer as a stream i/o device and "printf" to it. If you want to light a couple of LED's, I'd suggest putting them on the serial port (or just watch the lights on an external modem.) For much beyond that, get an I/O board with a Mfgr's driver interface to C, or get ready to write your own replacement port driver, a task NOT for newbies.  

Howrd

RE: Hardware Interfacing thru C..

A very useful page for this kind of thing is
http://www.lvr.com/

The direct page for parallel ports is
http://www.lvr.com/parport.htm

See the section on windows drivers that can be used to allow direct IO on windows, some are free, some are commercial, but it may help your problem.

Cheers

B

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources