Closed tmpvar closed 9 years ago
@JayBeavers hey, thanks for looking into this. Unfortunately this appears to be a bug somewhere in serialport where the serialport fd is somehow being mapped to stdin assuming you perform operations in the manner described above.
Could be that somewhere sp.fd
is initialized to 0 and due to the timing of opening the sp it never gets set? I'll dig around in there when I get a spare cycle or 2
btw: SIGINT
is the signal that is sent to your process when you press control-c, definitely not what I'm doing!
What happens if you don't console log?
I notice that your open callback is not handling the first err parameter. Can you handle that and log it as well? e.g.
sp.on('open', function(err) {
if (err) console.log(err);
...
@reconbot the console.log
is to demonstrate why sp.write
does not work as expected. Removing it has no effect on the sp.write
call. sp.fd == 0
is a bad thing
@JayBeavers to be a good node citizen, serialport should provide an error
event (which it does: https://github.com/voodootikigod/node-serialport/blob/master/serialport.js#L94). The event handler for open
should not pass an error (which it does not: https://github.com/voodootikigod/node-serialport/blob/master/serialport.js#L242).
I've noticed that this issue is flagged as "needsdata", can someone confirm that this is an issue on more than just my system? I'd be happy to provide more information if you cannot duplicate.
Is this still an issue? I believe we have fixed this, can you confirm @tmpvar
Still a bug, using the same test case as before:
$ echo "hello" | node serialport-229.js
SerialPort FD: 0
events.js:72
throw er; // Unhandled 'error' event
^
Error: Serialport not open.
at SerialPortFactory.SerialPort.write (/Users/tmpvar/work/js/tmp/node_modules/serialport/serialport.js:211:17)
at SerialPort.<anonymous> (/Users/tmpvar/work/js/tmp/serialport-229.js:10:8)
at SerialPort.emit (events.js:92:17)
at /Users/tmpvar/work/js/tmp/node_modules/serialport/serialport.js:203:12
$ head node_modules/serialport/package.json
{
"name": "serialport",
"version": "1.4.6",
"description": "Welcome your robotic javascript overlords. Better yet, program them!",
"author": {
"name": "Chris Williams",
"email": "voodootikigod@gmail.com",
"url": "http://www.voodootikigod.com"
},
"binary": {
That error is being emitted from the sp.write()
function call which is inside sp.on('open'...)
!
EDIT:
Oh, and there is an arduino attached running grbl
$ ls /dev/tty.usbmodem*
/dev/tty.usbmodemfd121
Can you cat serialport-22.js
On Monday, September 22, 2014, Elijah Insua notifications@github.com wrote:
That error is being emitted from the sp.write() function call which is inside sp.on('open'...)!
— Reply to this email directly or view it on GitHub https://github.com/voodootikigod/node-serialport/issues/229#issuecomment-56453852 .
Chris Williams
@voodootikigod http://twitter.com/voodootikigod | GitHub http://github.com/voodootikigod
The things I make that you should check out: SaferAging http://www.saferaging.com/ | JSConf http://jsconf.com/ | RobotsConf http://robotsconf.com/ | RobotsWeekly http://robotsweekly.com/
Help me end the negativity on the internet, share this http://jsconf.eu/2011/an_end_to_negativity.html.
exactly the same as the OP
$ cat serialport-229.js
var SerialPort = require('serialport').SerialPort;
process.stdin.on('data', function() {});
process.stdin.on('end', function() {
var sp = new SerialPort('/dev/tty.usbmodemfd121');
sp.on('open', function() {
console.log('SerialPort FD:', sp.fd);
sp.write('this will not get sent');
setTimeout(process.exit, 100);
});
});
linux or mac?
osx 10.9.4
here's a test case:
run with
echo "hello" | node stdin-fail.js
example output:
Notice that
sp.fd
is 0, which is certainly not correct. Moving the SerialPort creation outside of theprocess.stdin.on('end', ...)
callback results insp.fd
being equal to 11 on my system.EDIT:
I should note that I've tried various versions of node-serialport (1.1.3, 1.2.2, git, etc..) on node v0.10.18