Page 1 of 1

Programming to control hardware

Posted: 2010-06-05 10:19pm
by raptor3x
So I've come to realize that I don't know even the basics of how to write code to interface a computer with external hardware. I know how to write codes to do FEM, FVM simulations, mesh generation, etc. but how the computer controls the blinking lights on my network card is a complete mystery to me. So, can any computer science (software engineering?) people give me a starting point or list of good books?

Re: Programming to control hardware

Posted: 2010-06-06 01:36am
by Gerald Tarrant
My experience was more from a bottom up type of learning, so this may not be useful to you, in which case: apologies Ignore.

A good place to start might be to get a basic understanding of digital logic, and maybe the ability to read the various data sheets associated with the hardware you're interested in. Those are kind of important to move into the next step, drivers. Drivers do a couple of things, they manage the low level stuff on hardware (command words and such) and they protect shared resources from over use by multiple threads (the technique I'm familiar with used "semaphores"). For instance if one of your threads were using the modem to send out 20k of data somewhere, a semaphore would prevent another thread from doing anything with the modem until the first thread reported that it was finished sending stuff. I don't think you need a deep understanding of any of those things, but if you can get a basic grasp of those things, you'll probably be ready to start tinkering.

Re: Programming to control hardware

Posted: 2010-06-06 01:38am
by GrandMasterTerwynn
raptor3x wrote:So I've come to realize that I don't know even the basics of how to write code to interface a computer with external hardware. I know how to write codes to do FEM, FVM simulations, mesh generation, etc. but how the computer controls the blinking lights on my network card is a complete mystery to me. So, can any computer science (software engineering?) people give me a starting point or list of good books?
It's like writing code to anything else. Depending on the environment, it can be as simple as linking in the right DLL and invoking the appropriate manufacturer-supplied access functions. If you're in a lower-level environment, you're going to have to push data into pointers to registers on a memory map. You will have to supply the right words to the device to make it do what you want it to do. All of this is usually found in the SDK for whichever device you're interested in trying to access.

The question becomes what sort of hardware are you interested in accessing and on what platform?

Re: Programming to control hardware

Posted: 2010-06-06 06:05am
by Dooey Jo
raptor3x wrote:So I've come to realize that I don't know even the basics of how to write code to interface a computer with external hardware. I know how to write codes to do FEM, FVM simulations, mesh generation, etc. but how the computer controls the blinking lights on my network card is a complete mystery to me. So, can any computer science (software engineering?) people give me a starting point or list of good books?
You could try, or at least read up on, programming stuff for the GameBoy Advance. There's lots of material out there, and it can be fun. Then you will have to interface "directly" with the hardware by reading and writing directly to certain hardware memory addresses (the memory mapping Terwynn is talking about) in various ways.

Re: Programming to control hardware

Posted: 2010-06-06 02:13pm
by Sarevok
I would recommend finding a easy to use micro controller and starting from there. This will help you get a feel of how software can have a tangible effect on the physical world by controlling simple devices like a light switch or motor.

Re: Programming to control hardware

Posted: 2010-06-06 10:01pm
by Korvan
You can get micro controllers these days with built in web servers. You simply connect the controller to your computer with an Ethernet cable and send commands via http. Super simple to use. With a webcam mounted on a servo motor connected to the controller and a free colour tracking addon, I was able to get the camera to track objects. It's been a couple of years since I've messed around with it and I can't remember where I ordered it from, but it wasn't too expensive. There are a number of alternatives that a search on "micro controllers with built in web server" turns up as well.