【问题标题】:Creating node webkit installable创建节点 webkit 可安装
【发布时间】:2015-09-02 05:28:27
【问题描述】:

我正在使用 node webkit 为串行 USB 连接开发一个 Windows 应用程序。

当我使用 node 命令运行脚本时,它会给出准确的输出:

var usb = require('usb');

var devices = usb.getDeviceList();

console.log("Devices are="+devices.length);

var findDevice=usb.findByIds(1027,24577);

console.log("Devices found="+findDevice);

findDevice.open();

然而,当我用 HTML 页面实现它时,它给了我错误

使用脚本的命令 require('usb') 访问 USB 时对内存位置的访问无效

我试过的代码sn-p是

$scope.callFun=function()
{
    var usb=require('usb');

    var devices = usb.getDeviceList();
}

我已经安装了node-pre-gypnpm install usb。我做错了什么?

【问题讨论】:

    标签: angularjs node.js node-webkit nw.js


    【解决方案1】:

    尝试以下方法,不确定,但它可能会起作用。

    添加一个'node-main' 脚本,并在其中按以下方式执行要求:

    exports.usb = require('usb');
    

    然后,在您的 html 中使用 exports.usb 访问它:

    var devices = exports.usb.getDeviceList();
    

    这确实是在黑暗中拍摄,但当我遇到类似问题时它帮助了我。成功了吗?

    【讨论】:

      猜你喜欢
      • 2014-07-05
      • 2014-08-05
      • 1970-01-01
      • 2016-02-15
      • 1970-01-01
      • 2013-01-25
      • 1970-01-01
      • 2016-09-13
      • 1970-01-01
      相关资源
      最近更新 更多