0

I need to capture logs from GtkTerm tool directly to text file. I tried

gtkterm > /path/to/file/file.txt

and

touch /path/to/file/file.txt
gtkterm -f /path/to/file/file.txt -e -c MyConfiguration

in both cases GtkTerm shell started to generate log but target file was empty.

0

I have the answer/solution for you.

Firstly, apologies for my bad english level, i'll try to do my best.

I was looking for the same thing that you but i cant find anything. I made a script to do this automatically and it works. Here's the code:

#!/usr/bin/python
# get lines of text from serial port, save them to a file

from __future__ import print_function
import serial, io

addr  = '/dev/ttyUSB0'   # serial port to read data from
baud  = 9600             # baud rate for serial port
fname = '/home/gps.dat'  # log file to save data in
fmode = 'a'              # log file mode = append

with serial.Serial(addr,9600) as pt, open(fname,fmode as outf:
   spb = io.TextIOWrapper(io.BufferedRWPair(pt,pt,1),
     encoding='ascii', errors='ignore', newline='\r',line_buffering=True)
   spb.readline()  # throw away first line; likely to start mid-sentence (incomplete)
 while (1):
     x = spb.readline() # read one line of text from serial port
     print (x,end='')   #echo line of text on-screen
     outf.write(x)      #write line of text to file
     outf.flush()       #make sure it actually gets written out

This is the script that runs the communication. In my case, i have a GPS connect via RS-232 (DB-9) to USB cable to Raspberry PI (Raspbian SO), for that i use ttyUSB0.

In the line that says fname, you can indicate the destiny and name for the file to want capture the info.

If you want to use .dat or .txt format its no problem.

And one thing more. I dont use the gtkterm for this (i was crazy with this terminal).

I think this is so easy way for your quest, and i hope it will be usefully.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.