Serial communication from JavaScript?
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.
Related videos on Youtube
Nick Heiner
JS enthusiast by day, horse mask enthusiast by night. Talks I've Done
Updated on July 09, 2022Comments
-
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 about 13 yearsI wrote a little code to send/get information to/from a modem with a GSM chip.
-
Demian Brecht about 13 yearsThis isn't actually using JS - you're using JS to invoke methods of an ActiveX component.
-
Vismari about 13 yearsIt 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 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 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 about 13 yearsObvious 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 over 11 years
-
Buzz over 6 yearsBut why we can access ordinary webcam without need 'server-side code''?
-
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 over 4 yearsI think this is Chrome OS specific, doesn't work in Chrome (browser).
-
sjaustirni about 2 yearsNow it actually is possible to use in Chrome, the browser: developer.mozilla.org/en-US/docs/Web/API/Web_Serial_API