ioctl IOError

Christopher N. Deckard cnd at ecn.purdue.edu
Thu Jul 27 00:03:53 EDT 2000


In my quest to learn Python, more about C, and learn syscalls, I decided
to port a C program to Python.  The program is called pcfm and it's used
to talk to the GemTek serial radio tuner (AM/FM).  Why use something
that works, when I can rewrite it in another language right?

So, I've got the serial port part working, now I'm trying to get the
sound mixer stuff to work, and I'm running into problems.  

Here are the thingers in C which use ioctl.  The first, setvolume, is
used to set the volume of the mixer.  The second fetches the current
volume setting.

Also, from soundcard.h, we have:
SOUND_MIXER_READ_LINE = 0x80044D06
SOUND_MIXER_WRITE_LINE = 0xC0044D06
(you can also get these under Linux by doing 'man 2 ioctl_list')

void setvolume(int fd, int value) {
  value = (value<<8)|value;
  if (ioctl(fd, SOUND_MIXER_WRITE_LINE, &value)<0) perror("ioctl
write");
}

int getvolume(int fd) {
  int value;
  if (ioctl(fd, SOUND_MIXER_READ_LINE, &value)<0) perror("ioctl read");
  return ( ((value&0xff)+(value>>8)) /2 );
}

So, I basically need these functions in python.  So I've got a class
called mixer which has the file descriptor (fd), and then these
functions:

def setvolume(self, value):
	value = (value << 8) | value
	fnctl.ioctl(self.fd, SOUND_MIXER_WRITE_LINE, value)

def getvolume(self):
	value = 0
	fnctl.ioctl(self.fd, SOUND_MIXER_READ_LINE, value)
	return (((value & 0xff) + (value >> 8)) / 2)

When I simply call the 'getvolume' function, I get:
IOError: (14, 'Bad address')


What is going on?  How do I fix it?  I'd like to leave these in Python,
but it is my understanding that I could create a C object and link them
in somehow?  How is that done?

Thanks for the help.  Please email me as well as reply to the newsgroup.
-Chris

-- 
----------------------------------------------------------------------
    Christopher N. Deckard      |        Lead Web Technician
      cnd at ecn.purdue.edu        |    Engineering Computer Network
     http://triad.dhs.org       |   http://www.ecn.purdue.edu/ECN/
----------------------------------------------------------------------



More information about the Python-list mailing list