我正试图用频率和持续时间发出哔哔声,我正在使用ioctl和一个带控制台路径的文件(我认为这是对的,我正在使用debian 6,顺便说一句)但是我不知道为什么它不起作用。代码到达行ioctl,但它没有发出蜂鸣声。我在虚拟机中工作。驱动程序应该不是问题,因为我已经安装了自己的驱动程序来控制键盘LED并且没有问题。
(我已经按照这个例子:http://linuxplayer.org/2010/04/beep-your-pc-speaker-in-linux)
#include <sys/ioctl.h>
#include <linux/kd.h>
int bip;
#define consolepath "/dev/console"
//#define consolepath "/dev/tty0"
void beep (int freq, int dur){
int aux;
if ( (bip = open(consolepath, 'w')) == -1 ) {
printf ("console unreachable/dev/console!\n" );
}else{
//fprintf(bip, "%c[10;%d]%c[11;%d]\a", ESC, freq, ESC, dur); //Another different try
ioctl(bip, KDMKTONE, (dur<<16 | 1193180/freq));
close(bip);
}
}
答案 0 :(得分:1)
我不知道这是否能解决你的问题,但是给出了“oflag”这个论点
至open()
应为O_WRONLY
或O_RDWR
,但不应为'w'
字符。
答案 1 :(得分:0)
问题在于我的操作系统,我在VMWare Workstation中执行Debian 6,端口映射效果不佳,所以我做不到。