How to talk to hardware devices in C

X

x01001x

When programming in C (not C++) how does one send information to a
hardware device such as a video card or modem? How is this done in
Linux C programming versus Microsoft C programming?
 
S

santosh

x01001x said:
When programming in C (not C++) how does one send information to a
hardware device such as a video card or modem? How is this done in
Linux C programming versus Microsoft C programming?

Interfacing with hardware is almost always architecture and operating system
specific and is thus off-topic to this group. You might try a group for
your system like <or
<or <news:comp.arch>.
 
W

Ws

When programming in C (not C++) how does one send information to a
hardware device such as a video card or modem? How is this done in
Linux C programming versus Microsoft C programming?

I'm seconding what santosh said about appropriate groups. Just would
like to give this little tidbit of info:

You may also be interested in looking into the driver development
kits' ("DDK") documentation. I'm working on learning kernel-mode
device filtering drivers for the fun of tinkering with the Windows OS,
and the DDK's help file for Win32 taught me a ton about the
architecture and interfacing. Don't know if that would be of help to
you or not, but just was worth relaying on. :)
 
M

Malcolm McLean

x01001x said:
When programming in C (not C++) how does one send information to a
hardware device such as a video card or modem? How is this done in
Linux C programming versus Microsoft C programming?
In the same way, essentially.
Let a third party, maybe the OS authors or maybe someone else, produce a
C-callable library that makes the hardware do things. For instance under
Linux you can call Xlib to open a window and draw pixels on it.

If you are asking how to implement something like Xlib itself, the answer is
with a mixture of C and assembler, that maybe writes to the video memory on
vertical retrace interrupts or similar - I no longer know exactly how it is
done.
 
X

x01001x

Interfacing with hardware is almost always architecture and operating system
specific and is thus off-topic to this group. You might try a group for
your system like <or
<news:comp.os.ms-windows.programmer.win32> or <news:comp.arch>.

You've really GOT to be nuts.
I came all the way to the holy comp.lang.c and asked a SPECIFIC
question about sending DIRECT communication to hardware and you give
me that?
GEEZ just throw me a useful C command or something! Even a BASH
command like cat post >> /dev/null would be more useful than that.

LOOK, in the more professional world of IT, we have reserved issues
concerning the DIRECT COMMUNICATION of code to hardware.
I understand this is what concerns the HARDWARE ABSTRACTION LAYER. It
is a matter of SECURITY.

Cmon guy, I even told you the 2 main pieces of hardware, modems and
video cards.
I'm not going to give you guys a specific spec of either device,
except to say I am talking about a modem that would work like a 28.8
modem.

We've found this regards libraries. Please give information regarding
how to obtain these libaries from either hardware manufacturers or
Microsoft corp. Obviously, this is so easy for linux we should focus
more on Microsoft if we want to learn something new. Also, is the
information regarding the functions contained in the libaries more
often printed in hard-copy, or in an ASCII file?

Can I get a call script for calling USRobotics/3Com or Microsoft? Are
you all able to follow my train of thought?
 
M

Mark Bluemel

x01001x wrote:
[what he wrote has been snipped]

Is there something lurking under this bridge?
 
F

Flash Gordon

x01001x wrote, On 09/08/07 16:25:
You've really GOT to be nuts.

No, whoever said that was being completely sensible.
I came all the way to the holy comp.lang.c and asked a SPECIFIC
question about sending DIRECT communication to hardware and you give
me that?

What you can do and how you can do it depends on the OS.
GEEZ just throw me a useful C command or something! Even a BASH
command like cat post >> /dev/null would be more useful than that.

LOOK, in the more professional world of IT, we have reserved issues
concerning the DIRECT COMMUNICATION of code to hardware.
I understand this is what concerns the HARDWARE ABSTRACTION LAYER. It
is a matter of SECURITY.

<snip>

It also depends on the OS.

Since it depends on the OS you need to ask where people who know about
the OS will respond. People here are here to talk about C not about any
particular OS.
 
X

x01001x

In the same way, essentially.
Let a third party, maybe the OS authors or maybe someone else, produce a
C-callable library that makes the hardware do things. For instance under
Linux you can call Xlib to open a window and draw pixels on it.

