Loghorn / ant-plus

A node module for ANT+
MIT License
138 stars 67 forks source link

TypeError: Cannot read property 'assignChannel' of undefined #15

Closed sam2b closed 6 years ago

sam2b commented 6 years ago

Bug in ant-plus.js that is missing this line in the module.exports = { } block: Messages: Ant.Messages,

After I added that line to the other exports, the error disappeared and the stick initialized fine.

pi@raspberrypi:~/ant-cycling-power $ sudo node test.js
/home/pi/ant-cycling-power/power-meter.js:15
    stick.write(Ant.Messages.assignChannel(channel, 'transmit'));
                             ^

**TypeError: Cannot read property 'assignChannel' of undefined**
    at GarminStick2.<anonymous> (/home/pi/ant-cycling-power/power-meter.js:15:30)
    at emitOne (events.js:116:13)
    at GarminStick2.emit (events.js:211:7)
    at GarminStick2.USBDriver.read (/home/pi/.nvm/versions/node/v8.11.1/lib/node_modules/ant-plus/build/ant.js:527:18)
    at InEndpoint.<anonymous> (/home/pi/.nvm/versions/node/v8.11.1/lib/node_modules/ant-plus/build/ant.js:374:23)
    at emitOne (events.js:116:13)
    at InEndpoint.emit (events.js:211:7)
    at Transfer.transferDone (/home/pi/.nvm/versions/node/v8.11.1/lib/node_modules/ant-plus/node_modules/usb/usb.js:328:9)
Loghorn commented 6 years ago

Can you please provide the code to reproduce the issue? Thank you

sam2b commented 6 years ago

Sure, see file here: https://github.com/olympum/ant-cycling-power/blob/master/power-meter.js stick.on('startup', function () { console.log('startup'); console.log('Max channels:', stick.maxChannels); var deviceId = 0xBEEF; stick.write(Ant.Messages.assignChannel(channel, 'transmit')); stick.write(Ant.Messages.setDevice(channel, deviceId, 11, 1)); stick.write(Ant.Messages.setFrequency(channel, 57)); stick.write(Ant.Messages.setPeriod(channel, 8182)); stick.write(Ant.Messages.openChannel(channel)); console.log('cycling power meter initialized'); }); ...

Loghorn commented 6 years ago

I'm sorry but this project is a ANT+ client, used for receiving data from ANT+ devices (bikes, HR sensors, etc.), while the project you link is for simulating an ANT+ bike. This projects was never meant to be used like that, so I'm not surprised it doesn't work. I believe that simulating a device could be useful but must be a separate project: feel free to start it and take this project as a base if you find it useful.

sam2b commented 6 years ago

Regardless of the project, is it improper to write Ant.Messages.* to the stick? If not, what & where is your intended use of Ant.Messages, because the missing export was the source of my issues. Please advise.

Loghorn commented 6 years ago

Ant.Messages is meant to be used only by the library internal functions (and this is the reason it's not exported)