gpt4 book ai didi

javascript - USB 模块失败的 Node webkit 应用程序

转载 作者:太空宇宙 更新时间:2023-11-04 02:22:39 25 4
gpt4 key购买 nike

我正在使用 node-webkit 编写桌面应用程序。我已经使用 Node USB 模块编写了脚本,如果我使用 Node 运行该脚本,该脚本可以正常工作。它列出了所有 USB 设备、连接、读取、写入。现在我想使用 node-webkit 应用程序来实现相同的目标,其中 HTML 有一个我们必须在其上执行这些操作的按钮。现在为此我们需要配置 Node 模块。我已将该模块添加到我的项目中,然后按照上述方式进行处理

package.json:

{
"name": "node-webkit-angular-bootstrap-starter",
"version": "0.0.1",
"description": "Starter destkop app using node-webkit, html5, angular, and bootstrap",
"main": "app/index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"window": {
"title": "node-webkit-angular-bootstrap-starter",
"toolbar": true,
"frame": true,
"width": 1024,
"height": 768,
"position": "center"
},
"dependencies" : {
"node-pre-gyp": "0.6.9"
},
"bundledDependencies":["node-pre-gyp"],
"devDependencies": {
"aws-sdk": "~2.0.0-rc.15"
},
"scripts": {
"install": "node-pre-gyp install --fallback-to-build"
},
"binary": {
"module_name": "usb",
"module_path": "./app/lib/binding/",
"host": "https://github.com/camsoupa/node-usb"
}
}

Home.js:

(function () {    'use strict';  app.controller('homeController', function ($scope) {alert("Heelooooo");


var gui = require('nw.gui');
var os = require('os');

$scope.settings = [];
$scope.usb = require('usb'); });})();

使用 nw 运行应用程序时出现以下错误

"%1 is not a valid Win32 application.↵D:\Projects\…er\node_modules\usb\src\binding\usb_bindings.node"}

有人可以帮我吗?

最佳答案

在我的案例中,我通过编译正确的架构解决了这个问题。在我的环境中,node 是 32 位,而 nw 是 64 位。将目录更改为 USB 模块,以下两个命令通过创建 64 位版本的 native 绑定(bind)解决了该问题:

nw-gyp configure --target=0.12.3 --module_name=usb_bindings --module_path=..\src\binding\ --target_arch=x64

nw-gyp build --target=0.12.3 --module_name=usb_bindings --module_path=..\src\binding\ --target_arch=x64

module_namemodule_path 变量是必需的,因为无论出于何种原因,nw-gyp 都无法从 binding.gyp 文件中获取它们的值。

可能导致您描述的错误的另一件事是将 nw.exe 重命名为其他名称。只要它被命名为nw.exe,符号就会正确绑定(bind)。

关于javascript - USB 模块失败的 Node webkit 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32344741/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com