Hello,
I want use the serial port on ttyAMA0.
I connect with none problem Raspberry and Dell Ubuntu with minicom for communication.
Now, i want use ttylog (http://sourceforge.net/p/ttylog)
i have a source and compile with makefile, but if i run ttylog, no connection
problem with fopen(modem_device...) I have a infinity wait
minicom on ubuntu, i disable the hardware/software flow control.
can you help me on this problem. you can test ttylog ?
My objective is used this command :
./ttylog -f -b 115200 -d /dev/ttyAMA0 | tee -a serial.log
See You Later
Florent
-
- Posts: 4277
- Joined: Sun Jan 15, 2012 1:11 pm
Re: Serial & C Programming
WARNING: This has nothing to do with your specific issue. It is a side issue that caught my attention.
You mention using "minicom". Minicom has a long history of being the only serial comm program included with basic Linux installs - and, following the general Unix/Linux attitude of "If it is at least barely usable, it is sufficient", it seems people continue to use it, despite its shortcomings. But in my opinion, minicom is absolutely dreadful in both concept and implementation and is horrendously difficult to use. The problem is that, since Linux's main focus has always been on the Internet, there just hasn't been much effort put into developing a replacement.
However, I am here to suggest two alternatives, that I believe are much better:
1) screen (Yes, GNU screen!) - which can function as a serial comm program. This is a little known feature of screen. This works very well - and, of course, can be used either with or without X.
2) Seyon. This is a nice X-based serial comm program. It is very old (which confirms what I said above about there just not being much development effort put into this area), and may not be in the repositories, but I've built it from source many times over the years. It is slightly weird to get going (i.e., to get configured), but works well once you've gotten past that hurdle.
You mention using "minicom". Minicom has a long history of being the only serial comm program included with basic Linux installs - and, following the general Unix/Linux attitude of "If it is at least barely usable, it is sufficient", it seems people continue to use it, despite its shortcomings. But in my opinion, minicom is absolutely dreadful in both concept and implementation and is horrendously difficult to use. The problem is that, since Linux's main focus has always been on the Internet, there just hasn't been much effort put into developing a replacement.
However, I am here to suggest two alternatives, that I believe are much better:
1) screen (Yes, GNU screen!) - which can function as a serial comm program. This is a little known feature of screen. This works very well - and, of course, can be used either with or without X.
2) Seyon. This is a nice X-based serial comm program. It is very old (which confirms what I said above about there just not being much development effort put into this area), and may not be in the repositories, but I've built it from source many times over the years. It is slightly weird to get going (i.e., to get configured), but works well once you've gotten past that hurdle.
And some folks need to stop being fanboys and see the forest behind the trees.
(One of the best lines I've seen on this board lately)
(One of the best lines I've seen on this board lately)
Re: Serial & C Programming
I'm used minicom just for testing the communication between 2 units (RaspBerry Pi and PC Dell).
Now I want testing ttylog because i want little software for logging my serial port into log file.
(I want compile myself the different source with gcc)
THX
Florent
Now I want testing ttylog because i want little software for logging my serial port into log file.
(I want compile myself the different source with gcc)
THX
Florent
Re: Serial & C Programming
Why not just do
stty -F /dev/ttyAMA0 115200
cat </dev/ttyAMA0 | tee serial.log
stty -F /dev/ttyAMA0 115200
cat </dev/ttyAMA0 | tee serial.log
Re: Serial & C Programming
I'm not much of a GUI user and cut my teeth on XTerm with MS DOS.
When I need a serious Serial terminal I use PuTTy in the RAW mode.
However, when I need a serial terminal for trouble shooting a serial device on a remote Server.
I SSh into my Server and execute Minicom . As mentioned, there has been no development of a serial terminal for years. Not too many Ops have a need for a Modem or Terminal Node program.
I have tried Peco and several other X Term pgms and despite it's short comings return to using Minicom. If someone has a suggestion of a better X Term app I will be glad to give it a try.
When I need a serious Serial terminal I use PuTTy in the RAW mode.
However, when I need a serial terminal for trouble shooting a serial device on a remote Server.
I SSh into my Server and execute Minicom . As mentioned, there has been no development of a serial terminal for years. Not too many Ops have a need for a Modem or Terminal Node program.
I have tried Peco and several other X Term pgms and despite it's short comings return to using Minicom. If someone has a suggestion of a better X Term app I will be glad to give it a try.
The Grass may be greener on the other side of the fence, but it still has to be mowed.
- tedhale
- Posts: 114
- Joined: Thu Sep 20, 2012 4:52 pm
- Location: Williamsburg, VA, USA
- Contact: Website
Re: Serial & C Programming
The open is failing because the OS is using that port by default.
On boot it outputs status info
After boot it allows a user to logon.
Look at my blog post
http://raspberrypihobbyist.blogspot.com ... -port.html
There are instructions on how to stop the OS from using the serial port and allow you to use it.
On boot it outputs status info
After boot it allows a user to logon.
Look at my blog post
http://raspberrypihobbyist.blogspot.com ... -port.html
There are instructions on how to stop the OS from using the serial port and allow you to use it.
- Ted B. Hale
http://raspberrypihobbyist.blogspot.com
http://raspberrypihobbyist.blogspot.com
Re: Serial & C Programming
@joan > tomorrow, i test !!
@tedhale > oups
i comment only this line :
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
i forgot /boot/cmdline.txt, i also tested
Thank you
@tedhale > oups
i comment only this line :
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
i forgot /boot/cmdline.txt, i also tested
Thank you
Re: Serial & C Programming
Hi,
@joan > my serial.log file is empty
@tedhale > i apply modified on /boot/cmdline.txt and
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
but my ttylog block always on logfile = fopen(modem_device, "rb");
no probleme with open but segment fault after
how can i display to look to /dev/ttyAMA0 is used/busy ??
It's Ok with minicom if i run after
A+
Florent
@joan > my serial.log file is empty
@tedhale > i apply modified on /boot/cmdline.txt and
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
but my ttylog block always on logfile = fopen(modem_device, "rb");
no probleme with open but segment fault after

how can i display to look to /dev/ttyAMA0 is used/busy ??
It's Ok with minicom if i run after

A+
Florent
Re: Serial & C Programming
I paste my Makefile and ttylog.c
http://zerobin.handismart.fr/?f2381faff ... blQDZieX0=
I invite you to compile my program and tested
THX
http://zerobin.handismart.fr/?f2381faff ... blQDZieX0=
I invite you to compile my program and tested

THX
Re: Serial & C Programming
Hi,
I test on Python language with miniterm.py : OK
I test on Shell command : (stty raw; cat > serial.log) < /dev/ttyAMA0 : OK
Have you an program tested for C language ??
Can you test the ttylog.c ????
Big Help and Big THX
Florent
I test on Python language with miniterm.py : OK
I test on Shell command : (stty raw; cat > serial.log) < /dev/ttyAMA0 : OK
Have you an program tested for C language ??
Can you test the ttylog.c ????
Big Help and Big THX
Florent
Re: Serial & C Programming
It sort of works. If you use minicom you have to send a newline (ctrl J) to get fgets to return.
Re: Serial & C Programming
I use minicom on DELL Ubuntu for send caracter.
My ttylog is always blocked on fopen(modem_device...
I tested CTRL+J on minicom but it's identical.
C-U
Florent
My ttylog is always blocked on fopen(modem_device...
I tested CTRL+J on minicom but it's identical.
C-U
Florent
Re: Serial & C Programming
It should not block on fopen. Perhaps it is returning an error?
Re: Serial & C Programming
no crash, just wait after "FCC2>" on fopen (fopen is between printf FCC2/FCC3)
Re: Serial & C Programming
I get this
Perhaps I altered your code. I seem to remember I had to add new lines as zerobin seemed to have stripped all whitespace.joan@pluto:~$ cc -o ttylog ttylog.c
joan@pluto:~$ ./ttylog -d /dev/ttyAMA0
ttylog version 0.1.d-2.FC.
FCC>1
FCC>2
FCC>3
FCC>
FCC> fileno id : 3
^C
joan@pluto:~$ ./ttylog -d /dev/ttyAMA9
ttylog version 0.1.d-2.FC.
FCC>1
FCC>2
FCC>3
FCC> ./ttylog: invalid device /dev/ttyAMA9
joan@pluto:~$ ./ttylog -d /dev/ttyA
ttylog version 0.1.d-2.FC.
FCC>1
FCC>2
FCC>3
FCC> ./ttylog: invalid device /dev/ttyA
joan@pluto:~$
Code: Select all
/* ttylog - serial port logger Copyright (C) 1999-2002 Tibor Koleszar Copyright (C) 2008-2011 Robert James Clay This program is free software;
you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program;
if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <sys/stat.h>
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#define VERSION "0.1.d-2.FC"
#define BAUDN 9
char flush = 0;
char *BAUD_T[] =
{"300", "1200", "2400", "4800", "9600",
"19200", "38400", "57600", "115200"};
int BAUD_B[] =
{B300, B1200, B2400, B4800, B9600,
B19200, B38400, B57600, B115200};
int main (int argc, char *argv[])
{
FILE *logfile;
fd_set rfds;
int retval, i, j, baud = -1;
int fd;
char line[1024], modem_device[512];
struct termios oldtio, newtio;
printf ("ttylog version %s.\n", VERSION);
modem_device[0] = 0;
if (argc < 2)
{ printf ("%s: no params. try %s -h\n", argv[0], argv[0]);
exit (0);
}
for (i = 1; i < argc; i++)
{
if (!strcmp (argv[i], "-h") || !strcmp (argv[i], "--help"))
{ printf ("ttylog version %s. Programmed by Tibor Koleszar <oldw@debian.org>\n", VERSION);
printf ("Usage: \n -h, --help This help\n -v, --version Version number\n");
printf (" -b, --baud Baud rate\n -d, --device Serial device (eg. /dev/ttyS1)\n -f, --flush Flush output\n");
exit (0);
}
if (!strcmp (argv[i], "-v") || !strcmp (argv[i], "--version"))
{ printf ("ttylog version %s.\n", VERSION);
exit (0);
}
if (!strcmp (argv[i], "-f") || !strcmp (argv[i], "--flush"))
{ flush = 1;
}
if (!strcmp (argv[i], "-b") || !strcmp (argv[i], "--baud"))
{ if (argv[i + 1] != NULL)
{
for (j = 0; j < BAUDN; j++)
if (!strcmp (argv[i + 1], BAUD_T[j])) baud = j;
}
if (baud == -1)
{ printf ("%s: invalid baud rate %s\n", argv[0], argv[i + 1]);
exit (0);
}
}
if (!strcmp (argv[i], "-d") || !strcmp (argv[i], "--device"))
{
if (argv[i + 1] != NULL) {
//strcpy (modem_device, argv[i + 1]);
memset (modem_device, '\0', sizeof(modem_device));
strncpy (modem_device, argv[i + 1], sizeof(modem_device)-1);
}
else { }
}
}
printf("FCC>1\n");
if (!strlen(modem_device))
{
printf ("%s: no device is set. Use %s -h for more information.\n", argv[0], argv[0]);
exit (0);
}
printf("FCC>2\n");
logfile = fopen (modem_device, "rb");
printf("FCC>3\n");
if (logfile == NULL)
{ printf ("FCC> %s: invalid device %s\n", argv[0], modem_device);
exit (0);
}
printf("FCC>\n");
fd = fileno (logfile);
printf("FCC> fileno id : %d\n", fd);
tcgetattr (fd, &oldtio);
/* save current serial port settings */
bzero (&newtio, sizeof (newtio));
/* clear struct for new port settings */
//- newtio.c_cflag = BAUD_B[baud] | CRTSCTS | CS8 | CLOCAL | CREAD;
//- newtio.c_cflag = CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_cflag = CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR | IGNCR;
newtio.c_oflag = 0;
newtio.c_lflag = ICANON;
cfsetispeed (&newtio, BAUD_B[baud]);
cfsetospeed (&newtio, BAUD_B[baud]);
tcflush (fd, TCIFLUSH);
tcsetattr (fd, TCSANOW, &newtio);
/* Clear the device */ FD_ZERO (&rfds);
FD_SET (fd, &rfds);
fgets (line, 1024, logfile);
int hh=0;
while (1) { FD_ZERO (&rfds);
FD_SET (fd, &rfds);
retval = select (fd + 1, &rfds, NULL, NULL, NULL);
printf("%d\n", hh++);
if (retval) { fgets (line, 1024, logfile);
printf ("%s\n", line);
if (flush) { printf("1\n");
fflush(stdout);
} } } fclose (logfile);
tcsetattr (fd, TCSANOW, &oldtio);
return 0;
}
Re: Serial & C Programming
YES YES It's OK nowjoan wrote:It sort of works. If you use minicom you have to send a newline (ctrl J) to get fgets to return.

In the file, two fgets !!
CTRL+J with minicom it's ok
it's possible to modified ttylog to run without ctrl+J ??
THX
Florent
Re: Serial & C Programming
fgets will not return until end of file or a newline.
You'll need to use something like fgetc to get character by character.
You'll need to use something like fgetc to get character by character.
Re: Serial & C Programming
effectively 
I tested tomorrow

I tested tomorrow