Javascript interface with RS-232 Serial Port

回眸只為那壹抹淺笑 提交于 2019-11-27 16:51:13

问题


I am currently working on a project that involves a 4 Port A/V switch. This switch can be controlled via RS-232.

The computer that will interface with the switch runs Vista. I would like to create a sidebar gadget that has 4 buttons- 1 for each port on the switch. When the user presses the button, it switches to that port.

I have done a bit of googling, and it seems that there isn't a very good way to interface between javascript and rs-232.

Does anyone have any suggestions for me?

Thanks!


回答1:


Do you like convoluted hacks?

Install a webserver. Use CGI, Python, PHP, Perl, or some other method to control the serial port from a page on the webserver.

Point the control at the webpage.




回答2:


I think you'll need to add a Java or Active-X layer in between. JavaScript is pretty well isolated (deliberately) from the OS.




回答3:


Javascript in particular, or just from the browser with some method? And which browser? (IE or Firefox?) Firefox plugins using XUL + javascript are pretty easy, although you'd still have to implement something in XPCOM (the Mozilla equivalent of ActiveX/COM) to work the RS232.

Alternatively you could use JSDB as an impromptu web server (on an alternate port of the local machine). It's ridiculously easy to use the RS232 port in JSDB:

c:\>jsdb
js>S=new Stream('com1://115200');
com1
js>S.write('\x00');    // send ASCII character 0 to the serial port
1
js>

So your browser-side implementation could just be whatever your favorite bookmark/link/thingy is that links to http://localhost:9999/comport/1 where 9999 is the port # JSDB is listening to, and "1" is the serial port switch. The JSDB code would listen to the port and send the appropriate RS232 command after parsing a GET request from the browser.




回答4:


RealTerm has an extensive COM interface and is easy to control from JavaScript on windows. The SourceForge downloads page has version 2.0.0.57, and i2cchip.com has a version 2.0.0.70.

There is a JavaScript example in the "examples" subdirectory which is installed by default.

Sadly, the JavaScript examples appear to have been removed from later versions4 It may still be possible to do it, but there are no examples.




回答5:


I don't have a solution, but here could be a start of one.

  1. Signed java applet would give you access to the system
  2. Use RXTX (Java Serial COM API) to connect to serial ports
  3. Applet would need to install files to the jre/ext folder. Restart the app after doing so.

Now if you're running the javascript from your own machine you could use HTA to have full access to the system.




回答6:


You could try looking at something like V8 and writing a small wrapper for the C library to expose to the VM.




回答7:


You need a RS-232 ActiveX component that you install on the system and then create an object from in the javascript code in your sidebar widget. Note that there is no standard to create objects from ActiveX components, this is only available in JScript, Microsoft's implementation of the language we all know as Javascript.




回答8:


I'm sorry to be posting under my own question- I hadn't registered, so now I cannot edit it.

I wanted to implement a Vista Sidebar Gadget for the task. unfortunately it looks like those are just basically html documents with javascript, so it doesn't look like that is going to be a good solution for me. I'll probably just write a little .Net application or something.

Thank you for all of your input though. If any one still has ideas, I'll take them.




回答9:


AFAIK, Vista gadget's runtime supports the use of signed ActiveX controls. You may also be able to use Java. You can create an ActiveX wrapper to .Net which has a fair amount of support for serial devices. For the most part ActiveX + Serial communications is limited to commercial controls.



来源:https://stackoverflow.com/questions/592099/javascript-interface-with-rs-232-serial-port

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