{"action":"created","issue":{"url":"https://api.github.com/repos/eelcocramer/node-bluetooth-serial-port/issues/93","repository_url":"https://api.github.com/repos/eelcocramer/node-bluetooth-serial-port","labels_url":"https://api.github.com/repos/eelcocramer/node-bluetooth-serial-port/issues/93/labels{/name}","comments_url":"https://api.github.com/repos/eelcocramer/node-bluetooth-serial-port/issues/93/comments","events_url":"https://api.github.com/repos/eelcocramer/node-bluetooth-serial-port/issues/93/events","html_url":"https://github.com/eelcocramer/node-bluetooth-serial-port/issues/93","id":137071803,"number":93,"title":"Putting code inside of a module fails to find serial port","user":{"login":"MrZunz","id":545963,"avatar_url":"https://avatars.githubusercontent.com/u/545963?v=3","gravatar_id":"","url":"https://api.github.com/users/MrZunz","html_url":"https://github.com/MrZunz","followers_url":"https://api.github.com/users/MrZunz/followers","following_url":"https://api.github.com/users/MrZunz/following{/other_user}","gists_url":"https://api.github.com/users/MrZunz/gists{/gist_id}","starred_url":"https://api.github.com/users/MrZunz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MrZunz/subscriptions","organizations_url":"https://api.github.com/users/MrZunz/orgs","repos_url":"https://api.github.com/users/MrZunz/repos","events_url":"https://api.github.com/users/MrZunz/events{/privacy}","received_events_url":"https://api.github.com/users/MrZunz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-28T16:59:14Z","updated_at":"2016-02-28T19:55:49Z","closed_at":null,"body":"Working code:\r\n\r\n```\r\n// var obd = require('obd');\r\n// obd.connect();\r\n\r\nvar BluetoothSerialPort = require(\"bluetooth-serial-port\").BluetoothSerialPort;\r\nvar myBtPort = new BluetoothSerialPort();\r\nvar dataBuffer = \"\";\r\n\r\nmyBtPort.on('found', function (address, name) {\r\n    console.log('Found: ' + address + ' with name ' + name);\r\n\r\n    if(name != \"ubuntu-0\" && name != \"OBDII\") { return; }\r\n\r\n    myBtPort.findSerialPortChannel(address, function(channel) {\r\n        console.log('Found RFCOMM channel for serial port on ' + name + ': ' + channel);\r\n        console.log('Attempting to connect...');\r\n\r\n        myBtPort.connect(address, channel, function() {\r\n            console.log('Connected. Receiving data...');\r\n            myBtPort.on('data', function(buffer) {\r\n\r\n            });\r\n        });\r\n    });\r\n});\r\n\r\nmyBtPort.on('finished', function() {\r\n    console.log('scan did finish');\r\n});\r\n\r\nmyBtPort.inquire();\r\n```\r\n\r\nThis does work every time I run it, it'll find the serial port and connect just fine. However, when I put the exact same code inside of a module it doesn't. It wont find the serial port...\r\n\r\n```\r\nfunction OBD() {\r\n\tconsole.log(\"OBD:\", 'Initializing...');\r\n}\r\n\r\nOBD.prototype.connect = function() {\r\n\r\n\tvar BluetoothSerialPort = require(\"bluetooth-serial-port\").BluetoothSerialPort;\r\n\tvar myBtPort = new BluetoothSerialPort();\r\n\tvar dataBuffer = \"\";\r\n\r\n\tmyBtPort.on('found', function (address, name) {\r\n\t    console.log('Found: ' + address + ' with name ' + name);\r\n\r\n\t    if(name != \"ubuntu-0\" && name != \"OBDII\") { return; }\r\n\r\n\t    myBtPort.findSerialPortChannel(address, function(channel) {\r\n\t        console.log('Found RFCOMM channel for serial port on ' + name + ': ' + channel);\r\n\t        console.log('Attempting to connect...');\r\n\r\n\t        myBtPort.connect(address, channel, function() {\r\n\t            console.log('Connected. Receiving data...');\r\n\t            myBtPort.on('data', function(buffer) {\r\n\r\n\t            });\r\n\t        });\r\n\t    });\r\n\t});\r\n\r\n\tmyBtPort.on('finished', function() {\r\n\t    console.log('scan did finish');\r\n\t});\r\n\r\n\tmyBtPort.inquire();\r\n}\r\n\r\nmodule.exports = exports = new OBD();\r\n```\r\nAnyone has any clue why it is behaving like this? This does not seem logical but I just can't get it to work with a module..."},"comment":{"url":"https://api.github.com/repos/eelcocramer/node-bluetooth-serial-port/issues/comments/189934700","html_url":"https://github.com/eelcocramer/node-bluetooth-serial-port/issues/93#issuecomment-189934700","issue_url":"https://api.github.com/repos/eelcocramer/node-bluetooth-serial-port/issues/93","id":189934700,"user":{"login":"eelcocramer","id":795579,"avatar_url":"https://avatars.githubusercontent.com/u/795579?v=3","gravatar_id":"","url":"https://api.github.com/users/eelcocramer","html_url":"https://github.com/eelcocramer","followers_url":"https://api.github.com/users/eelcocramer/followers","following_url":"https://api.github.com/users/eelcocramer/following{/other_user}","gists_url":"https://api.github.com/users/eelcocramer/gists{/gist_id}","starred_url":"https://api.github.com/users/eelcocramer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eelcocramer/subscriptions","organizations_url":"https://api.github.com/users/eelcocramer/orgs","repos_url":"https://api.github.com/users/eelcocramer/repos","events_url":"https://api.github.com/users/eelcocramer/events{/privacy}","received_events_url":"https://api.github.com/users/eelcocramer/received_events","type":"User","site_admin":false},"created_at":"2016-02-28T19:55:49Z","updated_at":"2016-02-28T19:55:49Z","body":"What is the console output for the 2nd code piece? I get:\r\n\r\n```\r\nOBD: Initializing...\r\nscan did finish\r\n```\r\n\r\nfor this program:\r\n\r\n```javascript\r\nvar odb = require('./odb.js');\r\nodb.connect();\r\n```\r\n\r\nBut I do not have a test device that I can connect to right now."}}