Skip to content

Instantly share code, notes, and snippets.

@tmbdev
Created June 13, 2013 10:00
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmbdev/5772607 to your computer and use it in GitHub Desktop.
Save tmbdev/5772607 to your computer and use it in GitHub Desktop.
Use expect to connect to a serial port (e.g., for Arduino)
#!/usr/bin/expect -f
# device
set modem /dev/ttyUSB0
# keep it open
exec sh -c "sleep 3 < $modem" &
# serial port parameters
exec stty -F $modem 9600 raw -clocal -echo -istrip -hup
# connect
send_user "connecting to $modem, exit with ~.\n"
spawn -open [open $modem w+]
interact {
~. exit
~~ {send "\034"}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment