dart-archive / sdk

The Dartino project was an experiment seeking to improve productivity when writing application code for embedded devices.
https://dartino.org
Other
330 stars 36 forks source link

Debugging via serial port fails on a mac #504

Closed mit-mit closed 8 years ago

mit-mit commented 8 years ago

When attaching, it just hangs trying to connect.

sgjesse commented 8 years ago

This is must likely caused by the serial port configuration not being correct. Right now we just use dart:ioto open the device (e.g. /dev/ttyACM0), and dart:io does not give any control over the serial port settings.

Right now the device is configured for 115200,8,n,1

And on Linux this matches the default:

$ stty -F /dev/ttyACM0 
speed 115200 baud; line = 0;
kill = ^H; eof = ^A; min = 1; time = 0;
-icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
sgjesse commented 8 years ago

But on Mac the default is:

$ stty -f /dev/tty.usbmodem1413 
speed 9600 baud;
lflags: -icanon -isig -iexten -echo
iflags: -icrnl -ixon -ixany -imaxbel -brkint
oflags: -opost -onlcr -oxtabs
cflags: cs8 -parenb crtscts

We probably need a native extension to handle this correctly.

sigurdm commented 8 years ago

This page (http://www.clearchain.com/blog/posts/using-serial-devices-in-freebsd-how-to-set-a-terminal-baud-rate) explains the problem somewhat. It seems that on BSD (and therefore probably also on macOS) changes to the tty settings are reset when the program setting them stops. Therefore stty cannot change it. But the page explains that there are tty.init files that can be used for permanent settings. I'm also looking into using the serial_port package with its native extension.

sigurdm commented 8 years ago

The serial port should work on a mac as of https://github.com/dartino/sdk/commit/33fde1ba34b38f32188ce682d1abb6bc95511597 . I am still waiting for equipment, can anyone with a mac confirm that it works?.

mit-mit commented 8 years ago

I'd be happy to test this. Can you update the instructions here, please?

sigurdm commented 8 years ago

Yes - good idea! Done.

mit-mit commented 8 years ago

It works great!