001- linux - 字符设备控制之ioctl - 控制BUZZER

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define BUZZER_NUM 2

int main(int argc , char* argv[])
{

	int fd , buzzer_num;
	char *buzzer = "/dev/buzzer_ctl";
	
	 
	if(atoi(argv[1]) >= BUZZER_NUM)
	{
		printf("argv1 is 0 or 1 \n");
		exit(1);		
	}	
	

	if((fd = open(buzzer,O_RDWR|O_NOCTTY|O_NDELAY)) < 0)
	{
		printf("open %s failed \n",buzzer);
		exit(1);
	}else{
		ioctl(fd, atoi(argv[1]),atoi(argv[2]));
		printf("open %s success \n ",buzzer);
	}
	close(fd);
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/Stone_Xin_H_T/article/details/81437585
今日推荐