linux 讀取裝置節點值
阿新 • • 發佈:2019-01-27
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;
}