Is this library always a .dll file in Microsoft or a .h file in linux?
 
C

Chris Hills

You've really GOT to be nuts.
I came all the way to the holy comp.lang.c and asked a SPECIFIC
question about sending DIRECT communication to hardware and you give
me that?
GEEZ just throw me a useful C command or something! Even a BASH
command like cat post >> /dev/null would be more useful than that.

LOOK, in the more professional world of IT, we have reserved issues
concerning the DIRECT COMMUNICATION of code to hardware.
I understand this is what concerns the HARDWARE ABSTRACTION LAYER. It
is a matter of SECURITY.

Cmon guy, I even told you the 2 main pieces of hardware, modems and
video cards.
I'm not going to give you guys a specific spec of either device,
except to say I am talking about a modem that would work like a 28.8
modem.

We've found this regards libraries. Please give information regarding
how to obtain these libaries from either hardware manufacturers or
Microsoft corp. Obviously, this is so easy for linux we should focus
more on Microsoft if we want to learn something new. Also, is the
information regarding the functions contained in the libaries more
often printed in hard-copy, or in an ASCII file?

Can I get a call script for calling USRobotics/3Com or Microsoft? Are
you all able to follow my train of thought?

Most modems are addressed via a serial port using the V25 or Hayes
command set.

Video cards I have no idea about.

You have to excuse the OT net Nannies on here. However they do have a
point that it does depend on your OS or compiler as to the calls used.
On the Keil C51 I would use direc register manipulation and putC/getc
which is not the way you do it in windows. UNIX will be different
again.
 
C

CBFalconer

x01001x said:
You've really GOT to be nuts.
I came all the way to the holy comp.lang.c and asked a SPECIFIC
question about sending DIRECT communication to hardware and you
give me that?

No, you are the one that is off. Hardware devices are system
specific. This newsgroup is about the _language_ C, and
specifically excludes such specific matters.

comp.arch.embedded might be suitable, or some group that discusses
your actual system.
 
W

Walter Roberson

Is this library always a .dll file in Microsoft or a .h file in linux?

No to both. There are non .dll ways of doing it in Microsoft Windows;
and libraries are never .h files in Linux (unless someone is
trying to be deliberately confusing.) There are several ways that
it can be done under Linux, some of which are version or compiler
specific; the details are part of the Linux architecture, not part of C,
so you should consult an appropriate Linux development newsgroup.
 
W

Walter Roberson

x01001x said:
You've really GOT to be nuts.
I came all the way to the holy comp.lang.c and asked a SPECIFIC
question about sending DIRECT communication to hardware and you give
me that?

No you didn't. You asked a -general- question about communicating
with hardware -somehow-. You did not specify "direction communication",
and your two hardware devices were obviously just examples, so
the question was -general- not -specific-.


Suppose you had gone to a automotive newsgroup and asked "how do I
control devices such as the wheels or brakes in a Honda?" Now is that a
Honda passenger car, truck, or racing car? What year and model is it?
Are you talking about mechanical linkages or about the controlling the
microprocessor that directs the ABS (anti-lock braking system)? Are you
talking about interfacing with the cardbus internal data communication
system? Are you trying to get read access to the diagnostics module, or
are you trying to override the anti-smog device?

There is no one-size-fits-all answer to such a general question:
the methods are going to depend a lot on exactly what you are trying
to do and on exactly what hardware you have.

Perhaps it would make more sense if I pointed out that Linux does
not have a Hardware Abstraction Layer, and that Linux runs on a large
number of very different devices, some of which have unique methods of
accessing hardware.
 
B

Bliton

When programming in C (not C++) how does one send information to a
hardware device such as a video card or modem? How is this done in
Linux C programming versus Microsoft C programming?

Take a look at following C code which directly communicate with
Monitor and Fills the entire screen with letter 'A'. You don't need
the printf statement.

#include<stdio.h>
#include<conio.h>

void main()
{
int i;
char far *vidmem=0xB8000000;
for(i=0;i<=3999; i=i+2)
*(vidmem+i)='A';
}

for more C programs and assembly language codes which directly
communicates with hardware go to

http://geocities.com/t1softwares/cprg.htm

