BeagleBoard上的NodeJS fs.write错误未知-1



我正在尝试创建一个NodeJS库,该库允许使用BeagleBone的串行(uart)端口。一些引脚是多路复用的,因此一些配置位必须写入两个文件。这是我的函数,它写入配置位以启用uart:

var setMuxForUart = function (uart, next) {
    var txFd, rxFd;
    var txBuf = new Buffer(uart.muxTx.config, 'ascii');
    var rxBuf = new Buffer(uart.muxRx.config, 'ascii');
    var txBytesWritten, rxBytesWritten;
    console.log ("Configuring UART MUX for " + uart.path);
    txFd = fs.openSync (MUX_PATH + uart.muxTx.path, 'w');
    rxFd = fs.openSync (MUX_PATH + uart.muxRx.path, 'w');
    if (txFd && rxFd) {
        try {
            txBytesWritten = fs.writeSync (txFd, txBuf, 0, txBuf.length, 0);
        }
        catch (e) {
            fs.closeSync (txFd);
            fs.closeSync (rxFd);
            console.log ('Error Writing to file: '+ MUX_PATH + uart.muxTx.path + ' | ' + util.inspect (e));            
            return;
        }
        try {
            rxBytesWritten = fs.writeSync (rxFd, rxBuf, 0, rxBuf.length, 0);
        }
        catch (e) {
            fs.closeSync (txFd);
            fs.closeSync (rxFd);
            console.log ('Error Writing to file: ' + MUX_PATH + uart.muxRx.path + ' | ' + util.inspect(e));            
            return;
        }
        fs.closeSync (txFd);
        fs.closeSync (rxFd);
        if (txBytesWritten && rxBytesWritten) {
            console.log ("Uart MUX finished configuration");
            next ();
        }
        else {
            console.log ("An error occured writing to the UART MUX.");
        }
    }
    else {
        console.log ("An error occured while opening the UART MUX files.");
    }
};

这是包含此函数的文件。以下是运行此功能的输出:

root@beaglebone:~/workspace/BonescriptSerial# node BonescriptSerial.js
The "sys" module is now called "util". It should have a similar interface.
Opening Serial Port for: /dev/ttyO1
Configuring UART MUX for /dev/ttyO1
Error Writing to file: /sys/kernel/debug/omap_mux/uart1_txd | { [Error: UNKNOWN, unknown error] errno: -1, code: 'UNKNOWN', syscall: 'write' }

我已经验证了将正确的输出写入测试文件,我尝试了许多模式参数("7777"无关紧要),我尝试过同步和异步函数,但都没有成功,我还尝试过在python中成功地写入这些文件。如果你有任何想法可以帮助解决这个问题,我将不胜感激。

这是该项目的github回购,目前还处于起步阶段,因此没有太多文档。python版本也在repo中。

感谢NodeJS谷歌小组的Ben Noordhuis,我发现了导致问题的以下问题。我试图编写的设备驱动程序显然不接受任意的查找写入,所以为了避免这种情况,我需要欺骗NodeJS使用write而不是pwrite。诀窍是告诉写入命令在-1而不是0开始写入。

fs.writeSync (txFd, txBuf, 0, txBuf.length, -1);

最新更新