blob: 6fe19d30a2c1980b405c27dbbb4c864ec65a85f3 [file] [log] [blame]
Parker Schuh46b48812019-02-22 20:45:36 -08001#!/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
11ttydev="/dev/ttyACM0"
12if [ "X$1" = "X-d" ]; then ttydev=$2; shift 2; fi
13
14if [ ! -c "$ttydev" ]; then echo "Cannot access $ttydev -- is JeVois plugged in? -- ABORT"; exit 1; fi
15
16# Set the tty flags:
17sudo stty -F "${ttydev}" sane raw igncr clocal cread -echo
18
19# First read any accumulated junk in the serial buffers:
20while true; do
21 sudo bash -c "read -s -t 0.05 < \"${ttydev}\""
22 if [ $? -ne 0 ]; then break; fi
23done
24
25# Make a python program:
26prog="import serial
27ser = serial.Serial('$ttydev', 115200, timeout=1)
28ser.write('$*\n')
29nothing=1
30out = ''
31while nothing or ser.inWaiting() > 0:
32 out += ser.read(1)
33 nothing=0
34if out != '':
35 print out,
36"
37
38# Send the command:
39sudo python2.7 -c "$prog"