美文网首页
Android JNI读写GPOI,

Android JNI读写GPOI,

作者: 代瑶 | 来源:发表于2022-01-27 15:07 被阅读0次
//读取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());

相关文章

网友评论

      本文标题:Android JNI读写GPOI,

      本文链接:https://www.haomeiwen.com/subject/uydahrtx.html