diff --git a/lib/adapters/chrome-serial.js b/lib/adapters/chrome-serial.js index e37d169..16b53d0 100644 --- a/lib/adapters/chrome-serial.js +++ b/lib/adapters/chrome-serial.js @@ -18,9 +18,19 @@ function ChromeSerialAdapter (path, options) { this._path = path; this._options = convertOptions(options); + this._paused = true; + this._connectionId = null; this.onData = null; this.onError = null; + + var self = this; + + serial.onReceive.addListener(function (info) { + if (info['connectionId'] !== self._connectionId) return; + + self.onData(new Buffer(new Uint8Array(info['data']))); + }); } function convertOptions (options) { @@ -46,6 +56,8 @@ function open (callback) { serial.connect(this._path, this._options, function (info) { self._connectionId = info['connectionId']; + serial.setPaused(self._connectionId, self._paused, function () {}); + callback(); }); } @@ -70,10 +82,18 @@ function write (data, callback) { } function pause () { + this._paused = true; + + if (!this._connectionId) return; + serial.setPaused(this._connectionId, true, function () {}); } function resume () { + this._paused = false; + + if (!this._connectionId) return; + serial.setPaused(this._connectionId, false, function () {}); }