本文介绍了从node-webkit访问USB设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个需要在所有3个主要桌面环境(windows,mac和linux)上运行的node-webkit应用程序我需要将我的应用程序连接到插入的USB设备而且我遇到了一些麻烦确切地知道如何解决这个问题。

I'm building a node-webkit app that needs to run on all 3 main desktop environments (windows, mac and linux) I need my app to connect to a plugged in USB device and I'm having a bit of trouble working out exactly how to go about this.

是否存在适用于所有操作系统的npm?我可以使用C ++内置的吗? node-webkit是否内置了与设备交互的内容(设备API?)

Is there an npm that would work across all OS's? Could I get one built in C++ that would work? Is there anything built in to node-webkit for interacting with devices (Devices API?)

提前致谢。

推荐答案

您几乎肯定需要一个C / C ++模块来实现这一点,这意味着需要构建过程。好消息是你可以在你的机器上进行构建并为Windows和OS X分发生成的二进制文件(x86和x64).Linux可能有点棘手,但另一方面它更可能有一个工作版本环境。

You're almost certain to need a C/C++ module to make this happen, which means a build process is required. The good news is that you can just do the build on your machine and distribute the resulting binaries (x86 and x64) for Windows and OS X. Linux might be a little trickier, but on the other hand it's more likely to have a working build environment.

为了方便起见,有几种方法:

There are a few approaches, in order of ease:


  • 如果您的GPS设备可以将其自身显示为简单的串行设备(Windows上的COM端口,或* nix上的 / dev / tty-usbserial ),那么您可以只需使用连接到设备并接收原始数据。有一个模块,可以处理解析数据。 serialport在所有3个平台上都可以开箱即用。

  • If your GPS device can present itself as a simple serial device (a COM port on Windows, or /dev/tty-usbserial on *nix), then you can just use serialport to connect to the device and receive raw data. There's a nmea module that can handle parsing the data. serialport works out of the box on all 3 platforms.

如果驱动程序没有官方选项将设备作为串行设备提供,您可能能够通过一些搜索找到一种不受支持的方式来实现。

If the drivers don't have an official option to present the device as a serial device, you may be able to find an unsupported way to make it happen with some searching.

如果GPS设备的驱动程序没有将设备作为串行设备公开,那么您需要编写与驱动程序接口的。你需要为所有三个平台编写代码;设备制造商应提供文档/ SDK。 (以获取有关在Windows上开始使用本机模块的建议。)

If the GPS device's drivers don't expose the device as a serial device, you'll need to write a C++ module that interfaces with the driver. You'll need to write code for all three platforms; the device manufacturer should provide documentation/an SDK. (See here for advice about getting started with native modules on Windows.)

最后的手段:您可以使用模块直接与设备通信。这可能涉及对设备用于与计算机通信的协议进行逆向工程。

Last resort: you may be able to use the usb module to communicate directly with the device. This will probably involve reverse engineering the protocol that the device uses to communicate with the computer.

这篇关于从node-webkit访问USB设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 21:02