Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ To Use
Opening a serial port:

```js
var SerialPort = require("browser-serialport").SerialPort
var SerialPort = require("browser-serialport");
var serialPort = new SerialPort("/dev/tty-usbserial1", {
baudrate: 57600
});
Expand Down Expand Up @@ -84,13 +84,14 @@ serialPort.on("open", function () {
});
```

You can also call the open function, in this case instanciate the serialport with an additional flag.
You can also call the open function, in this case instantiate the serialport with an additional `autoOpen` property set to `false`.

```js
var SerialPort = require("browser-serialport").SerialPort
var serialPort = new SerialPort("/dev/tty-usbserial1", {
baudrate: 57600
}, false); // this is the openImmediately flag [default is true]
baudrate: 57600,
autoOpen: false
});

serialPort.open(function (error) {
if ( error ) {
Expand Down
21 changes: 12 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function convertOptions(options){
return options;
}

function SerialPort(path, options, openImmediately, callback) {
function SerialPort(path, options, callback) {

EE.call(this);

Expand All @@ -59,7 +59,7 @@ function SerialPort(path, options, openImmediately, callback) {

options = (typeof options !== 'function') && options || {};

openImmediately = (openImmediately === undefined || openImmediately === null) ? true : openImmediately;
var autoOpen = (options.autoOpen === undefined || options.autoOpen === null) ? true : options.autoOpen;

callback = callback || function (err) {
if (err) {
Expand Down Expand Up @@ -166,7 +166,7 @@ function SerialPort(path, options, openImmediately, callback) {

this.path = path;

if (openImmediately) {
if (autoOpen) {
process.nextTick(function () {
self.open(callback);
});
Expand Down Expand Up @@ -360,6 +360,10 @@ SerialPort.prototype.set = function (options, callback) {
});
};

SerialPort.prototype.isOpen = function () {
return this.connectionId > -1;
};

function SerialPortList(callback) {
if (typeof chrome != 'undefined' && chrome.serial) {
chrome.serial.getDevices(function(ports) {
Expand Down Expand Up @@ -411,9 +415,8 @@ function toBuffer(ab) {
return buffer;
}

module.exports = {
SerialPort: SerialPort,
list: SerialPortList,
buffer2ArrayBuffer: buffer2ArrayBuffer,
used: [] //TODO: Populate this somewhere.
};
SerialPort.buffer2ArrayBuffer = buffer2ArrayBuffer;
SerialPort.list = SerialPortList;
SerialPort.used = [];

module.exports = SerialPort;
2 changes: 1 addition & 1 deletion test/serialport-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var without = require('lodash/array/without');
var expect = chai.expect;

var MockedSerialPort = require('../');
var SerialPort = MockedSerialPort.SerialPort;
var SerialPort = MockedSerialPort;

var options;

Expand Down