0

I'm new in this of bash programming in linux, basically what I want to do is to program a bash file that can open the port ttyUSB0 and then I need to interrogate it with AT commands (like "0100") and then assign the response to a variable, I've been trying this with this different ways:

1) Using cat #!/bin/bash PORT= \ls /dev/ttyU* cat $PORT ????

2) Using Minicom `#!/bin/bash minicom ???? '

3) Using Screen #!/bin/bash PORT= \ls /dev/ttyU* screen $PORT ????

How can I interrogate it before the cat, minicom and screen starts? What should I have to put in ???? of the 3 different codes?

Thank you so much!!!

antalbokor
  • 33
  • 5

2 Answers2

0

Don't try writing to a tty device using bash, you'll end up chasing your own tail forever. Use minicom or C-Kermit for that.

If you want to check that the device is active before starting minicom, you can read from it with bash and there is a good explanation of how to achieve this here: Bash read from ttyUSB0 and send to URL

Community
  • 1
  • 1
mproffitt
  • 2,409
  • 18
  • 24
  • Thanks for your answer but how do I interrogate the ttyUSB0?, what I can see it's how to read the answer, that would it be with "READ=`dd if=/dev/ttyUSB0 count=22 | sed 's/ //g'`" But, What is the dd? What is the count=22 | sed 's/ //g'? – antalbokor Jun 09 '13 at 17:38
  • `dd` is a tool for copying a file and count=22 means to copy only 22 blocks from the file before termination. This is then piped to `sed` which strips spaces ('s/ //g' means strip all spaces). – mproffitt Jun 09 '13 at 17:45
0

You should be able to use my atinout program for this. It is a command line tool to talk with a modem:

$ echo AT | atinout - /dev/ttyUSB0 -
AT
OK
$

So with a little bit of scripting you should be able to extract the response you want (remember to always check for a successful OK response).

hlovdal
  • 26,565
  • 10
  • 94
  • 165