2

Trying to get a GPIO board working, need to access it from script, here is what I am using:

stty -F /dev/ttyACM1 115200 raw -echo   #CONFIGURE SERIAL PORT
exec 3</dev/ttyACM1                     #REDIRECT SERIAL OUTPUT TO FD 3
cat <&3 > /tmp/ttyDump.dat &            #REDIRECT SERIAL OUTPUT TO FILE
PID=$!                                  #SAVE PID TO KILL CAT
echo "gpio readall" > /dev/ttyACM1      #SEND COMMAND STRING TO SERIAL PORT
sleep 5s                                #WAIT FOR RESPONSE
kill $PID                               #KILL CAT PROCESS
exec 3<&-                               #FREE FD 3
cat /tmp/ttyDump.dat                    #DUMP CAPTURED DATA

The board is working - I can access via screen, enter same command and get results back, so I know its my fractured script. What am I doing wrong?

Note - this script was copied from elsewhere here on stackexchange.

alabamatoy
  • 121
  • 1

1 Answers1

0

I found my problem. First, I had the tty commo configured wrong. Second, I was sending the command in a way that the GPIO board didn't know what to do with it. This works:

stty -F /dev/ttyACM1 -cstopb -crtscts cs8 9600 #CONFIGURE SERIAL PORT
exec 3</dev/ttyACM1                            #REDIRECT SERIAL OUTPUT TO FD 3
cat <&3 > /tmp/ttyDump.dat &                   #REDIRECT SERIAL OUTPUT TO FILE
PID=$!                                         #SAVE PID TO KILL CAT
#  echo "Process ID is $PID"
printf "gpio read 0\r" > /dev/ttyACM1          #SEND COMMAND STRING TO SERIAL PORT
sleep .2s                                      #WAIT FOR RESPONSE
kill $PID                                      #KILL CAT PROCESS
exec 3<&-                                      #FREE FD 3
cat /tmp/ttyDump.dat                           #DUMP CAPTURED DATA
alabamatoy
  • 121
  • 1