Little script with minicom


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Little script with minicom
# 29  
Old 04-20-2012
Quote:
Originally Posted by methyl
@Corona688
What is your modem, by the way?
A fairly generic-looking thing made by AddTell. It's certainly not new, but neither is it particularly weird either. I experimented with a BASH script to control it thinking it might be useful for the server to be able to send faxes, but I never wrote anything beyond basic communication.
# 30  
Old 04-20-2012
my modem is a HSPA+ of sierra wireless: SL8092 Sierra Wireless - SL809x HSPA+ module for mobile computing and M2M

I use it with minicom and it work well!

Code:
#!/bin/bash

MODEM="/dev/ttyUSB3"
TMP="./response"

get_response ()
{
        local ECHO
        # cat will read the response, then die on timeout
        cat <&5 >$TMP &
        echo "$1" >&5
        # wait for cat to die
        wait $!

        exec 6<$TMP
        read ECHO <&6
        if [ "$ECHO" != "$1" ]
        then
                exec 6<&-
                return 1
        fi

        read ECHO <&6
        read RESPONSE <&6
        exec 6<&-
        return 0
}



# Clear out old response
: > $TMP

# Set modem with timeout of 5/10 a second
stty -F "$MODEM" 9600 -echo igncr -icanon onlcr ixon min 0 time 5

# Open modem on FD 5
exec 5<>"$MODEM"

get_response "AT+CGMI" || echo "Bad response"
echo "Response was '${RESPONSE}'"       ;       cat $TMP

echo

get_response "AT" || echo "Bad response"
echo "Response was '${RESPONSE}'"       ;       cat $TMP

exec 5<&-

Code:
sh scriptmodem.sh

Moderator's Comments:
Mod Comment Please use code tags instead of quote tags for code and samples

Last edited by Scrutinizer; 04-20-2012 at 05:09 PM..
# 31  
Old 04-20-2012
The point is, it's not really a serial port -- it's a USB device pretending to be one. Operations like changing the baud rate may not even exist -- why would you ever change the baud rate on a serial port which doesn't really exist -- causing stty to complain when you try to do it. All the important operations ought to be supported though.

It is a bash script. You aren't running it with bash, you're running it with sh -- which probably ends up being dash in ubuntu. Many important features I use are missing, dash doesn't even have functions.

Run it using bash instead.

The "get_response" function sends the given command to the modem and waits for an "OK" within a short amount of time. If it gets it, it returns success, if it doesn't, it returns error. Substitute whatever you want for your AT commands there.

Last edited by Corona688; 04-20-2012 at 05:19 PM..
# 32  
Old 04-20-2012
okk

so i type:
Code:
chmod u+x scriptmodem.sh
./scriptmodem.sh

is right?

And now how modified your script for to do:

Code:
send AT+CREG?
IF not exist /dev/ttyUSB3 echo "MODEM NOT CONNECTED" and exit
ELSE (exist /dev/ttyUSB3) {
send AT+CREG?
if ouput is different from +creg: 0,1 then echo "MODEM NOT REGISTRED ERROR 1" and redo at+creg if is still different from +creg: 0,1 then echo "Modem  not registred ERROR 2"
AT!PADCONN=1
if output is different from CONNECTED 1,0 then "IMPOSSIBLE OPEN A SOCKET  ERROR 1" and redo at!PADCONN=1
and if is still different from CONNECTED 1,0 then echo "IMPOSSIBLE OPEN A SOCKET ERROR 2"
}

I not undstand good your get_response function and i dont know how change it for me. You can write only one row for me?
ONLY THIS PLS:

Code:
send AT+CREG?
if ouput is different from +creg: 0,1 then echo "MODEM NOT REGISTRED ERROR 1" and redo at+creg if is still different from +creg: 0,1 then echo "Modem  not registred ERROR 2"


Help me pls Smilie

Last edited by enaud; 04-20-2012 at 05:30 PM..
# 33  
Old 04-20-2012
You are really getting ahead of yourself. Why not just try get_response "AT+CREG" ; echo $RESPONSE and see whether it works at all? If it doesn't, then writing your 500 lines of script for you will be pretty pointless.
# 34  
Old 04-20-2012
Yes, but now i am not at university for try. Smilie I'm at home and i can't try your script. Here are 23:10 PM Smilie

You confirm that:
for run your script i must type: ./script ?
# 35  
Old 04-20-2012
Yes, just like any other UNIX program or script file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Alternatives to minicom During Remote Access?

Hey All, I am trying to find something similar to minicom, but it needs the ability to be ran during a remote dialup session on the remote device's side. If I dial into the remote server (*using minicom) and then try to run minicom on the remote server I get the following: # minicom... (20 Replies)
Discussion started by: mrm5102
20 Replies

2. SCO

Minicom

hello is there a copy of minicom or equivalent for unixware 7? thanks (3 Replies)
Discussion started by: deus-programmer
3 Replies

3. Shell Programming and Scripting

Expect script not working in crontab with minicom

Hi All, I am testing expect script in command prompt without issue, but in crontab it is not working, i check the output error as below: #cat /var/log/testexp.log spawn minicom -C /var/log/minicom1.log No cursor motion capability (cm) AT+COPS=? I am new in scripting, together... (1 Reply)
Discussion started by: elingtey
1 Replies

4. Shell Programming and Scripting

Help with minicom script

I'm a fairly new user to Linux based systems and am still a little uncomfortable with using the command interface. I'm trying to get my feet wet but have unfortunately hit a wall and am actually not even sure what I am trying to accomplish is at all possible. Basically, I am trying to use a... (0 Replies)
Discussion started by: nrdk00
0 Replies

5. Shell Programming and Scripting

Exiting from Minicom on a shell script

This is what I've tried: #!/bin/sh send sh send showifs send exit ! killall minicom My problem is that for some reason when I do this it doesn't give me the results of the prior commands sent like showifs So I suspect my syntax is wrong. (1 Reply)
Discussion started by: uradunce
1 Replies

6. Shell Programming and Scripting

minicom works, but stty does not

Hi all, I have some trouble getting stty to talk to some serial/usb converter. Getting minicom to work was however quite simple after I entered the following settings in addition to its standard-setup: pu port /dev/ttyUSB0 pu baudrate 19200 pu bits 8 pu... (3 Replies)
Discussion started by: pa-trick
3 Replies

7. Shell Programming and Scripting

expect minicom

Hi, I am new to using minicom. I want how to write a expect script for minicom login? I wrote a code but its not acting what iam expecting. here I have my code: #!/usr/bin/expect set fd fconfigure $fd spawn -open $fd spawn minicom expect “enter:” send "\n" send "\n" ... (3 Replies)
Discussion started by: vanid
3 Replies

8. Shell Programming and Scripting

running scripts in minicom

Hi, I am new to use minicom. I want script to run on minicom with username and password as automated.(Expect). please could anyone suggest the sample code for it. Thanks in advance (2 Replies)
Discussion started by: vanid
2 Replies

9. UNIX for Dummies Questions & Answers

Minicom Scripting

Does anyone have a working minicom script they would care to post as I can't get the scripting working and the scriptdemo and unixlogin sample scripts are on my system either. Thanx, I (2 Replies)
Discussion started by: ianf
2 Replies

10. UNIX for Dummies Questions & Answers

linux - minicom

hello. i'm attempting to use minicom in linux, but i'm having some difficulties. When i type in "minicom", the application opens up. It says 'starting minicom/finding modem'(something like that). However, once it actually starts, I can't do anything. No matter what I type in, it doesn't work. ... (2 Replies)
Discussion started by: kickboxer
2 Replies
Login or Register to Ask a Question