emw
Posts: 52
Joined: Tue Apr 12, 2016 2:53 pm

Serial port won't open after using minicom

Thu Nov 28, 2019 7:58 pm

I using the Raspberry Pi Zero W with the serial port. If I run my application before minicom it works fine. mincom works fine. However If I run my application after minicom it hangs when opening the serial port. Any Idea what is going on here? Does it have anything to do with using the mini-uart?

Code: Select all

minicom -b 57600 -o -D /dev/serial0

Code: Select all

#include <stdio.h>   /* Standard input/output definitions */
#include <string.h>  /* String function definitions */
#include <unistd.h>  /* UNIX standard function definitions */
#include <fcntl.h>   /* File control definitions */
#include <errno.h>   /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */

int main(int argc, char* argv[])
{
    printf("open\n");fflush(stdout);
    int fd  = open( "/dev/serial0", O_RDWR | O_NOCTTY  ) ;
    printf("write\n");fflush(stdout);
    write(fd, "abc",3);
    printf("done\n");fflush(stdout);
}
open

ElEscalador
Posts: 856
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA
Contact: Website

Re: Serial port won't open after using minicom

Thu Nov 28, 2019 8:06 pm

I've had that problem. I think it was solved by closing minicom with the ctrl-a, then z or menu, then x for the official "close minicom" dance instead of just closing the window. Or maybe it was the other thing where closing the window worked. Been a while. But yeah, something in minicom hangs onto the port and until I figured out the thing I had to reboot to get my port back.
Robotics tips, hacks, book extras https://youtube.com/practicalrobotics

User avatar
scruss
Posts: 3492
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Serial port won't open after using minicom

Thu Nov 28, 2019 9:28 pm

See what program is hanging on to the serial port:

Code: Select all

lsof /dev/serial0
You may need to install lsof first. Minicom should let the port go if it was properly exited.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

emw
Posts: 52
Joined: Tue Apr 12, 2016 2:53 pm

Re: Serial port won't open after using minicom

Thu Nov 28, 2019 9:42 pm

lsof shows nothing for /dev/serial0 or /dev/ttyS0.

I am exiting with ctrl-a the x, so as far as I know I am exiting properly.

renice123
Posts: 248
Joined: Tue Oct 15, 2019 3:56 pm

Re: Serial port won't open after using minicom

Fri Nov 29, 2019 7:26 am

Many years ago, in the era of Internet communications over the phone, Minicom was my favorite program.
But even then I noticed the “freezing”. Alas, many years have passed since then and communication using the serial port has not improved =) Recently, I again tried to use minicom to organize data transfer between a color temperature measuring device and a computer and got a “hang”. I had to use a third-party serial port program. Yes, apparently this is just a problem of the old and unsupported minicom program and the old rs-232 interface.
You can try to use a different console terminal (there are a lot of them in Linux), but the organization of interaction with rs-232 in modern operating systems often causes problems.

Return to “Troubleshooting”