JavaScript/JQuery 与 SerialPort/COM1 通信
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18379529/
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
JavaScript/JQuery communicate with SerialPort/COM1
提问by Alex Tape
is it possible to force any communication from e.g. Javascript/JQuery to any serial comport?!
是否可以强制任何从例如 Javascript/JQuery 到任何串行端口的通信?!
google is not able to answer that question.. but anyway it should be possible.. env is firefox in my case..
谷歌无法回答这个问题..但无论如何它应该是可能的..在我的情况下,env是firefox..
ideas/knowledge is very welcome.
非常欢迎想法/知识。
kindly tape
亲切的胶带
采纳答案by markle976
Yes you can, but not with a typical browser. Browsers are sandboxed to not have access to the local file system (except cookies) so that malicious sites can't read from / write to your hard drive. As far as I know there is no way to override this behvior (short of writing your own browser).
是的,您可以,但不能使用典型的浏览器。浏览器被沙箱化,无法访问本地文件系统(cookie 除外),因此恶意站点无法从您的硬盘驱动器读取/写入。据我所知,没有办法覆盖这种行为(缺少编写自己的浏览器)。
However, this can be done in JavaScript using Node.js. It runs as a process rather than in a browser window and can access the file system. Specifically, there is already an npm module (node library) for serial communication: https://github.com/voodootikigod/node-serialport
但是,这可以使用 Node.js 在 JavaScript 中完成。它作为一个进程运行而不是在浏览器窗口中运行,并且可以访问文件系统。具体来说,已经有一个用于串口通信的npm模块(节点库):https: //github.com/voodootikigod/node-serialport
Alternatively, you could always just spin up a local web server (via node.js, php, rails, etc). Web servers can access file systems, and therefore should be able to access serial ports.
或者,您可以随时启动本地 Web 服务器(通过 node.js、php、rails 等)。Web 服务器可以访问文件系统,因此应该能够访问串行端口。
Hope this helps.
希望这可以帮助。
回答by kimstik
I think it is possible..
我觉得有可能。。
Look to: jUART, Cross platform browser plugin for serial port communication from JavaScript https://github.com/billhsu/jUART
查看:jUART,用于 JavaScript 串行端口通信的跨平台浏览器插件 https://github.com/billhsu/jUART
回答by Mimouni
with chrome it's possible ,
使用 chrome 是可能的,
here is the link for documentations : https://developer.chrome.com/apps/app_serial
这是文档的链接:https: //developer.chrome.com/apps/app_serial
or
或者
回答by Matthias
kimstik's suggestion, using the jUART plugin for the browser is an excellent solution.
kimstik 的建议,为浏览器使用 jUART 插件是一个很好的解决方案。
Another possibility is to use a middleware, that facilitates the serial communication and provides a web interface, that JavaScript can interface with using AJAX requests.
另一种可能性是使用中间件,它促进串行通信并提供 Web 界面,JavaScript 可以使用 AJAX 请求与该界面进行交互。
Python could be used, e.g. a script using a combination of pySerialand python-bobo.
可以使用 Python,例如使用pySerial和python-bobo组合的脚本。