简体   繁体   English

带RS-232串口的Javascript接口

[英]Javascript interface with RS-232 Serial Port

I am currently working on a project that involves a 4 Port A/V switch. 我目前正在开发一个涉及4端口A / V开关的项目。 This switch can be controlled via RS-232. 该开关可通过RS-232控制。

The computer that will interface with the switch runs Vista. 与交换机连接的计算机运行Vista。 I would like to create a sidebar gadget that has 4 buttons- 1 for each port on the switch. 我想创建一个侧栏小工具,它有4个按钮 - 交换机上的每个端口都有1个。 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. 我已经做了一些谷歌搜索,似乎没有一个非常好的方式来javascript和rs-232之间的接口。

Does anyone have any suggestions for me? 有人对我有什么建议吗?

Thanks! 谢谢!

Do you like convoluted hacks? 你喜欢错综复杂的黑客吗?

Install a webserver. 安装Web服务器。 Use CGI, Python, PHP, Perl, or some other method to control the serial port from a page on the webserver. 使用CGI,Python,PHP,Perl或其他方法从Web服务器上的页面控制串行端口。

Point the control at the webpage. 将控件指向网页。

I think you'll need to add a Java or Active-X layer in between. 我认为你需要在它们之间添加Java或Active-X层。 JavaScript is pretty well isolated (deliberately) from the OS. JavaScript在操作系统中非常孤立(故意)。

Javascript in particular, or just from the browser with some method? 特别是Javascript,还是只是从浏览器中用一些方法? 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. (IE或Firefox?)使用XUL + javascript的Firefox插件非常简单,尽管你仍然需要在XPCOM(Mozilla相当于ActiveX / COM)中实现一些工作RS232。

Alternatively you could use JSDB as an impromptu web server (on an alternate port of the local machine). 或者,您可以将JSDB用作即兴Web服务器(在本地计算机的备用端口上)。 It's ridiculously easy to use the RS232 port in JSDB: 在JSDB中使用RS232端口非常容易:

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. 因此,您的浏览器端实现可能只是您最喜欢的书签/链接/东西链接到http://localhost:9999/comport/1 ,其中9999是#JSDB正在侦听的端口,“1”是串行端口开关。 The JSDB code would listen to the port and send the appropriate RS232 command after parsing a GET request from the browser. 在解析来自浏览器的GET请求后,JSDB代码将侦听端口并发送相应的RS232命令。

RealTerm has an extensive COM interface and is easy to control from JavaScript on windows. RealTerm具有广泛的COM接口,可以通过Windows上的JavaScript轻松控制。 The SourceForge downloads page has version 2.0.0.57, and i2cchip.com has a version 2.0.0.70. SourceForge下载页面的版本为2.0.0.57, i2cchip.com的版本为2.0.0.70。

There is a JavaScript example in the "examples" subdirectory which is installed by default. 默认情况下安装的“examples”子目录中有一个JavaScript示例。

Sadly, the JavaScript examples appear to have been removed from later versions 4 It may still be possible to do it, but there are no examples. 遗憾的是,JavaScript示例似乎已从更高版本中删除4可能仍然可以执行此操作,但没有示例。

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 签名的Java applet将允许您访问系统
  2. Use RXTX (Java Serial COM API) to connect to serial ports 使用RXTX(Java Serial COM API)连接到串行端口
  3. Applet would need to install files to the jre/ext folder. Applet需要将文件安装到jre / ext文件夹。 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. 现在,如果您从自己的计算机上运行javascript,则可以使用HTA来完全访问系统。

您可以尝试查看类似V8的内容,并为C库编写一个小包装器以向VM公开。

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. 您需要在系统上安装的RS-232 ActiveX组件,然后在侧栏小部件的javascript代码中创建一个对象。 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. 请注意,没有标准来从ActiveX组件创建对象,这仅适用于JScript,Microsoft的语言实现我们都知道为Javascript。

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. 我想为这项任务实现一个Vista边栏小工具。 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. 不幸的是,看起来这些只是基本上使用javascript的html文档,所以看起来这对我来说不是一个好的解决方案。 I'll probably just write a little .Net application or something. 我可能只是写一点.Net应用程序或其他东西。

Thank you for all of your input though. 谢谢你的所有输入。 If any one still has ideas, I'll take them. 如果任何人仍然有想法,我会接受他们。

AFAIK, Vista gadget's runtime supports the use of signed ActiveX controls. AFAIK,Vista小工具的运行时支持使用已签名的ActiveX控件。 You may also be able to use Java. 您也可以使用Java。 You can create an ActiveX wrapper to .Net which has a fair amount of support for serial devices. 您可以为.Net创建一个ActiveX包装器,它对串行设备有相当大的支持。 For the most part ActiveX + Serial communications is limited to commercial controls. 在大多数情况下,ActiveX +串行通信仅限于商业控制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM