Serial communication from JavaScript?

拥有回忆 提交于 2019-12-18 11:54:08

问题


Is it possible to communicate over a machine's serial port through 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.


回答1:


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.

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:

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




回答2:


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.

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




回答3:


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




回答4:


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

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.




回答5:


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.




回答6:


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.

Another way is to create a POJO service.




回答7:


No.

I'd recommend wx-widgets for the task.



来源:https://stackoverflow.com/questions/5640953/serial-communication-from-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!