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

14,173

Solution 1

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.

Solution 2

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

Solution 3

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

Share:
14,173
ipohfly
Author by

ipohfly

a developer

Updated on June 29, 2022

Comments

  • ipohfly
    ipohfly almost 2 years

    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! =)

    • zerkms
      zerkms almost 12 years
      There is no way to interact with devices from browser's sandbox. The only possible way is to install a browsers' plugin, that will be an intermediate layer
    • Luca Rainone
      Luca Rainone almost 12 years
      it's not an answer but… take a look to serproxy (lspace.nildram.co.uk/freeware.html). Maybe it can be a piece of your puzzle :)
    • Admin
      Admin over 9 years
  • ipohfly
    ipohfly almost 12 years
    the reason why ActiveX and Java being ruled out is because there are implication in having a 'middle tier' of programming running in the client machine.
  • Rachael
    Rachael over 9 years
    what if the client's machine is on the same network as the server? Is there a way to pull data off of it using node.js and net? node.js net module,