LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-11-2015, 06:23 PM   #1
Stuny
LQ Newbie
 
Registered: Nov 2015
Posts: 3

Rep: Reputation: Disabled
Post Capuring data with Minicom over tty interface


Hi, I'm using a raspberry pi to capture the serial output of a device under test. The pi is managed remotely via SSH.
On my pi I have a USB to serial (1 USB, 2 serial - USB0 and USB1).
I tried a simple :
sudo stty -F /dev/ttyUSB0 115200
sudo cat /dev/ttyUSB0 > my_log_file.txt

but it seems that my USB driver is messing up in the sense that it is sending carriage return all the time... that's not good.

So I moved to minicom. After configuring minicom with the correct settings it's working with the following parameter
sudo minicom USB0 -C my_log_file.txt

My problem is that when I use the following :
sudo minicom USB0 -C my_log_file.txt &
the log file is not recording anything at all (size does not increment).

I configured minicom by default save a log file, but I'm not able to find it or read it (I looked in /etc/minicom).

I need to run two instance of minicom at the same time and have them run in the background so I can use my SSH session for other purpose.

Thanks for you help !
 
Old 11-11-2015, 10:59 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
AFAIK, minicom reads from stdin. Background processes have their stdin closed and are stopped when they attempt access to stdin. This would explain your problem, but I would have expected a message telling you that the process was stopped.

You could launch minicom inside a screen, detach from the screen program and use your ssh session for interactive work.

I also stumbled on a post here at Linuxquestions where somebody was successful using just stty and cat (as you attempted to do originally).

Last edited by berndbausch; 11-11-2015 at 11:02 PM.
 
Old 11-12-2015, 12:37 PM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
When you specify capture file for minicom, it raises a dialog with a default filename, you can replace that with a fully qualified path and filename:
Code:
/home/myuser/mycapture.txt
 
Old 11-12-2015, 01:16 PM   #4
Stuny
LQ Newbie
 
Registered: Nov 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
You mean in "Filenames and paths" > option F ?
I tried using :
sudo screen minicom USB0 -C USB0.log &
A pid is created but the file isn't modified.

Am I doing this right ?
 
Old 11-12-2015, 01:28 PM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
A while back I was having similar issues, and just broke down and wrote a little C program to open and configure the serial port and then log everything that comes in to disk. It took a little development to write it, but it's been indispensable since, and I wouldn't do it any other way. With just some tiny tweaks you can have it rotate through numbered log files as they hit a certain size, you can add timestamps to the data that's collected, etc.

This is a slightly modified (and untested) version of my most recent iteration, it should get you 99.9% of the way there (just might need some tweaks to the file writing, that's the part that's untested):
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>

// Change this to match the machine's serial port
#define SERDEV "/dev/ttyUSB0"

void initComPort(int* sfd, char* device)
{
  struct termios options;

  *sfd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
  if (*sfd == -1)
  {
    fprintf(stderr, "unable to open %s\n",device);
    exit(1);
  }
  else
  {
    fcntl(*sfd, F_SETFL, FNDELAY);
  }

  tcgetattr(*sfd, &options);

  cfsetispeed(&options, B115200);
  cfsetospeed(&options, B115200);

  cfmakeraw(&options);

  options.c_cflag &= ~(PARENB | CSTOPB | CSIZE | CRTSCTS);
  options.c_cflag |= (CLOCAL | CREAD | CS8);

  options.c_oflag &= ~OPOST;
  options.c_cc[VMIN] = 1;
  options.c_cc[VTIME] = 0;

  tcsetattr(*sfd, TCSANOW, &options);
}


int main(void)
{
  int sfd;
  FILE *ofd;
  int32_t n, i;
  u_int32_t bytes;
  u_int8_t buff[10000];

  // Initialize the serial port
  initComPort(&sfd, SERDEV);

  while (1)
  {
    // Check if there's any data available to read
    ioctl(sfd, FIONREAD, &bytes);
    if (bytes > 0)
    {
      // Read what we can
      n = read(sfd, buff, 10000);
      if (n < 0)
      {
        fprintf(stderr, "read failed\n");
      }
      if (n > 0)
      {
        ofd = fopen("data.bin", "a");
        if (ofd==NULL)
        {
          fprintf(stderr, "unable to open output file\n");
          exit(2);
        }

        fwrite(buff, 1, n, ofd);

        fclose(ofd);
      }
    }
    usleep(1000);
  }
}
It's hardcoded to the pretty standard 115200 8N1 protocol, but you can adjust that as necessary in initComPort.

Everything is done in raw bytes, so it doesn't matter if your device is pushing out ascii or binary data.

Last edited by suicidaleggroll; 11-12-2015 at 01:31 PM.
 
Old 11-12-2015, 01:44 PM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by Stuny View Post
You mean in "Filenames and paths" > option F ?
I tried using :
sudo screen minicom USB0 -C USB0.log &
A pid is created but the file isn't modified.

Am I doing this right ?
Firstly, I LOVE the example shown by suicidaleggroll.

What I mean for minicom is the following:

Enter minicom normally.

CTRL-A Z to configure minicom, you get a menu
L shows on mine as the option for Capture on/off
When I do that I get a pop-up with some default filename that I can change to be like /home/myuser/myfile.txt

That's it.
 
Old 11-13-2015, 10:32 AM   #7
Stuny
LQ Newbie
 
Registered: Nov 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
Well I guess I owe people an apology, my cat finally worked with the example below (added the background task). I don't fully understand what went wrong in the first place. I understand that if I start a task in my SSH/TELNET session this task will stop as I kill my active session, but this was not even working as I was in session...
Long story short, it's working !

sudo stty -F /dev/ttyUSB0 115200
sudo cat /dev/ttyUSB0 > my_log_file.txt &
 
Old 04-10-2019, 06:41 AM   #8
MPH426
LQ Newbie
 
Registered: Feb 2013
Posts: 23

Rep: Reputation: Disabled
Captureing data with Minicom over tty interface

I know this is a dead thread, but in case it helps someone else.

Assuming that minicom is configured to use the proper device, baud, etc...


minicom | tee ouput.file


This works quite well for me anyway.

Hope it helps.

MPH
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
i am not able to store the data into the log file from minicom through rs232 infoinfo Linux - Newbie 1 02-20-2013 10:31 AM
minicom shows offline and is not captuing the serial data being sent lcbalogh Linux - Newbie 3 01-06-2011 07:54 AM
GPS Receiver data not being displayed in minicom arnie001 Linux - Embedded & Single-board computer 3 07-14-2010 03:48 AM
Minicom -- want to read data coming in a serial port ihopeto Linux - Newbie 2 04-12-2009 09:46 PM
no serial data appear at minicom on FC3 powah Linux - Networking 1 04-20-2006 01:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration