#!/bin/bash ## # Read a 'USB thermal station' from www.d3p.pl. # # This is a USB interface with 8 ports. It responds to commands # through an ACM driver, which presents as a serial device through # /dev/ttyACM0 (or possibly higher numbers if you have multiple). # It requires the Kernel driver 'cdc_acm' to be present on Linux. # # Commands accepted by the device are: # # - report the temperature for sensor in degrees C # V # - report the device version # We only use the sensor commands. # # Readings are provided quickly, although I've used a 2 second # delay here, just to be sure that I get back the data. # # The 'cu' tool is used to communicate with the device. # It is necessary for the device to be accessible by the 'uucp' # user. You may need to use 'chown uucp /dev/ttyACM0' or similar # prior to using this script. # # Output takes the form of a line per sensor, in the form: # id= # where starts at 0. # SENSORS="$1" DEVICE="$2" DELAY="$3" SPEED="$4" if [ "$SENSORS" = '-h' ] ; then echo "Syntax: $0 " echo " Number of sensors to probe (default 8)" echo " Device to query (default /dev/ttyACM0)" echo " Delay for query (default 2 seconds)" echo " Speed to communicate at (default 115200)" fi # Set defaults for the paramters SENSORS=${SENSORS:-8} DEVICE=${DEVICE:-/dev/ttyACM0} DELAY=${DELAY:-2} SPEED=${SPEED:-115200} # Turn it into a list of sensors SENSORS=$(seq 0 $(($SENSORS-1))) # Fire off the request for the sensors - ( echo $(echo $SENSORS | sed 's/ /\r/g') ; sleep $DELAY ) | cu --parity=n -l $DEVICE -s $SPEED dir 2> /dev/null | grep id | sed 's/ /=/'