How to access hardware ports using C ?

A

agnivesh

Hi there,

I'm a beginner in C programming and want to learn how to write C (pure
C) code to access hardware ports (serial,parallel,usb etc.) under
windows environment ?

1. Please, suggest any online tutorials or free ebooks etc. for that.

2. Is it possible to do above tasks using MingW Developer Studio, GTK+
etc. ? I've just downloaded these tools and want to make sure before
starting learning these tools, that we can use these tools to write
small windows GUI applications (in C), which can interact with external
embedded systems through PC's serial, parallel or usb port.

thanks in advance,
agnivesh.
 
T

Thomas Matthews

agnivesh said:
Hi there,

I'm a beginner in C programming and want to learn how to write C (pure
C) code to access hardware ports (serial,parallel,usb etc.) under
windows environment ?

1. Please, suggest any online tutorials or free ebooks etc. for that.

2. Is it possible to do above tasks using MingW Developer Studio, GTK+
etc. ? I've just downloaded these tools and want to make sure before
starting learning these tools, that we can use these tools to write
small windows GUI applications (in C), which can interact with external
embedded systems through PC's serial, parallel or usb port.

thanks in advance,
agnivesh.

Hardware ports are platform dependent. The bigger platforms
require that programs use operating system functions to access
the ports. In smaller platforms, programs generally access
some kind of hardware chip. In even smaller platforms, the
ports are accessed directly.

You will have to ask in a newsgroup about your platform or
operating system.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 
A

agnivesh

Please guide considering my os being windows xp and I want to interact
with external hardware thruogh hardware ports like serial, parallel or
usb using C.

thanks in advance.
 
G

Gordon Burditt

Please guide considering my os being windows xp and I want to interact
with external hardware thruogh hardware ports like serial, parallel or
usb using C.

This question is best asked in a newsgroup specific to your OS.

A reasonable OS will insist that a user-level program ask the OS
nicely (and if you don't have admin-like privileges, say "NO")
before letting it do direct I/O to ports (assuming the hardware
supports such a thing at all), or simply not allow it at all. After
you've asked nicely, you may be able to use the assembly-language
instructions to do I/O to ports.

Or you use the drivers that the OS has provided.

It is not particularly easy to do your own I/O to USB devices when
the OS is also trying to do I/O to USB devices it controls (e.g.
the keyboard and/or mouse.) without stomping over each other and
likely locking up the system. Generally the right way to do this
is called "writing a driver".

Operating systems likely to qualify as a "reasonable OS" as defined
above include UNIX, Linux, and recent versions of Windows (including
XP). CP/M, most configurations of MS-DOS, and Windows 3.1 and
earlier don't. I'm not sure of the status of Windows 95 and Windows
98.

Gordon L. Burditt
 
C

CBFalconer

agnivesh said:
Please guide considering my os being windows xp and I want to
interact with external hardware thruogh hardware ports like
serial, parallel or usb using C.

What part of Thomas Matthews advice, to which you replied but
didn't bother to quote, don't you understand? Also see the advice
in my sig, below.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson

Chuck F ([email protected]) ([email protected])
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
 
V

Villy Kruse

What part of Thomas Matthews advice, to which you replied but
didn't bother to quote, don't you understand? Also see the advice
in my sig, below.

Appart from that, I don't think a beginner should even go there. On xp
system the hardware should exclusively be accessed through device drivers
and user programs should then talk to the device drivers using the API
designed for this purpose.

Villy
 
I

italy

Eh, this newsgroup is specifically for discussion of the C language.

1. Google
2. Yes, you may use any compiler. Look into your platform for how ports
are written to, and obviously read.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top