[Tutor] Hardware input
Tue, 23 Jan 2001 22:01:26 -0500
On Mon, Jan 22, 2001 at 08:03:46PM -0800, Matthias Hager wrote:
| How do you receive input from hardware? Can python do it directly? Say I want to make a cd song player, can python do this and how? Or using microphone, printer, scanner, etc..
You want to make device drivers now? This can be interesting. Python
is not particularly well suited for device drivers. It is better to
write such things in C or some other low-level language, then make a
python module that can interact with the driver.
When I did a little bit of assembly language programming (Motorla 68K
arch) we used memory mapped io. Basically, some addresses in memory
were set to read/write to the device's registers (just the PI/T and
DUART). Then the code would simply read/write to those "magic"
locations. C can access arbitrary locations like this, but python
You would also need to know the specs for you the scanner, etc,
communicate with the computer. Not a trivial thing.
If all you want is a higher level control, then perhaps you can
interact with an existing driver. I don't recall if you are working
with Windows or *nix, but it would (probably) be different for each of
To print you would want to work with the system's existing printing
mechanisms. (lpr/lpd for *nix, try the win32all module for 'doze)
I don't know about scanners. There is a standard called TWAIN but I
don't have any experience in developer issues (I've only used scanners
as a user, only in 'doze).
There is probably a sound module you could use for the microphone. I
suppose you could just read from the device file in /dev (*nix), but I
don't know if that will produce useful data or if you would need to do
some significant processing on it.
To read a cd you could open /dev/cdrom. I imagine that you would have
to handle the sector offsets for the tracks yourself. Maybe using
seek()? If you know C you could look at programs like gtcd and see
how they do it.