How can I access a linux character device with D?

Viewed 159

I would like to turn a led (character device) of an embedded linux board (BeagleBone Black) on and off with a script written in D.

Via the command line a led can be turned on and off (e.g. for led "USER LEDS D2 0") with:

cd /sys/class/leds/beaglebone:green:usr0
echo none > trigger
echo 1 > brightness
echo 0 > brightness

(echo none > trigger disables the default "heartbeat" flashing)

In the D Cookbook on page 93 I found info about how to make linux system calls via the C interface like follows:

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);
}

Is that a suitable way to access a character device or are there better alternatives?

1 Answers
Related