TypeError: Cannot set property 'fd' of undefined #289

Closed
jdevelvis opened this Issue Jan 5, 2014 · 6 comments

Comments

Projects
None yet
4 participants

I'm trying to build an IRToy node module using serialport, and when I try to open a connection to /dev/ttyACM0, I get this error:

/home/.../node_modules/serialport/serialport.js:184
this.fd = null;
^
TypeError: Cannot set property 'fd' of undefined
at SerialPort (/home/pi/nodeIRToy/node_modules/serialport/serialport.js:184:15)
at IRToy.flashLED (/home/pi/nodeIRToy/nodeIRToy.js:71:12)
at Object. (/home/pi/nodeIRToy/index.js:4:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3

Here's the code that leads to that error:

    var sp1 = SerialPort(this.devicePath, {
      baudrate: 9600,
      databits: 8,
      stopbits: 1,
      parity: 'none'
    });

And I verified that this.devicePath is set to /dev/ttyACM0

Contributor

programmarchy commented Jan 5, 2014

Try adding

sp1.on('error', function(e) { console.error(e) });

to see what error might occur?

Same thing, it's happening when I set the sp1 variable, so I can't get anything out of the on error event until after the variable is defined. (I even tried it, just to make sure)

Also, it looks like it isn't happening on open, it's happening when I define the variable. I thought it was having an issue opening the connection, so I set the openImmediately parameter to false, and still get the same error on that line

Collaborator

JayBeavers commented Jan 17, 2014

Can you post a full example including the require(...) statement?

The example on the home page looks like:

var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("/dev/tty-usbserial1", {
  baudrate: 57600
});

and you're missing the new statement. When you don't use the new statement, the 'this' variable gets defined differently. I'm betting 'this is not what you think it is'.

Some javascript ctors have a protection against them being called without 'new'. Looks like we're missing this protection.

Collaborator

reconbot commented Jan 24, 2014

Also, unless you pass a flag not to auto open the port the sp1.on('error'.... wont work, you need to pass it as a callback.

Collaborator

reconbot commented Jun 11, 2014

@jdevelvis I'm going to close this for now, let us know if you're still having this issue and we'll do our best to help!

@reconbot reconbot closed this Jun 11, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment