modem tty access in bash
I can access a radio modem (slice of radio) using minicom which works just fine, but accessing it using bash/sh only works if I first access using minicom, then quit without resetting the modem. my script is something like this (rough psudo code)
Code:
MODEM=/dev/ttyAMA0 Code:
minicom -b 9600 -o -F /dev/ttyAMA0 This script is running on rasbian jessie, as root user. any ideas would be appreciated, thanks. |
The usual problem is that once the modem device is closed it goes back to its default configuration... You only have a single input connection - but the output is handled separately. So once the stty exits - it would tend to return to the default configuration.
This is why using minicom works - it can set the configuration of both input and output sides of the serial device, and keep the channels open. A side benefit is that it prevents any other process for doing things to the serial device by locking access. |
do you any suggestions on how I can set the device and leave it open. ?
I couldn't find any options in stty to do that, although running Code:
stty -F /dev/ttyAMA0 -a I should re-mention that if I run minicom first and then quit without resetting the port, then my script works fine. I just want to achieve "whatever minicom does" in my script. |
I think minicom sets other flags besides just the baud rates (modem signals, parity, control flow, escape handling for modem control...) - but then minicom is designed to handle serial lines. Bash isn't.
Serial lines are not that easy to set up. They are asynchronous devices... and bash does not work that way. This is why minicom uses a pty to interface with the user - it provides synchronization between input and output (both from the user and from the serial line). You can use the "expect" tool to interface... but it isn't easy either. |
Well, I've solved the problem, so for the benefit of anyone else, here is my solution.
1. run minicom as usual ( minicom -b 9600 -o -F /dev/ttyAMA0 ), and demonstrate that comms work. 2. quit minicom without resetting the modem/port ( Ctrl-A q ) 3. run stty -F /dev/ttyAMA0 -g >config.txt 4. take the config text, and in the script, use stty -F $MODEM `cat config.txt` (I just pasted the contents of the text after $MODEM as it is tidier) 5. ta-da everything just works. to prove it, go into minicom and edit resetting the modem ( Ctrl-A X ) the script still works, where as before it did not. If I manually close the port (using minicom) then try echo "hi">/dev/ttyAMA0 it fails as expected, then Ctrl-C and run the script, I get an warning about not being able to set everything, but it still works, and after quitting the script, running it again there is no warning. thanks jpollard for for the comments. I had feared that I had to do some "extra modem initialisation", as that is shown in some of the minicom options, but it was not necessary. stty did all that was needed. |
Congratulations. I was wrong about it falling back to the defaults.
|
All times are GMT -5. The time now is 08:52 AM. |