Robots in the browser. Just like node-serialport but for browser/chrome apps.
Robots in the browser. Just like node-serialport but for browser apps.
Nodebots are awesome but HTML5 apps have access to a lot of APIs that make sense for robotics like the GamepadAPI, WebRTC Video and Data, Web Speech API, etc. Also you get a nice GUI and its easier to run. I have also made a fork of Johnny-Five to work with Browserify as well by modifying it's dependancy Firmata to use browser-serialport.
You will not be able to add this to your normal website.
If you want help making your first Chrome App, read the "Create Your First App" tutorial.
There is currently no Firefox extension support but that might come soon if possible.
npm install browser-serialport
Opening a serial port:
var SerialPort = require"browser-serialport"SerialPortvar serialPort = "/dev/tty-usbserial1"baudrate: 57600;
When opening a serial port, you can specify (in this order).
The options object allows you to pass named options to the serial port during initialization. The valid attributes for the options object are the following:
Note, we have added support for either all lowercase OR camelcase of the options (thanks @jagautier), use whichever style you prefer.
You MUST wait for the open event to be emitted before reading/writing to the serial port. The open happens asynchronously so installing 'data' listeners and writing before the open event might result in... nothing at all.
Assuming you are connected to a serial console, you would for example:
serialPorton"open"console.log'open';serialPorton'data'console.log'data received: ' + data;;serialPortwrite"ls\n"console.log'err ' + err;console.log'results ' + results;;;
You can also call the open function, in this case instanciate the serialport with an additional flag.
var SerialPort = require"browser-serialport"SerialPortvar serialPort = "/dev/tty-usbserial1"baudrate: 57600false; // this is the openImmediately flag [default is true]serialPortopenif errorconsole.log'failed to open: '+error;elseconsole.log'open';serialPorton'data'console.log'data received: ' + data;;serialPortwrite"ls\n"console.log'err ' + err;console.log'results ' + results;;;
You can also list the ports along with some metadata as well.
var serialPort = require"browser-serialport";serialPortlistportsforEachconsole.logportcomName;console.logportpnpId;console.logportmanufacturer;;;
Browser-serialport doesn't as of 2.0.0 support parsers.
You can get updates of new data from the Serial Port as follows:
You can write to the serial port by sending a string or buffer to the write method as follows:
serialPortwrite"OMG IT WORKS\r";
Enjoy and do cool things with this code.