以下shell命令切换Leopardboard gpio 31就好了:
echo 31 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio31/direction
echo 0 > /sys/class/gpio/gpio31/value
echo 1 > /sys/class/gpio/gpio31/value
echo 0 > /sys/class/gpio/gpio31/value
This用作以下代码的示例。 知道为什么以下.vala代码不会切换gpio 31吗?
public void sync () {
int fd = -1;
fd = open("/sys/class/gpio/export", O_WRONLY);
if (fd < 0) {
GLib.stdout.printf("Error sync export\n");
return;
}
write(fd, "31", 3);
close(fd);
fd = open("/sys/class/gpio/gpio31/direction", O_WRONLY);
if (fd < 0) {
GLib.stdout.printf("Error sync direction\n");
return;
}
write(fd, "out", 4);
close(fd);
fd = open("/sys/class/gpio/gpio31/value", O_WRONLY);
if (fd < 0) {
GLib.stdout.printf("Error sync value\n");
return;
}
write(fd, "0", 2);
write(fd, "1", 2);
Thread.usleep (1000); /* 1ms */
write(fd, "0", 2);
close(fd);
}
答案 0 :(得分:3)
echo 31
实际上会产生\ x33 \ x31 \ x0a,但您的write
调用会写入\ x33 \ x31 \ x00。尝试这样的事情:
write(fd, "31\n", 3);
您还需要对write
的其他来电进行类似的调整。