0

For entering minicom and saving the log of it, I use "sudo minicom -C nameoffile", but I want to do this in a loop, opening minicom can be done by using subprocess but I couldn't find anything to exit minicom in my loop and continue looping, since you need to enter "ctrl-a, then x" or "ctrl-a, then q" and after must press enter for confirming this. Anybody have any idea or suggestion?

Tolga Varol
  • 1,036
  • 1
  • 16
  • 21
  • For how long do you wish to run the minicom? How about running it as a sub-process and killing from outside (from the father process)? – ArnonZ Aug 22 '14 at 14:23
  • @ArnonZilca thank you for your comment and sorry for late answer, but will it be able to run again after I kill it? I need to run the loop for at least an hour and minicom must be logged, grepped and the line will be appended to a list then it must be shut, after same routine must go. – Tolga Varol Aug 22 '14 at 21:55
  • Do you **want** to run-it, kill-it, run-it, kill-it... or do you want to run it the whole time and sample it from time to time. Does the configuration or the device changes from one sample to another? – ArnonZ Aug 24 '14 at 07:23
  • @ArnonZilca yes, I want to run-it, kill-it and make it in a loop, because I think if I run it whole time I won't be able to use Bash to gather "iwlist output data" or NMEA sentences – Tolga Varol Aug 24 '14 at 12:45
  • @ArnonZilca No, once it is connected, it is always seen as ttyUSB1,ttyUSB2 and ttyUSB3, the one I use for gathering data for that device is ttyUSB3 and I setup and save ttyUSB3 to minicom. – Tolga Varol Aug 24 '14 at 12:46
  • Got it. I'll write my response as an answer. – ArnonZ Aug 24 '14 at 18:04
  • This looks like an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). Maybe instead of using minicom, use a Python library such as [PySerial](http://pyserial.sourceforge.net/) to directly access the serial port. –  Aug 24 '14 at 18:20
  • @TolgaVarol I agree with Andre. And as you can see I answered for X rather than Y. – ArnonZ Aug 24 '14 at 18:29

1 Answers1

10

The first (and obvious) solution

might take a little more effort (or not - you decide) and it is probably the best way to do this is to open the device yourself using pySerial (and here's an example) and then do whatever you like with the data - write it to a file, parse it, send it to NASA or all of the above. :)



If you insist on working around that solution:

One possibility I can think of...

is piping the minicom command to tee. when you pipe through tee you can give it a file name (to log to) and pipe tee as input to your own binary / script. That should take care of logging + parsing the input. (I Haven't tried it with minicom and i'm not sure how you will exit your piped program like that).

Another possibility I can think of...

is redirect to a file (>) and then write a different binary / script that will read the file as it is being written (like tail -f does). Here's an example for reading a file in python while it is being written.

Since it's serial data, I'm guessing it's pretty slow (especially NMEA), so I don't think that you will have much latency if you write it to a file and read it using a different binary / script.

Community
  • 1
  • 1
ArnonZ
  • 3,822
  • 4
  • 32
  • 42
  • IF there is no need to use minicom, using `pyserial` is far easier. So +1 for the first suggestion. File write latency problems come with buffering, fast data is actually easier than slow data. – DrV Aug 24 '14 at 18:36
  • @DrV minicom is needed, because I can't send AT commands from python script directly. – Tolga Varol Aug 25 '14 at 08:43
  • @Arnon Zilca , thank you for your answer, I just wrote a code for reading via pyserial but it is not reading the AT commands, it is just reading an "A" from the 3G module. _ser3g = serial.Serial("/dev/ttyUSB3", 115200, timeout = 5)_ **time.sleep(1)** _ser3g.write("AT+CSQ")_ **time.sleep(1)** _response = ser3g.read()_ **print >> file ,date,',',val[:42],',',data,',',response** – Tolga Varol Aug 25 '14 at 09:11
  • @Arnon Zilca , only thing comes to my mind now is to capture minicom terminal inside the loop but I don't have any idea how to exit minicom inside a loop like run it- kill it- run it.... and so on. For capturing what I do is **'sudo' 'minicom' '-C' 'filename'** , do you have any idea how I can exit minicom terminal in a loop? – Tolga Varol Aug 25 '14 at 09:16
  • Both of the solutions (other than pySerial), suggest you do it without run-kill-run-kill. I think that piping minicom to tee and then to a parser python script, or redirecting minicom to a file and then reading from the file in a different process will be a lot easier. – ArnonZ Aug 25 '14 at 09:26
  • @ArnonZilca thank you again, I managed to do it without using minicom, what I did wrong was I wasn't reading the line needed via pyserial, pyserial is working, but I couldn't manage to use minicom inside the loop, but it is not necessary. – Tolga Varol Aug 25 '14 at 10:25