Serial communication from JavaScript?

63,533

Solution 1

JavaScript itself doesn't have any built in functionality to allow you to access the serial port. However, various JavaScript engines (v8, rhino, etc) allow you to write your own custom native objects.

You might want to check out node.js, which is a JavaScript library for v8 that's focused on writing server-side code (rather than web browser client code). It seems that someone's already written a serialport package for that:

https://github.com/voodootikigod/node-serialport

Solution 2

This is an old question, but in case this helps anyone else, Chrome Apps have access to a serial API - http://developer.chrome.com/apps/serial.html - which might help.

It's Chrome specific (obviously..), but Chrome is available cross-platform so might answer the question.

Solution 3

There's a cross platform plugin for serial port communication called jUART.

Share:
63,533

Related videos on Youtube

Nick Heiner
Author by

Nick Heiner

JS enthusiast by day, horse mask enthusiast by night. Talks I've Done

Updated on July 09, 2022

Comments

  • Nick Heiner
    Nick Heiner almost 2 years

    Is it possible to communicate over a machine's serial port through JavaScript?

    I have to write a short program that sends data to a microcontroller over the serial port that has a GUI and is cross-platform compatible, and I really don't want to use Java's Swing.

  • Vismari
    Vismari about 13 years
    I wrote a little code to send/get information to/from a modem with a GSM chip.
  • Demian Brecht
    Demian Brecht about 13 years
    This isn't actually using JS - you're using JS to invoke methods of an ActiveX component.
  • Vismari
    Vismari about 13 years
    It works fine. JavaScript makes an interface between browser and COM(on Internet Explorer). I wrote a code to get ICCID of a GSM chip through an website.
  • Justin808
    Justin808 about 13 years
    "cross-platform compatible" that excludes the possibility of using ActiveX. Also, ActiveX is not javascript and it not adding a javascript object to access the serial port.
  • Demian Brecht
    Demian Brecht about 13 years
    @Vismari That's not the point. The question was whether or not it's possible through JS, which it isn't natively.
  • Vismari
    Vismari about 13 years
    Obvious natively it's impossible. But if you need make a communication to serial port's in a client/server enviroment you can use ActiveX + JavaScript(IE) to do this.
  • JKirchartz
    JKirchartz over 11 years
    There are a couple libraries available that do this: free rxtx, and paid serialio.
  • Buzz
    Buzz over 6 years
    But why we can access ordinary webcam without need 'server-side code''?
  • jacobq
    jacobq almost 5 years
    @Buzz probably because of the APIs provided by modern web browsers, e.g. WebUSB and Media Capture and Streams. See whatwebcando.today for some neat examples. These are not features of the programming language (JavaScript) itself but rather the environment in which it executes.
  • Zyo
    Zyo over 4 years
    I think this is Chrome OS specific, doesn't work in Chrome (browser).
  • sjaustirni
    sjaustirni about 2 years
    Now it actually is possible to use in Chrome, the browser: developer.mozilla.org/en-US/docs/Web/API/Web_Serial_API

Related