D
D
Da3z1e2017-07-13 11:55:31
Arduino
Da3z1e, 2017-07-13 11:55:31

Is it possible to limit the read command?

#!/bin/sh
set -x

IDLE_TIME=$((5000))

  while [ 0 ]
  do
  sleep_time=$IDLE_TIME
  triggered=false

  if [ read R</dev/ttyUSB0 ]; then
      if [ "$R" -eq "Sleep" ]; then 
          echo '&'> /dev/ttyUSB0
      fi
  fi
    	idle=$(xprintidle)
    if [ $idle -ge $IDLE_TIME ]; then
        	if ! $triggered; then
            	zenity --question --title="Бездействие пользователя" \
        --text="Вы возле компьютера?" \
        --timeout=10
 if [ $? -eq "0" ]
 then
    triggered=false
        	sleep_time=$((IDLE_TIME-idle+100))
  else echo '&'> /dev/ttyUSB0
    triggered=true
        	sleep_time=$IDLE_TIME
 	fi

        	fi
    fi
  sleep 1
  done

There is such a script. Are there any options for the read command so that it only executes when data arrives on the port? The if [ read ] thing does not work, but simply the read command kills the entire script and it waits for the data to arrive on the port and the rest of the script is not executed. with a timeout is also not suitable, because after the time it does not go further in the code. How to restrict the execution of the read command?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2017-07-13
@saboteur_kiev

It seems like there was a question like this quite recently.
Why is the timeout for read not suitable for the type:
read -t 5 R/ttyUSB0
why if [ read ] - what is this if [ read ] construction anyway?
maybe you need if read ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question