//读取GPIO信号
char readBuff[1];
int buffSize = 1;
int readCount = -1;
int gpioId = 969;
int fd1 = open(DEVICE_NAME_TEST969, O_RDONLY);
LOGE("fd1 %d ", fd1);
int readInfo = 0;
readCount = read(fd1, readBuff, buffSize);
if (readCount > 0) {
readInfo = readBuff[0];
if (readInfo >= '0')readInfo = readInfo - '0';
} else {
LOGE("gpio%d read failure", gpioId);
return env->NewStringUTF("读取错误");
}
close(fd1);
//写
int fd1 = open(DEVICE_NAME_TEST969, O_RDWR);
if (fd1 < 0) {
LOGE("gpio%d open failure", gpioId);
return env->NewStringUTF("出现错误");
}
int dataSize = 1;
char dataBuff[1];
if (gpioStatus == 0) {
dataBuff[0] = '0';
} else if (gpioStatus == 1) {
dataBuff[0] = '1';
} else {
return env->NewStringUTF("出现错误212");
}
int writeCount = write(fd1, dataBuff, dataSize);
if (writeCount <= 0) {
return env->NewStringUTF("读写错误");
}
close(fd1);
return env->NewStringUTF(hello.c_str());
网友评论