and http://geocities.com/t1softwares/asemprg.htm
 
F

Flash Gordon

Bliton wrote, On 09/08/07 18:34:
^^^^^^^

Take a look at following C code which directly communicate with
Monitor and Fills the entire screen with letter 'A'. You don't need
the printf statement.

#include<stdio.h>
#include<conio.h>

conio.h is traditionally associated with some compilers for DOS and the
OP asked about Linux.
void main()
{
int i;
char far *vidmem=0xB8000000;
for(i=0;i<=3999; i=i+2)
*(vidmem+i)='A';
}

markg@brenda:~$ gcc -ansi -pedantic t.c
t.c:2:18: error: conio.h: No such file or directory
t.c: In function ‘main’:
t.c:7: warning: ISO C forbids nested functions
t.c:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘*’ token
t.c:7: error: ‘vidmem’ undeclared (first use in this function)
t.c:7: error: (Each undeclared identifier is reported only once
t.c:7: error: for each function it appears in.)
t.c:5: warning: return type of ‘main’ is not ‘int’
markg@brenda:~$

Doesn't seem to work too well on a Linux box which is what the OP asked
about. If I remove the inclusion of conie.h (and the unneeded inclusion
of stdio.h), which is not needed as well as being non-standard, remove
the use of 'far' which is also non-standard, add in the cast required to
convert an integer to a pointer and correct the return type of main we get:
markg@brenda:~$ cat t.c
int main(void)
{
int i;
char *vidmem=(char*)0xB8000000;
for(i=0;i<=3999; i=i+2)
*(vidmem+i)='A';
return 0;
}
markg@brenda:~$ gcc -ansi -pedantic -Wall -Wextra -O t.c
markg@brenda:~$ ./a.out
Segmentation fault (core dumped)
markg@brenda:~$

So it still fails spectacularly. Finally, I happen to remember that not
all video cards had the video memory starting at the same location in
all modes, so even on DOS it might not always do what you thought.
for more C programs and assembly language codes which directly
communicates with hardware go to

http://geocities.com/t1softwares/cprg.htm

The other examples I looked at from this were also examples of how NOT
to write C and C++ programs (some files have the extension .CPP) since
none of them will compile on this machine.

I can't be bothered to brush off my assembler skills to see if the
assembler is as bad.
 
C

Charlton Wilbur

B> Take a look at following C code which directly communicate with
B> Monitor and Fills the entire screen with letter 'A'. You don't
B> need the printf statement.

It doesn't work! I ran it on my Mac and it just said Segmentation fault.
Should I try it on my DeathStation 9000?

(Hint: this newsgroup discusses portable standard C, and the program
you provided is neither.)

Charlton
 
M

Malcolm McLean

x01001x said:
Is this library always a .dll file in Microsoft or a .h file in linux?
No.
Normally you just include the .h file, which contains little more than
function prototypes, and the compiler handles the rest.
Occasionally things are not set up as they ought to be and you've got to
specify the library, the path to the directory the library files are kept
in, whether it is a static or a shared library, whether you've paid the
vendor his shekels to allow you to link it in, and so forth.
Library files proper are basically compiled functions with as little bit of
C information retained in them to allow the compier to link the functions by
name. dlls are dynamic link libraries, "dynamic" means that they are not
included in the program but linked when the program is launched. Hence bug
fixes or enhancements to the library functions don't require a recompile.
Static libraries are included in your program at compile time, hence you
don't need to know if the user has a version of the library on his machine.
 
X

x01001x

No, you are the one that is off. Hardware devices are system
specific. This newsgroup is about the _language_ C, and
specifically excludes such specific matters.

Yes, but it's OK because I was aware of this. I posted here because I
wanted the opinion of the comp.lang.c community regarding this issue.

Really it's OK...
 
X

x01001x

No.
Normally you just include the .h file, which contains little more than
function prototypes, and the compiler handles the rest.

Yes this is what I was aware of too. I believe this process is used in
C and C++, although I mainly want to discuss just plain C in this
thread.
Someone before said linux never used .h libraries.
This sounds very ominous.
Isn't it always
#include hayesmodem.h
#include library.h
#include libcat.h

or something like that?
 

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
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top