来自 JavaScript 的串行通信?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5640953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 18:12:46  来源:igfitidea点击:

Serial communication from JavaScript?

javascriptserial-port

提问by Nick Heiner

Is it possible to communicate over a machine's serial port through JavaScript?

是否可以通过 JavaScript 通过机器的串行端口进行通信?

I have to write a short program that sends data to a microcontroller over the serial port that has a GUI and is cross-platform compatible, and I really don't want to use Java's Swing.

我必须编写一个短程序,通过具有 GUI 且跨平台兼容的串行端口将数据发送到微控制器,而且我真的不想使用 Java 的 Swing。

回答by Jason LeBrun

JavaScript itself doesn't have any built in functionality to allow you to access the serial port. However, various JavaScript engines (v8, rhino, etc) allow you to write your own custom native objects.

JavaScript 本身没有任何内置功能来允许您访问串行端口。但是,各种 JavaScript 引擎(v8、rhino 等)允许您编写自己的自定义本机对象。

You might want to check out node.js, which is a JavaScript library for v8 that's focused on writing server-side code (rather than web browser client code). It seems that someone's already written a serialport package for that:

您可能想查看 node.js,它是 v8 的 JavaScript 库,专注于编写服务器端代码(而不是 Web 浏览器客户端代码)。似乎有人已经为此编写了一个串行端口包:

https://github.com/voodootikigod/node-serialport

https://github.com/voodootikigod/node-serialport

回答by Bill

There's a cross platform plugin for serial port communication called jUART.

有一个用于串行端口通信的跨平台插件,称为jUART

回答by Mark

This is an old question, but in case this helps anyone else, Chrome Apps have access to a serial API - http://developer.chrome.com/apps/serial.html- which might help.

这是一个老问题,但如果这对其他人有帮助,Chrome 应用程序可以访问串行 API - http://developer.chrome.com/apps/serial.html- 这可能会有所帮助。

It's Chrome specific (obviously..), but Chrome is available cross-platform so might answer the question.

它是 Chrome 特定的(显然......),但 Chrome 可跨平台使用,因此可能会回答这个问题。

回答by Vismari

Yes, it's possible using an ActiveX(I did it). You can make an activeX and use JavaScript to invoke it. If you prefer, you can make a .net dll and register it using regasm. Take a look at this link

是的,可以使用 ActiveX(我做到了)。您可以创建一个 activeX 并使用 JavaScript 来调用它。如果你愿意,你可以制作一个 .net dll 并使用 regasm 注册它。看看这个链接

You also can write an activeX using VB6 and register it. Both works fine. Ps.: if you are using ActiveX, the JavaScript code will run just on IE.

您也可以使用 VB6 编写一个 activeX 并注册它。两者都工作正常。Ps.:如果您使用的是 ActiveX,JavaScript 代码将仅在 IE 上运行。

回答by CAFxX

If you have a DLL library (this includes e.g. most Windows APIs) that allows you to communicate over serial port you can invoke it from Firefox chrome code (or content code with universalxpconnect privileges) by using ctypes.

如果您有一个允许您通过串行端口进行通信的 DLL 库(这包括例如大多数 Windows API),您可以使用ctypes从 Firefox chrome 代码(或具有universalxpconnect 权限的内容代码)调用它。

回答by Jubert

What you could do is to use a Java applet that connects to the local computer's Java application that reads the serial port. The applet would then transfer the data to a JavaScript class or something that can hold the information. Then additional JavaScript code can be used to access the data. It's a complicated solution but should work.

您可以做的是使用连接到读取串行端口的本地计算机的 Java 应用程序的 Java 小程序。然后小程序将数据传输到 JavaScript 类或可以保存信息的东西。然后可以使用额外的 JavaScript 代码来访问数据。这是一个复杂的解决方案,但应该有效。

Another way is to create a POJO service.

另一种方法是创建一个 POJO 服务。

回答by Teson

No.

不。

I'd recommend wx-widgets for the task.

我会推荐 wx-widgets 来完成这项任务。