diff --git a/README.md b/README.md index 03ac252..304f600 100644 --- a/README.md +++ b/README.md @@ -72,10 +72,34 @@ sp.write("BLOOP!"); // "Arduino says, BLOOP!" ### node-serialport methods/events: -#### sp.write(data) +#### sp.open(callback) +Simulates the port opening. It returns the callback execution and emits the `open` event on +`process.nextTick()` + +Writes data to the virtual device. Equivalent to `sp.emit("dataToDevice", data)`. +#### sp.write(data) Writes data to the virtual device. Equivalent to `sp.emit("dataToDevice", data)`. +#### sp.isOpen() +Returns boolean indicating wether the port is open or not. It returns the value of `sp.open` which +you may set manually. + +#### sp.pause() +This method is for API compatibility. It actually does nothing here. + +#### sp.resume() +This method is for API compatibility. It actually does nothing here. + +#### sp.flush(callback) +This method is for API compatibility. It actually does nothing and returns the callback call. + +#### sp.drain(callback) +This method is for API compatibility. It actually does nothing and returns the callback call. + +#### sp.close(callback) +This method is for API compatibility. It actually does nothing and returns the callback call. + #### sp.on("open", function(err) { ... } ) Runs function once `SerialPort` is ready, as you would with an actual `SerialPort` instance. @@ -93,6 +117,13 @@ Writes data to computer. Equivalent to `sp.emit("data", data)` #### sp.on("dataToDevice", function(data) { ... }) Act on data sent to the device. +## Parsers + +`node-serialport` is listed as an optional dependency. If some version of `node-serialport` is +installed, `virtual-serialport` will load it's parsers. + +For more information about parsers, please refer to the specific version of `node-serialport` docs. + ## TODO - move to automated testing (assertions and more) - better match voodootikigod's node-serialport api diff --git a/index.js b/index.js index c5debfb..5edd565 100644 --- a/index.js +++ b/index.js @@ -25,7 +25,7 @@ VirtualSerialPort.prototype.open = function open(callback) { this.emit('open'); }.bind(this)); if(callback) { - callback(); + return callback(); } }; @@ -38,7 +38,7 @@ VirtualSerialPort.prototype.write = function write(buffer, callback) { // This callback should receive both an error and result, however result is // undocumented so I do not know what it should contain if(callback) { - callback(); + return callback(); } }; @@ -50,20 +50,20 @@ VirtualSerialPort.prototype.resume = function resume() { VirtualSerialPort.prototype.flush = function flush(callback) { if(callback) { - callback(); + return callback(); } }; VirtualSerialPort.prototype.drain = function drain(callback) { if(callback) { - callback(); + return callback(); } }; VirtualSerialPort.prototype.close = function close(callback) { this.removeAllListeners(); if(callback) { - callback(); + return callback(); } }; @@ -74,7 +74,7 @@ VirtualSerialPort.prototype.isOpen = function isOpen() { try { var SerialPort = require('serialport'); if (SerialPort.SerialPort) { - // for v2.x serialport API + // for v2.x serialport API VirtualSerialPort = { SerialPort: VirtualSerialPort, parsers: SerialPort.parsers @@ -87,6 +87,4 @@ catch(error) { console.warn('VirtualSerialPort - NO parsers available'); } - - module.exports = VirtualSerialPort; diff --git a/package.json b/package.json index c45a8ee..f716473 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "virtual-serialport", - "version": "0.2.1", + "version": "0.3.0", "description": "A drop-in virtual replacement for node-serialport's SerialPort object", "main": "index.js", "directories": {