Typeerror: Object [Object Object] has no method 'Listen'

Asked

Viewed 76 times

1

const DEFAULT_SERIAL_PORT = "/dev/ttyUSB0";

// Dependancies
var fs = require('fs');
var vm = require('vm');
var events = require('events');
var cache = require('./plugins_cache.js');
var util = require('util');
var enocean = require('node-enocean')();


// Type de données
var enoceanRecords = {
    PTEC: { 'value': '', 'type': 'TEXT', 'unit': '' },
    IINST: { 'value': '', 'type': 'INTEGER', 'unit': 'A' }
};
// Includes
vm.runInThisContext(fs.readFileSync(__dirname + "/" + "plugins_table.js"));
var table = new Table();

// Class
var PluginEnocean = function () {
    this.infos = { name: "enocean",
		 version: "0.0.1"
		 };
};

PluginEnocean.prototype.query = function () {
    return this.infos;
}

PluginEnocean.prototype.init = function (config) {
	 var options = config.get('plugin:enocean');
    var path = DEFAULT_SERIAL_PORT;

    if(options !== undefined) {
        if(options['path'] !== undefined) {
            path = options['path'];
        }
    }

    // Open serial port
    console.log(path);
    enocean.listen(path);
	
	// Set table name
    table.setName(this.infos['name']);
	
	 // Collect data
    enocean.on('data', function (data) {
		
			var uuid = data['senderId'] ;
				
			for(key in enoceanRecords) {
					
			table.setRecord(key, enoceanRecords[key]);
			}
				
				
				
				
	// Feed data
			if(uuid !== undefined) { 
				table.setUuid(uuid);
				table.setStamp();
				cache.push(table);
			}
				});
		
	
};

PluginEnocean.prototype.run = function () {
};

PluginEnocean.prototype.exit = function () {
};

var enocean = module.exports = new PluginEnocean();

TypeError: Object [object Object] has no method 'listen' Does anyone have any idea what this is about exactly? I cannot understand the reason for this mistake...

THANK YOU.

  • Can you post a bit of the code? I think it has to do with the line you’re doing Switch to a certain door. But without it I can’t come to a conclusion

  • Good morning Miguel, I just updated the post, and thank you for HELP !

  • 1

    I think it has to do with "/dev/ttyUSB0" . I have never used this package, but from what I understand enocean has no such method listen available, at least when trying to use it

  • You are rewriting the variable (!)... var enocean = module.exports = new PluginEnocean(); and so var enocean = require('node-enocean')(); is erased.

  • Thank you for your comments, I really am grateful...! But I usually read the serial port "/dev/ttyUSB0", and when I do the test everything works perfectly ! The error only occurs when I launch the main script "main.js", when I simply throw the " plugin_enocean.js" everything goes well !

  • @Did you see my comment? you’re deleting the require('node-enocean')();...

  • THANK YOU SO MUCH! Finally it worked... I thank you again ! I was rewriting the variable "enocean" as WELL said SERGIO !

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.