欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

1-6、讯为系统编程adc

程序员文章站 2024-03-08 10:46:34
...
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

#define LED_NUM 2
#define LED_C 2

int main(int argc,char *argv[])
{
	int fd,led_num,led_c;
	char *leds = "/dev/leds";
	
	led_num = LED_NUM;
	led_c = led_c;

	printf("argv1 is cmd;argv2 is io\n");
	if(atoi(argv[1])>=led_c){
		printf("argv1 is 0 or 1\n");
		exit(1);
	}
	if(atoi(argv[2])>=led_num){
		printf("argv2 is 0 or 1\n");
		exit(1);
	}
	if((fd == open(leds,O_RDWR))<0){
		printf("open %s failed\n",leds);
	}
	else
	{
		ioctl(fd,atoi(argv[1]),atoi(argv[2]));
		printf("ioctl %s success\n",leds);
	}
	close(fd);
}

 

相关标签: 讯为iTop4412