我试图用频率和持续时间发出嘟嘟声,我使用ioctl和控制台路径中的文件(我认为它是正确的,我顺便说一句,使用debian 6),但我不知道为什么它不起作用。代码到达ioctl行,但不发出哔声。我在虚拟机中工作。驱动程序不应该是问题,因为我已经安装了自己的驱动程序来控制键盘LED,并且没有任何问题。当试图用持续时间和频率发出嘟嘟声时出现ioctl错误
(我按照这个例子: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);
}
}
检查失败的ioctl调用中的“errno”值。 – suspectus
ioctl呼叫,返回0,所以它看起来好像会做得很好 – Kaostias
开启扬声器并将音量调高到零以上:) –