1

I have implemented a Linux driver (beaglebone) that queries some hardware by SPI and copies the received data in a kfifo (which can get full if it is not emptied). - This kfifo is emptied by performing reads on a char device file (let's call it /dev/foo). - An userland program is responsible for reading the correct fifo entry size (or a multiple of it). - The driver is started and stopped through sysfs entries.

The example C userland program reads this file in blocking mode (i.e., the read returns when data is available).

Now here's my problem: I have a server in node.js running on the beaglebone for administration purposes and would also like to make it "collect" the data (on /dev/foo) and send it via websockets.

I don't really know how to do that, since /dev/foo is not a regular file (so fs.watch does not work), and data keeps on being available randomly on it.

Questions: - Can I solve this problem with node's standard library (like with streams, etc?) - Is there a node module that could solve my problem? - Or do I have to write a node module myself (using libuv?)

Thanks for your hints on any of these points.

mamahuhu
  • 311
  • 2
  • 10
  • 1
    Since stdin is also a character device, perhaps [this](http://stackoverflow.com/a/12506613/893780) might be a good starting point? – robertklep Mar 12 '13 at 17:02
  • 1
    Thanks. This gave me the (good) idea of opening /dev/foo as a stream (with `createReadStream`) – mamahuhu Mar 14 '13 at 18:58

1 Answers1

0

I know this a bit old, but mamahuhu gave me the right idea!

Here is what I do:

var fs = require('fs');

var readStream = fs.createReadStream("/dev/foo");

readStream.on('data', function (data) {
    console.log(data);
});
Lucas
  • 13,679
  • 13
  • 62
  • 94