Re: Could someone help with bash scripting?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



	hello.  Is the chat(1) program available  on your system?  It's designed to allow you to
do just what you're talking about from a shell script.  
	In general, the steps for talking to a device via a tty (serial port) are as follows:

1.  Set the parameters of the serial port (tty) by using the stty command.  The stty command
operates on the terminal associated with standard input on the process running stty.  For
example, if the serial port you want to set is: /dev/ttyu0, then to set the baud rate to
115200, you would do something like:
stty speed 115200 < /dev/ttyu0
The redirection at the end of the command tells stty to set the parameters on /dev/ttyu0.
To check the settings on /dev/ttyu0, do something like:
stty < /dev/ttyu0

2.  Once you get the speed, bits, stop bits and parity set the way you want, as well as the
flow control, use the chat command to send data down the serial port and to receive responses
from the device at the other end.  A snippet of shell script that does this might look like:

$SERDEV is the name of the /dev/tty device we're talking to.
$TMPFIL is just the name of a temporary file we're using for capturing the responses from the
modem on the end of $SERDEV  so we can figure out what it's doing.
The -v flag to chat makes it write a transcript of its conversation with the device it's
talking to.
The -s flag forces that transcript to come out on standard error, which is what we write to 
$TMPFIL

#First, see if we have a modem and can see signal.
/bin/rm -f $TMPFIL
sleep $RESETTIME
chat -V -s "" '\r\n\r\nATZ' 'OK' "$SIGNALSTR" 'OK' < $SERDEV > $SERDEV 2>$TMPFIL
grep -i 'LTE' $TMPFIL > /dev/null 2>&1
if [ $? -eq 0 ]; then
	signal="Using LTE (G4) services"
	hasmodem="true"
fi
grep -i '1X' $TMPFIL > /dev/null 2>&1
if [ $? -eq 0 ]; then
	signal="Using WCDMA (G3) services"
	hasmodem="true"
fi
/bin/rm -f $TMPFIL

3.  If you want to interact with the device using a live terminal session, as opposed to a
shell script, I suggest using the Kermit package from the University of Columbia.  There are
other programs like cu(1) and tip(1) that can do this, but I have found that kermit has the
best user interface and that it can be used interactively to both set the serial port up the
way you want as well as open a live session to talk with the device attached to it.

If the chat and kermit programs are not available on your native installation, do a google
search for examples of using those programs with your Linux distribution and that should reveal
the name of the precise packages you need to install to get them.

The kermit package may be called c-kermit or kermit.

Hope that helps.
-Brian





[Index of Archives]     [Linux for the Blind]     [Fedora Discussioin]     [Linux Kernel]     [Yosemite News]     [Big List of Linux Books]

  Powered by Linux