views:

4425

answers:

8

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!

+4  A: 

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

Diodeus
+1  A: 

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

ironfroggy
V8 is very nice btw.
Daniel A. White
+1  A: 

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.

svinto
+4  A: 

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.

Adam Davis
It's not convoluted. Whoever "-1"d this is silly. It's a lot simpler than writing ActiveX or XPCOM code to send junk out to the serial port.
Jason S
+1 for outside (or inside) the box. Good answer!
Moose
+1; it wouldn't even necessarily have to be a full web server, could just be a C daemon (I'm guessing C is the easiest way to access the serial port) which listens on a socket and speaks something close enough to HTTP to fool the browser ;-)
Kieron
I'm not sure if this approach is really going to make things easier. The first request locks the serial port. What do you want to happen when another request comes in before the first finishes?I'm thinking more along the lines of what Kieron describes.
Wouter van Nifterick
The requests are queued - the first request won't take forever (and timeouts will enforce that. The serial port server portion will have to handle this case of course, and it's the same issue as printing documents - one piece of hardware, with multiple users.
Adam Davis
+2  A: 

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.

TJ
+2  A: 

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.

Jason S
A: 

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.

A: 

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.

Tracker1