Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to communicate through serial port on client side using javascript?

Recently received a request to add communication to a device connected via serialport on the client's machine through my webpage.

I'd done some googling and found that node.js with node-serialport seems to be the javascript way of doing it. However, in my case, the device is actually connected to the client's machine, and not the server.

My question would be how do i implement node.js in this sense? Since the code is run at the client browser, is it possible for me to 'embed' node.js on my webpage?

Or is there any other alternative for doing this? Applet and ActiveX are out of the picture though.

Thanks

UPDATES: Had managed to convince the client to have applet loaded from the web, so we'll be going through the applet route. Thanks all for your great info! =)

like image 220
ipohfly Avatar asked Jul 27 '12 04:07

ipohfly


3 Answers

Try app.js if you want to access node.js functions from browser.

like image 45
Andrey Sidorov Avatar answered Nov 01 '22 08:11

Andrey Sidorov


JavaScript in the browser only has access to the APIs provided by the browser: it lives in the browser sandbox where it (rightly) has no access to the client file system or other hardware.

This is different from node.js, which is a server implementation that has access to all sorts of other file system APIs.

To "break out" of the browser you must use some sort of browser extension.

like image 170
Hamish Avatar answered Nov 01 '22 07:11

Hamish


You will have to create a plugin, an applet, or a client side application to get the data into the client's web browser before being sent off to your server.

You could make a small app that reads the serial port of the clients machine that creates a .js file, and then your web page includes that src of that "dynamically" created js file on the client's machine and presto your webpage gets access to the serial port in a roundabout way.

This is how GPSGate works: http://gpsgate.com/developer/gps_in_browser/

See also here: How to read from Serial port in a webpage

And a java applet based solution: http://code.google.com/p/java-simple-serial-connector/

http://code.google.com/p/java-simple-serial-connector/wiki/jSSC_Terminal

like image 24
Matthew Lock Avatar answered Nov 01 '22 09:11

Matthew Lock