Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node-serialport write/read loop has 500ms delay in NodeWebkit on OS X #2009

Closed
davidbenhaim opened this issue Jun 25, 2014 · 4 comments
Closed

Comments

@davidbenhaim
Copy link

I'm pretty sure this directly relates to #82. But really I have no idea.

Tried this out in versions 0.7.1 and 0.9.2 on OS X 10.9.2

Basically I'm writing an application that writes to some lab equipment over a serial port connection using node-serialport.

The application writes to the lab equipment, the lab equipment acks, then the application sends its next ack. The lab equipment can buffer a series of commands so it will ack a whole bunch in a row until its buffer is full, and then ack as it needs to to fill its buffer.

Basically the troubled code looks like this

serialport = require("serialport");
var default_settings = {baudrate: 115200, parser: serialport.parsers.readline("\n")};

var  message_queue = ["message1", "message2"....]; //long list of messages

port = new serialport.SerialPort("/dev/tty###", default_settings, false);
port.open();
port.on('data', function(data){ 
    write_next_message(data);
})

function write_next_message(data){
   var message = message_queue.pop();
   port.write(message + '\r', function(err, results){
           //I'm actually doing something in here with err/results
   });
}

Basically when I run this it will buffer 3 or 4 commands very quickly (3-5ms) and then hang for 500ms and then repeat. This causes the lab equipment to stutter (not good).

I have a script which does the same thing (sans a ui) written in python which works fine. So I know its not the equipment

First, I had this wrapped up in an angularjs service so I figured it might have something to do with the angular digest loop. So I ripped it out and then ran it as script in the window context. Same thing. I played around with this for awhile because I thought it had something to do with the node context and the window context mixing and things failing silently. This had a really strange result. Out of 10 runs of the same code the program would stutter 9 times and work once. No idea why or how that made sense. Took out all my logging, put it back in, put timing code in, tried virtual serial ports that immediately acked back. Couldn't figure out what was going on. I couldn't consistently get it to work. I tried sticking a bunch of port.drains() in and waiting until the port 'drained' until I wrote the next line. No dice.

Then I tried moving it all into a node module and requiring that in the main html document. Same deal.

Next I tried running the script outside of node-webkit just as a node script. Success.

Then I tried moving it to the node-main script. Which actually never ran because I had to compile it (node-pre-gyp rebuild --target=0.10.12 --runtime=node --target-arch=ia32) to run in the node context which then merged with the window context which broke it. Was getting some kind of dyld: lazy symbol binding failed: Symbol not found error.

Finally, I found #82 and figured I might try it out on my linux box where the original code worked no problems.

Thoughts?

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@davidbenhaim
Copy link
Author

#82 (comment)

@ericevenchick
Copy link

I'm having the same issue. Occasional 500 ms delays when reading. It works perfectly for the first few reads, then hangs.

@davidbenhaim did you ever find a solution for this? I'll try on a platform other than OS X.

@rogerwang
Copy link
Member

I didn't verify this, but it should have been fixed in 0.13.0 beta versions. Please re-open this issue if not.

@rogerwang
Copy link
Member

btw, native modules built by node-gyp/npm is now supported : https://groups.google.com/d/msg/nwjs-general/UqEq8ito2gI/W-ld9LSoDQAJ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants