jamesnesfield / node-waterrower

a node server for communicating with the WaterRower S4/S5 USB performance monitor
44 stars 18 forks source link

'this' is undefined #6

Closed steveharan closed 8 years ago

steveharan commented 8 years ago

Hi, line 261 of index.js - I get an error 'Cannot read property 'wr5' of undefined'

else if (type == "wr5") { response.device = 'waterrower'; response.connected = true; if (message.length >= 6){ if (this.wr5.hasOwnProperty(message.substring(0, 6))) {

full debug:

HA501698:node-waterrower sharan$ node test.js

undefined attempting to open port Number of ports=2 com name /dev/cu.Bluetooth-Incoming-Port port ID com name /dev/cu.usbmodem1421 port ID in readWrite open call read in read connecting to /dev/cu.usbmodem1421 in read open <

in read>SS< in read>SE< in read>P04< in read>P03< in read>P03< in read>P03< in read>P04< in read>P05< in read>P05< in read>P05< in read>P05< in read>P05< in read>P04< in read>P05< in read>P04< in read>P04< in read>P04< in read>P04< Stroke Rate ....................0 Total Speed ....................0 Average Speed ..................0 Distance... ....................0 Heart Rate .....................0 in read>P05< in read>P04< in read>P04< in read>P04< in read>P04< in read>P03< in read>P05< in read>P04< in read>P05< in read>P05< in read>P06< in read>P06< in read>P06< in read>SS< in read>P07< in read>P06< in read>P07<

USB in read>P06< in read>WR< <WR WR in read>P06< in read>P06< in read>P06< in read>P06< in read>P06< in read>P06< in read>P06< in read>P06< in read>P06< in read>P06< in read>SE< in read>P06< in read>P05< in read>P05< in read>P05< in read>P04< in read>P05< in read>P04< in read>P05< in read>P05< in read>P06< in read>P05< in read>P05< in read>P05< in read>P05< in read>P05< in read>P05< in read>P05< in read>P05< in read>P04< in read>P05< in read>P05< IRD140 in read>P04< in read>IDD1400044< <IDD1400044 IDD1400044 IDD1400044 /Users/sharan/node_modules/node-waterrower/Waterrower/index.js:262 if (this.wr5.hasOwnProperty(message.substring(0, 6))) { ^ TypeError: Cannot read property 'wr5' of undefined at readMessage (/Users/sharan/node_modules/node-waterrower/Waterrower/index.js:262:11) at /Users/sharan/node_modules/node-waterrower/Waterrower/index.js:103:17 at SerialPort. (/Users/sharan/node_modules/node-waterrower/Waterrower/index.js:169:3) at SerialPort.emit (events.js:107:17) at /Users/sharan/node_modules/node-waterrower/node_modules/serialport/parsers.js:25:17 at Array.forEach (native) at Object.parser (/Users/sharan/node_modules/node-waterrower/node_modules/serialport/parsers.js:24:13) at Object.SerialPort.opts.dataCallback (/Users/sharan/node_modules/node-waterrower/node_modules/serialport/serialport.js:181:12) at SerialPortFactory.SerialPort._emitData (/Users/sharan/node_modules/node-waterrower/node_modules/serialport/serialport.js:396:20) at afterRead (/Users/sharan/node_modules/node-waterrower/node_modules/serialport/serialport.js:372:20)

Really hope you can help! Nearly working I think. Thanks

steveharan commented 8 years ago

Just found the updated code - thanks