- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个运行 ubuntu 12.04 的嵌入式板(beagleboard-xm)。我需要连续读取一个 GPIO 以查看端口的值是否发生变化。我的代码如下:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
FILE *fp;
int main(void)
{
//linux equivalent code "echo 139 > export" to export the port
if ((fp = fopen("/sys/class/gpio/export", "w")) == NULL){
printf("Cannot open export file.\n");
exit(1);
}
fprintf( fp, "%d", 139 );
fclose(fp);
// linux equivalent code "echo low > direction" to set the port as an input
if ((fp = fopen("/sys/class/gpio/gpio139/direction", "rb+")) == NULL){
printf("Cannot open direction file.\n");
exit(1);
}
fprintf(fp, "low");
fclose(fp);
// **here comes where I have the problem, reading the value**
int value2;
while(1){
value2= system("cat /sys/class/gpio/gpio139/value");
printf("value is: %d\n", value2);
}
return 0;
}
0
),但是,当我将端口更改为
1
时,
system
调用输出正确的值,但是
printf
仍然打印
0
作为输出。
value2
有什么问题|不存储
system()
的值输出。
while
在上面循环,我得到一个关于打开
value
的错误文件(无法打开值文件。),如果我把
fopen
while
之外的行循环,它不会显示
value
中的更改文件。
char buffer[10];
while(1){
if ((fp = fopen("/sys/class/gpio/gpio139/value", "rb")) == NULL){
printf("Cannot open value file.\n");
exit(1);
}
fread(buffer, sizeof(char), sizeof(buffer)-1, fp);
int value = atoi(buffer);
printf("value: %d\n", value);
}
value
文件?
system("echo 139 > /sys/class/gpio/export")
导出端口和
fp = fopen("/sys/class/gpio/export","w"); fprintf(fp,"%d",139);
你建议我使用哪种方法?为什么?
最佳答案
system()
函数返回cat
的返回值,即 0。它不从 cat
返回标准输出,这是你所期待的。
我认为您的第二段代码的问题在于您没有调用 fclose()
.由于您在一个紧密的循环中运行,您几乎立即超过了允许的打开文件数。
所以,调用fclose()
,并考虑将 sleep()
也在里面。
关于c - 在 C (beagleboard-xm) 中读取端口 (GPIO) 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11375884/
我正在尝试在 BeagleBoard 上进行一些 Android 系统集成像设备。我拥有完整的文件系统访问权限,因为我可以读/写/格式化托管引导和 rootfs 分区的 CF 卡。例如,我可以轻松修改
我可以在 beagleboard xm 上安装 matlab(运行 ubuntu 12.04)吗?如果我不能在 beagleboard xm 上运行 matlab。我安装了 octave,它运行完美,
我有一个设备树覆盖: /dts-v1/; /plugin/; / { compatible = "ti,beaglebone", "ti,beaglebone-black"; part
在 beagleboard 或 beaglebone 中,引脚有不同的工作模式。对于以前的内核,它们位于/sys/kernel/debug/omap_mux 中。你知道最后一个内核中那些文件在哪里吗?
我有一个在 Beagleboard-xM/Angstrom 上运行的 java 应用程序,但是当串行通信开始时,一段时间后,应用程序卡住,我必须取消该进程(终端上的 ctrl + c)。我已经尝试在
我打算在我的 Beagleboard(Android 操作系统)上使用 paw 服务器,不幸的是我在安装 php 插件时遇到了困难。 我在我的 SD 卡中的 paw 中找不到任何插件文件夹。请帮帮我.
我正在尝试在 beagleboard 中启动 android。任何人都可以逐步解释如何使用 beagle board 启动 android。提前致谢。 最佳答案 或者,您可以尝试 0xdroid: h
我没有成功激活我的 beagleboard 上的循环计数器注册器。我读到我必须编译一个 linux 模块,但我也没有成功。 我的 linux 内核是2.6.35.8-l7 这是beagleboard提
我想在 Beagleboards 上使用 Haskell GHC/Haskell 平台基于ARM OMAP的。有什么方法可以在短期内做到这一点,但我不必先尝试交叉编译,例如LLVM 然后 GHC 等几
一个简单的问题:我可以在Angstrom(BeagleBoard)上构建OpenCV,而不必将其作为工具链的一部分下载吗?意思是下载Unix版本的代码并进行构建 (当然,构建过程本身必须通过工具链完成
我正在将一个 linux 应用程序移植到运行在 beagle board 上的 android 上。 我的应用程序必须访问串行端口(发送/接收)。是否可以使用应用程序读取/写入串行端口,除非 andr
我正在使用 BeagleBoard-xM 开发 Angstrom 图像,该图像是使用在线 Narcissus 图像生成器(开放式嵌入式)为 OpenCV 应用程序构建的。我将 OpenCV 包含在根文
我有一个 Beagle 板 OMAP3530-GP,我已将内核和 rootfs 复制到 SD 卡的两个分区中并想启动它。 SD卡分区1:FAT32启动分区 具有相同顺序的以下文件: MLO u-boo
我在将应用程序移植到 ARM 平台时遇到了很多问题。我尝试了 Java Embedded SE,它适用于简单的应用程序,但不适用于音频播放器。 我读了这个 https://blogs.oracle.c
我正在尝试让“hello world”类型的程序在我的 Beagleboard-xm 版本上运行。 C,通过从程序集调用 C puts 函数。 到目前为止,我一直将其用作引用:http://wiki.
我有一个 beagleboard BB-MB-000 Rev. C4,并使用配方 linux-ti-staging_4.4.bb 从 meta-ti-layer 构建一个带有 Yocto 的 core
我正在尝试弄清楚如何让 USB 蓝牙加密狗与我的 BeagleBone Black 配合使用。我尝试了几种不同的方法都无济于事,但看到其他人的帖子似乎取得了一些成功。 我已经尝试过此处记录的过程:ht
我正在尝试在 Beagleboard xM rev B 上启动 Angstrom。 我创建了可启动驱动器和另一个驱动器来放置根文件系统,当我开始运行 beagleboard 时,它启动但在显示以下消息
我在 Beagleboard 上的 Angstrom Linux 上运行 GNOME,设备启动时遇到问题,我正在运行 http://beagleboard.org/latest-images 中的 2
我正在分析 Beagleboard xM 上 POP mDDR 的 X-Loader 设置。BB xM 中的 mDDR POP 内存容量为 512MB(根据手册)。更准确地说,Micron 变体:CS
我是一名优秀的程序员,十分优秀!