LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   what is a good program for handling input and executing programs? (https://www.linuxquestions.org/questions/linux-general-1/what-is-a-good-program-for-handling-input-and-executing-programs-669939/)

anon112 09-14-2008 08:55 PM

what is a good program for handling input and executing programs?
 
My question may seem vague, but basically what I need is a program that will accept input from say a parallel or serial port and executing a command. Mostly I need this for my alarm system for my Lab. I'm going to hook up the device to close a switch (on a parallel or serial port) and cause my computer to execute a command to take a picture, or play an audio file of a gun being cocked.

Any suggestions would be greatly appreciated.
thanks in advance
-kev

stomfi 09-14-2008 11:25 PM

Quote:

Originally Posted by kev717 (Post 3280486)
My question may seem vague, but basically what I need is a program that will accept input from say a parallel or serial port and executing a command. Mostly I need this for my alarm system for my Lab. I'm going to hook up the device to close a switch (on a parallel or serial port) and cause my computer to execute a command to take a picture, or play an audio file of a gun being cocked.

Any suggestions would be greatly appreciated.
thanks in advance
-kev

Reading from a serial or parallel port can be done in a couple of ways.
1. You can read from the buffer and echo the result to another script or command thus:
#/bin/bash
while true
do
read LINE < /dev/tty0S
echo $LINE
done
Or instead of the echo command you can insert more processing commands.

2. You can use dd to process the raw input. See info coreutils for everything dd can do. Remember that /dev/ttySO is a file.
If you know how many bytes to expect you can even do this in a script.
dd if=/dev/ttyS0 count=1 bs=8
Add the option of=filename to put the output into a file or add a pipe (|) to pipe the output of dd to other commands.

There are probably some pages on the web for using dd. It used to be quite prevalent in the old Unix world for processing telemetry data received from a modem connection back in the pre www days, so you may have to dig and delve in the written world.

anon112 09-15-2008 02:09 PM

so would this repeat itself, or if it goes off once then the program just exits?

Also, what command would I do to get the data off of a USB port?
-kev


All times are GMT -5. The time now is 06:52 AM.