Parker Schuh | 46b4881 | 2019-02-22 20:45:36 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # USAGE: jevois-cmd [-d /dev/ttyACMX] command |
| 3 | # |
| 4 | # Send a command to a connected JeVois camera using the serial-over-USB port |
| 5 | # |
| 6 | # Tip: If things appear garbled in some way, maybe your TTY settings got messed up. Run screen /dev/ttyACM0 115200 to |
| 7 | # reset to the expected state. |
| 8 | # |
| 9 | # You may need to install: sudo apt install python-serial |
| 10 | |
| 11 | ttydev="/dev/ttyACM0" |
| 12 | if [ "X$1" = "X-d" ]; then ttydev=$2; shift 2; fi |
| 13 | |
| 14 | if [ ! -c "$ttydev" ]; then echo "Cannot access $ttydev -- is JeVois plugged in? -- ABORT"; exit 1; fi |
| 15 | |
| 16 | # Set the tty flags: |
| 17 | sudo stty -F "${ttydev}" sane raw igncr clocal cread -echo |
| 18 | |
| 19 | # First read any accumulated junk in the serial buffers: |
| 20 | while true; do |
| 21 | sudo bash -c "read -s -t 0.05 < \"${ttydev}\"" |
| 22 | if [ $? -ne 0 ]; then break; fi |
| 23 | done |
| 24 | |
| 25 | # Make a python program: |
| 26 | prog="import serial |
| 27 | ser = serial.Serial('$ttydev', 115200, timeout=1) |
| 28 | ser.write('$*\n') |
| 29 | nothing=1 |
| 30 | out = '' |
| 31 | while nothing or ser.inWaiting() > 0: |
| 32 | out += ser.read(1) |
| 33 | nothing=0 |
| 34 | if out != '': |
| 35 | print out, |
| 36 | " |
| 37 | |
| 38 | # Send the command: |
| 39 | sudo python2.7 -c "$prog" |