From 329ebe8d35fa9f3add93a319e6b8d25f94f4ebd5 Mon Sep 17 00:00:00 2001 From: roccomuso Date: Sun, 8 Jan 2017 00:10:08 +0100 Subject: [PATCH] replaced bug-fixed custom virtual-serialport with the original dependency, now up to date --- components/platform.js | 2 +- components/virtual-serialport.js | 96 -------------------------------- package.json | 3 +- 3 files changed, 3 insertions(+), 98 deletions(-) delete mode 100644 components/virtual-serialport.js diff --git a/components/platform.js b/components/platform.js index ec838fb..0089a2d 100644 --- a/components/platform.js +++ b/components/platform.js @@ -22,7 +22,7 @@ var rf433mhz = function(board){ type = (board.platform == 'rpi' && !config.platforms.rpi['use-external-arduino']) ? 'rpi' : 'arduino'; if (type === 'arduino'){ - var SerialPort = (process.env.NODE_ENV === 'development') ? require('./virtual-serialport'): require('serialport'); + var SerialPort = (process.env.NODE_ENV === 'development') ? require('virtual-serialport'): require('serialport'); serial = new SerialPort(board.port, { parser: SerialPort.parsers.readline('\n'), baudRate: config.arduino_baudrate, diff --git a/components/virtual-serialport.js b/components/virtual-serialport.js deleted file mode 100644 index 1203f28..0000000 --- a/components/virtual-serialport.js +++ /dev/null @@ -1,96 +0,0 @@ -var events = require('events'); -var util = require('util'); - -var VirtualSerialPort = function(path, options, openImmediately, callback) { - events.EventEmitter.call(this); - - var self = this; - - this.writeToComputer = function(data) { - self.emit("data", data); - }; - - if(openImmediately || openImmediately === undefined || openImmediately === null) { - process.nextTick(function() { - self.open(callback); - }); - } -}; - -util.inherits(VirtualSerialPort, events.EventEmitter); - -VirtualSerialPort.prototype.open = function open(callback) { - this.opened = true; - process.nextTick(function() { - this.emit('open'); - }.bind(this)); - if(callback) { - return callback(); - } -}; - -VirtualSerialPort.prototype.write = function write(buffer, callback) { - if(this.opened) { - process.nextTick(function() { - this.emit("dataToDevice", buffer); - }.bind(this)); - } - // This callback should receive both an error and result, however result is - // undocumented so I do not know what it should contain - if(callback) { - return callback(); - } -}; - -VirtualSerialPort.prototype.pause = function pause() {}; - -VirtualSerialPort.prototype.resume = function resume() {}; - -VirtualSerialPort.prototype.flush = function flush(callback) { - if(callback) { - return callback(); - } -}; - -VirtualSerialPort.prototype.drain = function drain(callback) { - if(callback) { - return callback(); - } -}; - -VirtualSerialPort.prototype.close = function close(callback) { - this.opened = false; - this.removeAllListeners(); - if(callback) { - return callback(); - } -}; - -VirtualSerialPort.prototype.isOpen = function isOpen() { - return this.opened ? true : false; -}; - -function VirtualSerialPortFactory() { - try { - var SerialPort = require('serialport'); - var serialportPackage = require('serialport/package.json'); - var semver = require('semver'); - - // for v2.x serialport API - if(semver.satisfies(serialportPackage.version, '<3.X')) { - this.SerialPort = VirtualSerialPort; - this.parsers = SerialPort.parsers; - console.log('attached to the instance'); - return this; - } - - VirtualSerialPort.parsers = SerialPort.parsers; - return VirtualSerialPort; - } catch (error) { - console.warn('VirtualSerialPort - NO parsers available'); - } - - return VirtualSerialPort; -} - -module.exports = new VirtualSerialPortFactory(); diff --git a/package.json b/package.json index b0728e7..b96a00b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "iot-433mhz", - "version": "1.0.34", + "version": "1.0.35", "description": "Node server to handle 433mhz outlets and sensors.", "main": "index.js", "preferGlobal": true, @@ -52,6 +52,7 @@ "serialport": "4.0.6", "socket.io": "1.7.1", "validator": "4.5.0", + "virtual-serialport": "^0.3.3", "yargs": "4.8.1" }, "devDependencies": {