蜂鸣器的控制linux
1设备的节点
2控制方法,输入1,蜂鸣器响,输入0蜂鸣器停止
3控制代码
#include <stdio.h>
//文件操作函数头文件
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#define BUZZ_CMD 2
/*
cmd:0--->buzz off 1--->buzz on
*/
int main(int argc ,char **argv)
{
int fd,buzzer_cmd;
char *buzz_path="/dev/buzzer_ctl";
printf("\n argv1 is cmd,argv2 is io\n");
printf("\ncmd:0--->buzz off 1--->buzz on\n");
printf("app name:%s\n",argv[0]);
buzzer_cmd = atoi(argv[1]);
if(buzzer_cmd>BUZZ_CMD)
{
printf("para1 buzz cmd err \n");
exit(1);
}
if((fd = open(buzz_path,O_RDWR|O_NOCTTY|O_NDELAY))<0)
{
printf("open path %s err \n",buzz_path);
exit(1);
}
if((ioctl(fd,buzzer_cmd,0))<0)
{
printf("buzz ioctl err \n");
}else
{
printf("buzz ioctl success \n");
}
close(fd);
return 0;
}