【发布时间】:2017-08-04 17:54:11
【问题描述】:
我想使用 D 编写的脚本打开和关闭嵌入式 linux 板 (BeagleBone Black) 的 LED(字符设备)。
通过命令行可以打开和关闭一个 LED(例如,对于 LED“USER LEDS D2 0”):
cd /sys/class/leds/beaglebone:green:usr0
echo none > trigger
echo 1 > brightness
echo 0 > brightness
(echo none > trigger 禁用默认的“心跳”闪烁)
在第 93 页的 D Cookbook 中,我找到了有关如何通过 C 接口进行 linux 系统调用的信息,如下所示:
void main(){
import core.sys.posix.unistd; // analogous to #include <unistd.h>
string hello = "Hello, world!";
write(1 /*stdout file descriptor*/, hello.ptr, hello.length);
}
这是访问字符设备的合适方法还是有更好的替代方法?
【问题讨论】:
-
顺便说一句:使用这里描述的 std.process stackoverflow.com/questions/6876553/… 对我也不起作用......
-
LDC 和 DMD 都为我编译了这个 sn-p(LDC 1.3.0 和 DMD 2.075.0)。你得到什么样的错误?
-
用 dmd 我得到
hello.d(3): Error: unexpected ( in declarator hello.d(3): Error: basic type expected, not 1 hello.d(3): Error: found '1' when expecting ')' hello.d(3): Error: no identifier for declarator write(_error_) hello.d(3): Error: semicolon expected following function declaration hello.d(3): Error: declaration expected, not ',' -
发布的代码和你编译的完全一样吗?它错过了
string hello = ...行上的分号。 -
不,它不缺少分号。和上面一模一样……
标签: linux-device-driver d