linux 读取设备节点值

来源:互联网 发布:mac装windows 编辑:程序博客网 时间:2024/06/05 15:03

int HalValueLoad(void)
{
 int fdd;
    char rbuf[1]={'\0'};
    char wbuf1[1]={'1'}; //字符'1'的ASCII码是49
    char wbuf2[1]={'0'}; //字符'0'的ASCII码是48
    static uint8 uHalValue = 0;
 
 fdd= open("/sys/class/switch/hall/state", O_RDWR);
 if(fdd==-1)
 {
  //printf("can't open the file\n");
 }
 read(fdd,&rbuf,1);
 if(!strncmp(wbuf1,rbuf,1))
 {
  //printf(" equal  11111111111111111\n");
  uHalValue = 1;   
 }
 else if(!strncmp(wbuf2,rbuf,1))
 {
  //printf(" equal 0000000000000000000\n"); 
  uHalValue = 0;  
 }

 close(fdd);
 return uHalValue;
}

0 0
原创粉丝点击