[Tutor] Controlling a device with ioctl's?

Joe Veldhuis electroblog at gmail.com
Wed Aug 25 00:04:05 CEST 2010


Hello to all. I'm working on writing a tool that will control a piece of hardware using ioctl's on its device node. Specifically, I'm trying to configure and tune a DVB-S receiver on Linux.

Just for starters, I want to try opening the frontend and setting the LNB voltage. An example in C:

###
/* all the normal #include's omitted */
#include <linux/dvb/frontend.h>

fd = open("/dev/dvb/adapter1/frontend0", O_RDWR)
r = ioctl (fd, FE_SET_VOLTAGE, SEC_VOLTAGE_18);
if (r == -1)
	perror ("ioctl FE_SET_VOLTAGE");
###

The relevant definitions in linux/dvb/frontend.h:

###
typedef enum fe_sec_voltage {
        SEC_VOLTAGE_13,
        SEC_VOLTAGE_18,
        SEC_VOLTAGE_OFF
} fe_sec_voltage_t;
...
#define FE_SET_VOLTAGE             _IO('o', 67)  /* fe_sec_voltage_t */
###

So, I wrote the following in Python:

###
import fcntl

fe_set_voltage = 67
sec_voltage_13 = 0
sec_voltage_18 = 1
sec_voltage_off = 2

fd = open("/dev/dvb/adapter1/frontend0", "wb")
fcntl.ioctl(fd, fe_set_voltage, sec_voltage_18)
###

This fails with "IOError: [Errno 95] Operation not supported".

Considering I'm not too good with C, and know absolutely /nothing/ about device drivers or kernel code, I'm certain I'm missing something simple and obvious. Anyone want to set me straight?

Thanks,
-Joe


More information about the Tutor mailing list