Skip to content

Commit

Permalink
bump to version 0.3 && add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
reyiyo committed Nov 6, 2016
1 parent 394271c commit a4d2aca
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
14 changes: 6 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ VirtualSerialPort.prototype.open = function open(callback) {
this.emit('open');
}.bind(this));
if(callback) {
callback();
return callback();
}
};

Expand All @@ -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();
}
};

Expand All @@ -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();
}
};

Expand All @@ -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
Expand All @@ -87,6 +87,4 @@ catch(error) {
console.warn('VirtualSerialPort - NO parsers available');
}



module.exports = VirtualSerialPort;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit a4d2aca

Please sign in to comment.